7438f34d3c7c206bc86189091119c83d21346be1
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2 # $Id$
3
4 compile_kernel_args() {
5         local ARGS
6
7         ARGS=''
8         if [ "${KERNEL_CROSS_COMPILE}" != '' ]
9         then
10                 ARGS="${ARGS} CROSS_COMPILE=\"${KERNEL_CROSS_COMPILE}\""
11         else
12                 if [ "${KERNEL_CC}" != '' ]
13                 then
14                         ARGS="CC=\"${KERNEL_CC}\""
15                 fi
16                 if [ "${KERNEL_LD}" != '' ]
17                 then
18                         ARGS="${ARGS} LD=\"${KERNEL_LD}\""
19                 fi
20                 if [ "${KERNEL_AS}" != '' ]
21                 then
22                         ARGS="${ARGS} AS=\"${KERNEL_AS}\""
23                 fi
24                 if [ -n "${KERNEL_ARCH}" ]
25                 then
26                         ARGS="${ARGS} ARCH=\"${KERNEL_ARCH}\""
27                 fi
28         fi
29         echo -n "${ARGS}"
30 }
31
32 compile_utils_args()
33 {
34         local ARGS
35         ARGS=''
36
37         if [ -n "${UTILS_CROSS_COMPILE}" ]
38         then
39                 UTILS_CC="${UTILS_CROSS_COMPILE}gcc"
40                 UTILS_LD="${UTILS_CROSS_COMPILE}ld"
41                 UTILS_AS="${UTILS_CROSS_COMPILE}as"
42         fi
43
44         if [ "${UTILS_ARCH}" != '' ]
45         then
46                 ARGS="ARCH=\"${UTILS_ARCH}\""
47         fi
48         if [ "${UTILS_CC}" != '' ]
49         then
50                 ARGS="CC=\"${UTILS_CC}\""
51         fi
52         if [ "${UTILS_LD}" != '' ]
53         then
54                 ARGS="${ARGS} LD=\"${UTILS_LD}\""
55         fi
56         if [ "${UTILS_AS}" != '' ]
57         then
58                 ARGS="${ARGS} AS=\"${UTILS_AS}\""
59         fi
60
61         echo -n "${ARGS}"
62 }
63
64 export_utils_args()
65 {
66         save_args
67         if [ "${UTILS_ARCH}" != '' ]
68         then
69                 export ARCH="${UTILS_ARCH}"
70         fi
71         if [ "${UTILS_CC}" != '' ]
72         then
73                 export CC="${UTILS_CC}"
74         fi
75         if [ "${UTILS_LD}" != '' ]
76         then
77                 export LD="${UTILS_LD}"
78         fi
79         if [ "${UTILS_AS}" != '' ]
80         then
81                 export AS="${UTILS_AS}"
82         fi
83 }
84
85 unset_utils_args()
86 {
87         if [ "${UTILS_ARCH}" != '' ]
88         then
89                 unset ARCH
90         fi
91         if [ "${UTILS_CC}" != '' ]
92         then
93                 unset CC
94         fi
95         if [ "${UTILS_LD}" != '' ]
96         then
97                 unset LD
98         fi
99         if [ "${UTILS_AS}" != '' ]
100         then
101                 unset AS
102         fi
103         reset_args
104 }
105
106 export_kernel_args()
107 {
108         if [ "${KERNEL_CC}" != '' ]
109         then
110                 export CC="${KERNEL_CC}"
111         fi
112         if [ "${KERNEL_LD}" != '' ]
113         then
114                 export LD="${KERNEL_LD}"
115         fi
116         if [ "${KERNEL_AS}" != '' ]
117         then
118                 export AS="${KERNEL_AS}"
119         fi
120         if [ "${KERNEL_CROSS_COMPILE}" != '' ]
121         then
122                 export CROSS_COMPILE="${KERNEL_CROSS_COMPILE}"
123         fi
124 }
125
126 unset_kernel_args()
127 {
128         if [ "${KERNEL_CC}" != '' ]
129         then
130                 unset CC
131         fi
132         if [ "${KERNEL_LD}" != '' ]
133         then
134                 unset LD
135         fi
136         if [ "${KERNEL_AS}" != '' ]
137         then
138                 unset AS
139         fi
140         if [ "${KERNEL_CROSS_COMPILE}" != '' ]
141         then
142                 unset CROSS_COMPILE
143         fi
144 }
145 save_args()
146 {
147         if [ "${ARCH}" != '' ]
148         then
149                 export ORIG_ARCH="${ARCH}"
150         fi
151         if [ "${CC}" != '' ]
152         then
153                 export ORIG_CC="${CC}"
154         fi
155         if [ "${LD}" != '' ]
156         then
157                 export ORIG_LD="${LD}"
158         fi
159         if [ "${AS}" != '' ]
160         then
161                 export ORIG_AS="${AS}"
162         fi
163         if [ "${CROSS_COMPILE}" != '' ]
164         then
165                 export ORIG_CROSS_COMPILE="${CROSS_COMPILE}"
166         fi
167 }
168 reset_args()
169 {
170         if [ "${ORIG_ARCH}" != '' ]
171         then
172                 export ARCH="${ORIG_ARCH}"
173                 unset ORIG_ARCH
174         fi
175         if [ "${ORIG_CC}" != '' ]
176         then
177                 export CC="${ORIG_CC}"
178                 unset ORIG_CC
179         fi
180         if [ "${ORIG_LD}" != '' ]
181         then
182                 export LD="${ORIG_LD}"
183                 unset ORIG_LD
184         fi
185         if [ "${ORIG_AS}" != '' ]
186         then
187                 export AS="${ORIG_AS}"
188                 unset ORIG_AS
189         fi
190         if [ "${ORIG_CROSS_COMPILE}" != '' ]
191         then
192                 export CROSS_COMPILE="${ORIG_CROSS_COMPILE}"
193                 unset ORIG_CROSS_COMPILE
194         fi
195 }
196
197 apply_patches() {
198         util=$1
199         version=$2
200
201         if [ -d "${GK_SHARE}/patches/${util}/${version}" ]
202         then
203                 print_info 1 "${util}: >> Applying patches..."
204                 for i in ${GK_SHARE}/patches/${util}/${version}/*{diff,patch}
205                 do
206                         [ -f "${i}" ] || continue
207                         patch_success=0
208                         for j in `seq 0 5`
209                         do
210                                 patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null
211                                 if [ $? = 0 ]
212                                 then
213                                         patch_success=1
214                                         break
215                                 fi
216                         done
217                         if [ ${patch_success} -eq 1 ]
218                         then
219                                 print_info 1 "          - `basename ${i}`"
220                         else
221                                 gen_die "could not apply patch ${i} for ${util}-${version}"
222                         fi
223                 done
224         fi
225 }
226
227 compile_generic() {
228         local RET
229         [ "$#" -lt '2' ] &&
230                 gen_die 'compile_generic(): improper usage!'
231         local target=${1}
232         local argstype=${2}
233
234         if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
235         then
236                 export_kernel_args
237                 MAKE=${KERNEL_MAKE}
238         elif [ "${2}" = 'utils' ]
239         then
240                 export_utils_args
241                 MAKE=${UTILS_MAKE}
242         fi
243         case "${argstype}" in
244                 kernel) ARGS="`compile_kernel_args`" ;;
245                 utils) ARGS="`compile_utils_args`" ;;
246                 *) ARGS="" ;; # includes runtask
247         esac
248         shift 2
249
250         # the eval usage is needed in the next set of code
251         # as ARGS can contain spaces and quotes, eg:
252         # ARGS='CC="ccache gcc"'
253         if [ "${argstype}" == 'runtask' ]
254         then
255                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
256                 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
257                 RET=$?
258         elif [ "${LOGLEVEL}" -gt "1" ]
259         then
260                 # Output to stdout and logfile
261                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
262                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
263                 RET=${PIPESTATUS[0]}
264         else
265                 # Output to logfile only
266                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
267                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
268                 RET=$?
269         fi
270         [ ${RET} -ne 0 ] &&
271                 gen_die "Failed to compile the \"${target}\" target..."
272
273         unset MAKE
274         unset ARGS
275         if [ "${argstype}" = 'kernel' ]
276         then
277                 unset_kernel_args
278         elif [ "${argstype}" = 'utils' ]
279         then
280                 unset_utils_args
281         fi
282 }
283
284 compile_modules() {
285         print_info 1 "        >> Compiling ${KV} modules..."
286         cd ${KERNEL_DIR}
287         compile_generic modules kernel
288         export UNAME_MACHINE="${ARCH}"
289         [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
290         compile_generic "modules_install" kernel
291         unset UNAME_MACHINE
292 }
293
294 compile_kernel() {
295         [ "${KERNEL_MAKE}" = '' ] &&
296                 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
297         cd ${KERNEL_DIR}
298         print_info 1 "        >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
299         compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
300         if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
301         then
302                 print_info 1 "        >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
303                 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
304         fi
305
306         local firmware_in_kernel_line=`fgrep CONFIG_FIRMWARE_IN_KERNEL "${KERNEL_DIR}"/.config`
307         if [ -n "${firmware_in_kernel_line}" -a "${firmware_in_kernel_line}" != CONFIG_FIRMWARE_IN_KERNEL=y ]
308         then
309                 print_info 1 "        >> Installing firmware ('make firmware_install') due to CONFIG_FIRMWARE_IN_KERNEL != y..."
310                 compile_generic "firmware_install" kernel
311         else
312                 print_info 1 "        >> Not installing firmware as it's included in the kernel already (CONFIG_FIRMWARE_IN_KERNEL=y)..."
313         fi
314
315         local tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY})
316         local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2})
317         if [ -z "${tmp_kernel_binary}" ]
318         then
319                 gen_die "Cannot locate kernel binary"
320         fi
321
322         if ! isTrue "${CMD_NOINSTALL}"
323         then
324                 copy_image_with_preserve "kernel" \
325                         "${tmp_kernel_binary}" \
326                         "kernel-${KNAME}-${ARCH}-${KV}"
327
328                 copy_image_with_preserve "System.map" \
329                         "System.map" \
330                         "System.map-${KNAME}-${ARCH}-${KV}"
331
332                 if isTrue "${GENZIMAGE}"
333                 then
334                         copy_image_with_preserve "kernelz" \
335                                 "${tmp_kernel_binary2}" \
336                                 "kernelz-${KV}"
337                 fi
338         else
339                 cp "${tmp_kernel_binary}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
340                         gen_die "Could not copy the kernel binary to ${TMPDIR}!"
341                 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
342                         gen_die "Could not copy System.map to ${TMPDIR}!"
343                 if isTrue "${GENZIMAGE}"
344                 then
345                         cp "${tmp_kernel_binary2}" "${TMPDIR}/kernelz-${KV}" ||
346                                 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
347                 fi
348         fi
349 }
350
351 compile_busybox() {
352         [ -f "${BUSYBOX_SRCTAR}" ] ||
353                 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
354
355         if [ -n "${BUSYBOX_CONFIG}" ]
356         then
357                 [ -f "${BUSYBOX_CONFIG}" ] ||
358                         gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}"
359         elif isTrue "${NETBOOT}" && [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" ]
360         then
361                 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")"
362         elif isTrue "${NETBOOT}" && [ -f "${GK_SHARE}/netboot/busy-config" ]
363         then
364                 BUSYBOX_CONFIG="${GK_SHARE}/netboot/busy-config"
365         elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ]
366         then
367                 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")"
368         elif [ -f "${GK_SHARE}/defaults/busy-config" ]
369         then
370                 BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config"
371         else
372                 gen_die "Could not find a busybox config file"
373         fi
374
375         # Delete cache if stored config's MD5 does not match one to be used
376         if [ -f "${BUSYBOX_BINCACHE}" ]
377         then
378                 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum)
379                 newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}")
380                 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
381                 then
382                         print_info 1 "busybox: >> Removing stale cache..."
383                         rm -rf "${BUSYBOX_BINCACHE}"
384                 else
385                         print_info 1 "busybox: >> Using cache"
386                 fi
387         fi
388
389         if [ ! -f "${BUSYBOX_BINCACHE}" ]
390         then
391                 cd "${TEMP}"
392                 rm -rf "${BUSYBOX_DIR}" > /dev/null
393                 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
394                         gen_die 'Could not extract busybox source tarball!'
395                 [ -d "${BUSYBOX_DIR}" ] ||
396                         gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
397                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
398                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig"
399                 cd "${BUSYBOX_DIR}"
400                 apply_patches busybox ${BUSYBOX_VER}
401                 print_info 1 'busybox: >> Configuring...'
402                 yes '' 2>/dev/null | compile_generic oldconfig utils
403
404                 print_info 1 'busybox: >> Compiling...'
405                 compile_generic all utils
406                 print_info 1 'busybox: >> Copying to cache...'
407                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
408                         gen_die 'Busybox executable does not exist!'
409                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
410                         gen_die 'Could not strip busybox binary!'
411                 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig ||
412                         gen_die 'Could not create the busybox bincache!'
413
414                 cd "${TEMP}"
415                 rm -rf "${BUSYBOX_DIR}" > /dev/null
416         fi
417 }
418
419 compile_lvm() {
420         if [ ! -f "${LVM_BINCACHE}" ]
421         then
422                 [ -f "${LVM_SRCTAR}" ] ||
423                         gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
424                 cd "${TEMP}"
425                 rm -rf ${LVM_DIR} > /dev/null
426                 /bin/tar -zxpf ${LVM_SRCTAR} ||
427                         gen_die 'Could not extract LVM source tarball!'
428                 [ -d "${LVM_DIR}" ] ||
429                         gen_die 'LVM directory ${LVM_DIR} is invalid!'
430                 rm -rf "${TEMP}/device-mapper" > /dev/null
431                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
432                         gen_die "Could not extract device-mapper binary cache!";
433                 
434                 cd "${LVM_DIR}"
435                 apply_patches lvm ${LVM_VER}
436                 print_info 1 'lvm: >> Configuring...'
437                         CFLAGS="-fPIC" \
438                         ./configure --enable-static_link --prefix=${TEMP}/lvm \
439                                 --with-lvm1=internal --with-clvmd=none --with-cluster=none \
440                                 --disable-readline --disable-selinux --with-mirrors=internal \
441                                 --with-snapshots=internal --with-pool=internal >> ${LOGFILE} 2>&1 || \
442                                 gen_die 'Configure of lvm failed!'
443                 print_info 1 'lvm: >> Compiling...'
444                         compile_generic '' utils
445                         compile_generic 'install' utils
446
447                 cd "${TEMP}/lvm"
448                 print_info 1 '      >> Copying to bincache...'
449                 strip "sbin/lvm.static" ||
450                         gen_die 'Could not strip lvm.static!'
451                 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
452                         gen_die 'Could not create binary cache'
453
454                 cd "${TEMP}"
455                 rm -rf "${TEMP}/device-mapper" > /dev/null
456                 rm -rf "${LVM_DIR}" lvm
457         fi
458 }
459
460 compile_dmraid() {
461         compile_device_mapper
462         if [ ! -f "${DMRAID_BINCACHE}" ]
463         then
464                 [ -f "${DMRAID_SRCTAR}" ] ||
465                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
466                 cd "${TEMP}"
467                 rm -rf ${DMRAID_DIR} > /dev/null
468                 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
469                         gen_die 'Could not extract DMRAID source tarball!'
470                 [ -d "${DMRAID_DIR}" ] ||
471                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
472                 rm -rf "${TEMP}/device-mapper" > /dev/null
473                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
474                         gen_die "Could not extract device-mapper binary cache!";
475                 
476                 cd "${DMRAID_DIR}"
477                 print_info 1 'dmraid: >> Configuring...'
478                 
479                 LDFLAGS="-L${TEMP}/device-mapper/lib" \
480                 CFLAGS="-I${TEMP}/device-mapper/include" \
481                 CPPFLAGS="-I${TEMP}/device-mapper/include" \
482                 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
483                         gen_die 'Configure of dmraid failed!'
484
485                 # We dont necessarily have selinux installed yet... look into
486                 # selinux global support in the future.
487                 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
488                 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
489                 mkdir -p "${TEMP}/dmraid"
490                 print_info 1 'dmraid: >> Compiling...'
491                 # Force dmraid to be built with -j1 for bug #188273
492                 MAKEOPTS=-j1 compile_generic '' utils
493                 #compile_generic 'install' utils
494                 mkdir ${TEMP}/dmraid/sbin
495                 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
496                 print_info 1 '      >> Copying to bincache...'
497                 cd "${TEMP}/dmraid"
498                 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
499                         gen_die 'Could not create binary cache'
500
501                 cd "${TEMP}"
502                 rm -rf "${TEMP}/device-mapper" > /dev/null
503                 rm -rf "${DMRAID_DIR}" dmraid
504         fi
505 }
506
507 compile_device_mapper() {
508         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
509         then
510                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
511                         gen_die "Could not find device-mapper source tarball: ${DEVICE_MAPPER_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
512                 cd "${TEMP}"
513                 rm -rf "${DEVICE_MAPPER_DIR}"
514                 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
515                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
516                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
517                 cd "${DEVICE_MAPPER_DIR}"
518                 CFLAGS="-fPIC" \
519                 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
520                         --disable-selinux >> ${LOGFILE} 2>&1 ||
521                         gen_die 'Configuring device-mapper failed!'
522                 print_info 1 'device-mapper: >> Compiling...'
523                 compile_generic '' utils
524                 compile_generic 'install' utils
525                 print_info 1 '        >> Copying to cache...'
526                 cd "${TEMP}"
527                 rm -rf "${TEMP}/device-mapper/man" ||
528                         gen_die 'Could not remove manual pages!'
529                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
530                         gen_die 'Could not strip dmsetup binary!'
531                 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
532                         gen_die 'Could not tar up the device-mapper binary!'
533                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
534                         gen_die 'device-mapper cache not created!'
535                 cd "${TEMP}"
536                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
537                 rm -rf "${TEMP}/device-mapper" > /dev/null
538         fi
539 }
540
541 compile_e2fsprogs() {
542         if [ -f "${BLKID_BINCACHE}" ]
543         then
544                 print_info 1 "blkid: >> Using cache"
545         else
546                 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
547                         gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
548                 cd "${TEMP}"
549                 rm -rf "${E2FSPROGS_DIR}"
550                 tar -zxpf "${E2FSPROGS_SRCTAR}"
551                 [ ! -d "${E2FSPROGS_DIR}" ] &&
552                         gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
553                 cd "${E2FSPROGS_DIR}"
554                 print_info 1 'e2fsprogs: >> Configuring...'
555                 LDFLAGS=-static ./configure >> ${LOGFILE} 2>&1 ||
556                         gen_die 'Configuring e2fsprogs failed!'
557                 print_info 1 'e2fsprogs: >> Compiling...'
558                 MAKE=${UTILS_MAKE} compile_generic "" ""
559                 print_info 1 'blkid: >> Copying to cache...'
560                 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
561                         gen_die 'Blkid executable does not exist!'
562                 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
563                         gen_die 'Could not strip blkid binary!'
564                 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
565                         gen_die 'bzip2 compression of blkid failed!'
566                 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
567                         gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
568
569                 cd "${TEMP}"
570                 rm -rf "${E2FSPROGS_DIR}" > /dev/null
571         fi
572 }
573
574 compile_fuse() {
575         if [ ! -f "${FUSE_BINCACHE}" ]
576         then
577                 [ ! -f "${FUSE_SRCTAR}" ] &&
578                         gen_die "Could not find fuse source tarball: ${FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
579                 cd "${TEMP}"
580                 rm -rf "${FUSE_DIR}"
581                 tar -zxpf "${FUSE_SRCTAR}"
582                 [ ! -d "${FUSE_DIR}" ] &&
583                         gen_die "fuse directory ${FUSE_DIR} invalid"
584                 cd "${FUSE_DIR}"
585                 print_info 1 'fuse: >> Configuring...'
586                 ./configure  --disable-kernel-module --disable-example >> ${LOGFILE} 2>&1 ||
587                         gen_die 'Configuring fuse failed!'
588                 print_info 1 'fuse: >> Compiling...'
589                 MAKE=${UTILS_MAKE} compile_generic "" ""
590
591                 # Since we're linking statically against libfuse, we don't need to cache the .so
592 #               print_info 1 'libfuse: >> Copying to cache...'
593 #               [ -f "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ] ||
594 #                       gen_die 'libfuse.so does not exist!'
595 #               strip "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ||
596 #                       gen_die 'Could not strip libfuse.so!'
597 #               cd "${TEMP}/${FUSE_DIR}/lib/.libs"
598 #               tar -cjf "${FUSE_BINCACHE}" libfuse*so* ||
599 #                       gen_die 'Could not create fuse bincache!'
600
601                 cd "${TEMP}"
602 #               rm -rf "${FUSE_DIR}" > /dev/null
603         fi
604 }
605
606 compile_unionfs_fuse() {
607         if [ ! -f "${UNIONFS_FUSE_BINCACHE}" ]
608         then
609
610                 # We'll call compile_fuse() from here, since it's not needed directly by anything else
611                 compile_fuse
612
613                 [ ! -f "${UNIONFS_FUSE_SRCTAR}" ] &&
614                         gen_die "Could not find unionfs-fuse source tarball: ${UNIONFS_FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
615                 cd "${TEMP}"
616                 rm -rf "${UNIONFS_FUSE_DIR}"
617                 tar -jxpf "${UNIONFS_FUSE_SRCTAR}"
618                 [ ! -d "${UNIONFS_FUSE_DIR}" ] &&
619                         gen_die "unionfs-fuse directory ${UNIONFS_FUSE_DIR} invalid"
620                 cd "${UNIONFS_FUSE_DIR}"
621                 print_info 1 'unionfs-fuse: >> Compiling...'
622                 sed -i "/^\(CFLAGS\|CPPFLAGS\)/s:^\\(.*\\)$:\\1 -static -I${TEMP}/${FUSE_DIR}/include -L${TEMP}/${FUSE_DIR}/lib/.libs:" Makefile src/Makefile
623                 sed -i "/^LIB = /s:^LIB = \(.*\)$:LIB = -static -L${TEMP}/${FUSE_DIR}/lib/.libs \1 -ldl -lrt:" Makefile src/Makefile
624                 MAKE=${UTILS_MAKE} compile_generic "" ""
625                 print_info 1 'unionfs-fuse: >> Copying to cache...'
626                 [ -f "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ] ||
627                         gen_die 'unionfs binary does not exist!'
628                 strip "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
629                         gen_die 'Could not strip unionfs binary!'
630                 bzip2 "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
631                         gen_die 'bzip2 compression of unionfs binary failed!'
632                 mv "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs.bz2" "${UNIONFS_FUSE_BINCACHE}" ||
633                         gen_die 'Could not copy the unionfs binary to the package directory, does the directory exist?'
634
635                 cd "${TEMP}"
636                 rm -rf "${UNIONFS_FUSE_DIR}" > /dev/null
637         fi
638 }
639
640 compile_iscsi() {
641         if [ ! -f "${ISCSI_BINCACHE}" ]
642         then
643                 [ ! -f "${ISCSI_SRCTAR}" ] &&
644                         gen_die "Could not find iSCSI source tarball: ${ISCSI_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
645                 cd "${TEMP}"
646                 rm -rf "${ISCSI_DIR}"
647                 tar -zxpf "${ISCSI_SRCTAR}"
648                 [ ! -d "${ISCSI_DIR}" ] &&
649                         gen_die "ISCSI directory ${ISCSI_DIR} invalid"
650                                 print_info 1 'iSCSI: >> Compiling...'
651                 cd "${TEMP}/${ISCSI_DIR}"
652
653                 # Only build userspace
654                 MAKE=${UTILS_MAKE} compile_generic "user" ""
655         
656                 # if kernel modules exist, copy them to initramfs, otherwise it will be compiled into the kernel
657                 mkdir -p "${TEMP}/initramfs-iscsi-temp/lib/modules/${RELEASE}/kernel/drivers/scsi/"
658                 for modname in iscsi_tcp libiscsi scsi_transport_iscsi
659                 do
660                         if [ -e "${CMD_KERNEL_DIR}/drivers/scsi/${modname}.ko" ]
661                         then
662                                 cp ${CMD_KERNEL_DIR}/drivers/scsi/${modname}.ko "${TEMP}/initramfs-iscsi-temp/lib/modules/${RELEASE}/kernel/drivers/scsi/"
663                         fi
664                 done
665
666                 cd "${TEMP}/initramfs-iscsi-temp/"
667                 print_info 1 'iscsistart: >> Copying to cache...'
668                 [ -f "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ] ||
669                         gen_die 'iscsistart executable does not exist!'
670                 strip "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ||
671                         gen_die 'Could not strip iscsistart binary!'
672                 bzip2 "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ||
673                         gen_die 'bzip2 compression of iscsistart failed!'
674                 mv "${TEMP}/${ISCSI_DIR}/usr/iscsistart.bz2" "${ISCSI_BINCACHE}" ||
675                         gen_die 'Could not copy the iscsistart binary to the package directory, does the directory exist?'
676
677                 cd "${TEMP}"
678                 rm -rf "${ISCSI_DIR}" > /dev/null
679         fi
680 }
681
682 compile_gpg() {
683         if [ -f "${GPG_BINCACHE}" ]
684         then
685                 print_info 1 "gnupg: >> Using cache"
686         else
687                 [ ! -f "${GPG_SRCTAR}" ] &&
688                         gen_die "Could not find gnupg source tarball: ${GPG_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
689                 cd "${TEMP}"
690                 rm -rf "${GPG_DIR}"
691                 tar -jxf "${GPG_SRCTAR}"
692                 [ ! -d "${GPG_DIR}" ] &&
693                         gen_die "gnupg directory ${GPG_DIR} invalid"
694                 cd "${GPG_DIR}"
695                 print_info 1 'gnupg: >> Configuring...'
696                 # --enable-minimal works, but it doesn't reduce the command length much.
697                 # Given its history and the precision this needs, explicit is cleaner.
698                 LDFLAGS='-static' CFLAGS='-Os' ./configure --prefix=/ \
699                         --enable-static-rnd=linux --disable-dev-random --disable-asm \
700                         --disable-selinux-support --disable-gnupg-iconv --disable-card-support \
701                         --disable-agent-support --disable-bzip2 --disable-exec \
702                         --disable-photo-viewers --disable-keyserver-helpers --disable-ldap \
703                         --disable-hkp --disable-finger --disable-generic --disable-mailto \
704                         --disable-keyserver-path --disable-dns-srv --disable-dns-pka \
705                         --disable-dns-cert --disable-nls --disable-threads --disable-regex \
706                         --disable-optimization --with-included-zlib --without-capabilities \
707                         --without-tar --without-ldap --without-libcurl --without-mailprog \
708                         --without-libpth-prefix --without-libiconv-prefix --without-libintl-prefix\
709                         --without-zlib --without-bzip2 --without-libusb --without-readline \
710                                 >> ${LOGFILE} 2>&1 || gen_die 'Configuring gnupg failed!'
711                 print_info 1 'gnupg: >> Compiling...'
712                 compile_generic "" "utils"
713                 print_info 1 'gnupg: >> Copying to cache...'
714                 [ -f "${TEMP}/${GPG_DIR}/g10/gpg" ] ||
715                         gen_die 'gnupg executable does not exist!'
716                 strip "${TEMP}/${GPG_DIR}/g10/gpg" ||
717                         gen_die 'Could not strip gpg binary!'
718                 bzip2 -z -c "${TEMP}/${GPG_DIR}/g10/gpg" > "${GPG_BINCACHE}" ||
719                         gen_die 'Could not copy the gpg binary to the package directory, does the directory exist?'
720
721                 cd "${TEMP}"
722                 rm -rf "${GPG_DIR}" > /dev/null
723         fi
724 }