9fe1e1f44f818102ea221cb1c06432ea460d3254
[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 tmp_kernel_binary=$(find_kernel_binary ${KERNEL_BINARY})
307         local tmp_kernel_binary2=$(find_kernel_binary ${KERNEL_BINARY_2})
308         if [ -z "${tmp_kernel_binary}" ]
309         then
310                 gen_die "Cannot locate kernel binary"
311         fi
312
313         if ! isTrue "${CMD_NOINSTALL}"
314         then
315                 copy_image_with_preserve "kernel" \
316                         "${tmp_kernel_binary}" \
317                         "kernel-${KNAME}-${ARCH}-${KV}"
318
319                 copy_image_with_preserve "System.map" \
320                         "System.map" \
321                         "System.map-${KNAME}-${ARCH}-${KV}"
322
323                 if isTrue "${GENZIMAGE}"
324                 then
325                         copy_image_with_preserve "kernelz" \
326                                 "${tmp_kernel_binary2}" \
327                                 "kernelz-${KV}"
328                 fi
329         else
330                 cp "${tmp_kernel_binary}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
331                         gen_die "Could not copy the kernel binary to ${TMPDIR}!"
332                 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
333                         gen_die "Could not copy System.map to ${TMPDIR}!"
334                 if isTrue "${GENZIMAGE}"
335                 then
336                         cp "${tmp_kernel_binary2}" "${TMPDIR}/kernelz-${KV}" ||
337                                 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
338                 fi
339         fi
340 }
341
342 compile_busybox() {
343         [ -f "${BUSYBOX_SRCTAR}" ] ||
344                 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
345
346         if [ -n "${BUSYBOX_CONFIG}" ]
347         then
348                 [ -f "${BUSYBOX_CONFIG}" ] ||
349                         gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}"
350         elif isTrue "${NETBOOT}" && [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" ]
351         then
352                 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")"
353         elif isTrue "${NETBOOT}" && [ -f "${GK_SHARE}/netboot/busy-config" ]
354         then
355                 BUSYBOX_CONFIG="${GK_SHARE}/netboot/busy-config"
356         elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ]
357         then
358                 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")"
359         elif [ -f "${GK_SHARE}/defaults/busy-config" ]
360         then
361                 BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config"
362         else
363                 gen_die "Could not find a busybox config file"
364         fi
365
366         # Delete cache if stored config's MD5 does not match one to be used
367         if [ -f "${BUSYBOX_BINCACHE}" ]
368         then
369                 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum)
370                 newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}")
371                 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
372                 then
373                         print_info 1 "busybox: >> Removing stale cache..."
374                         rm -rf "${BUSYBOX_BINCACHE}"
375                 else
376                         print_info 1 "busybox: >> Using cache"
377                 fi
378         fi
379
380         if [ ! -f "${BUSYBOX_BINCACHE}" ]
381         then
382                 cd "${TEMP}"
383                 rm -rf "${BUSYBOX_DIR}" > /dev/null
384                 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
385                         gen_die 'Could not extract busybox source tarball!'
386                 [ -d "${BUSYBOX_DIR}" ] ||
387                         gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
388                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
389                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig"
390                 cd "${BUSYBOX_DIR}"
391                 apply_patches busybox ${BUSYBOX_VER}
392                 print_info 1 'busybox: >> Configuring...'
393                 yes '' 2>/dev/null | compile_generic oldconfig utils
394
395                 print_info 1 'busybox: >> Compiling...'
396                 compile_generic all utils
397                 print_info 1 'busybox: >> Copying to cache...'
398                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
399                         gen_die 'Busybox executable does not exist!'
400                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
401                         gen_die 'Could not strip busybox binary!'
402                 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig ||
403                         gen_die 'Could not create the busybox bincache!'
404
405                 cd "${TEMP}"
406                 rm -rf "${BUSYBOX_DIR}" > /dev/null
407         fi
408 }
409
410 compile_lvm() {
411         compile_device_mapper
412         if [ ! -f "${LVM_BINCACHE}" ]
413         then
414                 [ -f "${LVM_SRCTAR}" ] ||
415                         gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
416                 cd "${TEMP}"
417                 rm -rf ${LVM_DIR} > /dev/null
418                 /bin/tar -zxpf ${LVM_SRCTAR} ||
419                         gen_die 'Could not extract LVM source tarball!'
420                 [ -d "${LVM_DIR}" ] ||
421                         gen_die 'LVM directory ${LVM_DIR} is invalid!'
422                 rm -rf "${TEMP}/device-mapper" > /dev/null
423                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
424                         gen_die "Could not extract device-mapper binary cache!";
425                 
426                 cd "${LVM_DIR}"
427                 apply_patches lvm ${LVM_VER}
428                 print_info 1 'lvm: >> Configuring...'
429                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
430                         CFLAGS="-fPIC" \
431                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
432                         ./configure --enable-static_link --prefix=${TEMP}/lvm \
433                                 --with-lvm1=none --with-clvmd=none --with-cluster=none \
434                                 --disable-readline --disable-selinux --with-mirrors=none \
435                                 --with-snapshots=none --with-pool=internal >> ${LOGFILE} 2>&1 || \
436                                 gen_die 'Configure of lvm failed!'
437                 print_info 1 'lvm: >> Compiling...'
438                         compile_generic '' utils
439                         compile_generic 'install' utils
440
441                 cd "${TEMP}/lvm"
442                 print_info 1 '      >> Copying to bincache...'
443                 strip "sbin/lvm.static" ||
444                         gen_die 'Could not strip lvm.static!'
445                 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
446                         gen_die 'Could not create binary cache'
447
448                 cd "${TEMP}"
449                 rm -rf "${TEMP}/device-mapper" > /dev/null
450                 rm -rf "${LVM_DIR}" lvm
451         fi
452 }
453
454 compile_dmraid() {
455         compile_device_mapper
456         if [ ! -f "${DMRAID_BINCACHE}" ]
457         then
458                 [ -f "${DMRAID_SRCTAR}" ] ||
459                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
460                 cd "${TEMP}"
461                 rm -rf ${DMRAID_DIR} > /dev/null
462                 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
463                         gen_die 'Could not extract DMRAID source tarball!'
464                 [ -d "${DMRAID_DIR}" ] ||
465                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
466                 rm -rf "${TEMP}/device-mapper" > /dev/null
467                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
468                         gen_die "Could not extract device-mapper binary cache!";
469                 
470                 cd "${DMRAID_DIR}"
471                 print_info 1 'dmraid: >> Configuring...'
472                 
473                 LDFLAGS="-L${TEMP}/device-mapper/lib" \
474                 CFLAGS="-I${TEMP}/device-mapper/include" \
475                 CPPFLAGS="-I${TEMP}/device-mapper/include" \
476                 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
477                         gen_die 'Configure of dmraid failed!'
478
479                 # We dont necessarily have selinux installed yet... look into
480                 # selinux global support in the future.
481                 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
482                 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
483                 mkdir -p "${TEMP}/dmraid"
484                 print_info 1 'dmraid: >> Compiling...'
485                 # Force dmraid to be built with -j1 for bug #188273
486                 MAKEOPTS=-j1 compile_generic '' utils
487                 #compile_generic 'install' utils
488                 mkdir ${TEMP}/dmraid/sbin
489                 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
490                 print_info 1 '      >> Copying to bincache...'
491                 cd "${TEMP}/dmraid"
492                 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
493                         gen_die 'Could not create binary cache'
494
495                 cd "${TEMP}"
496                 rm -rf "${TEMP}/device-mapper" > /dev/null
497                 rm -rf "${DMRAID_DIR}" dmraid
498         fi
499 }
500
501 compile_device_mapper() {
502         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
503         then
504                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
505                         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!"
506                 cd "${TEMP}"
507                 rm -rf "${DEVICE_MAPPER_DIR}"
508                 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
509                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
510                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
511                 cd "${DEVICE_MAPPER_DIR}"
512                 CFLAGS="-fPIC" \
513                 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
514                         --disable-selinux >> ${LOGFILE} 2>&1 ||
515                         gen_die 'Configuring device-mapper failed!'
516                 print_info 1 'device-mapper: >> Compiling...'
517                 compile_generic '' utils
518                 compile_generic 'install' utils
519                 print_info 1 '        >> Copying to cache...'
520                 cd "${TEMP}"
521                 rm -rf "${TEMP}/device-mapper/man" ||
522                         gen_die 'Could not remove manual pages!'
523                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
524                         gen_die 'Could not strip dmsetup binary!'
525                 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
526                         gen_die 'Could not tar up the device-mapper binary!'
527                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
528                         gen_die 'device-mapper cache not created!'
529                 cd "${TEMP}"
530                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
531                 rm -rf "${TEMP}/device-mapper" > /dev/null
532         fi
533 }
534
535 compile_e2fsprogs() {
536         if [ -f "${BLKID_BINCACHE}" ]
537         then
538                 print_info 1 "blkid: >> Using cache"
539         else
540                 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
541                         gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
542                 cd "${TEMP}"
543                 rm -rf "${E2FSPROGS_DIR}"
544                 tar -zxpf "${E2FSPROGS_SRCTAR}"
545                 [ ! -d "${E2FSPROGS_DIR}" ] &&
546                         gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
547                 cd "${E2FSPROGS_DIR}"
548                 print_info 1 'e2fsprogs: >> Configuring...'
549                 LDFLAGS=-static ./configure >> ${LOGFILE} 2>&1 ||
550                         gen_die 'Configuring e2fsprogs failed!'
551                 print_info 1 'e2fsprogs: >> Compiling...'
552                 MAKE=${UTILS_MAKE} compile_generic "" ""
553                 print_info 1 'blkid: >> Copying to cache...'
554                 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
555                         gen_die 'Blkid executable does not exist!'
556                 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
557                         gen_die 'Could not strip blkid binary!'
558                 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
559                         gen_die 'bzip2 compression of blkid failed!'
560                 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
561                         gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
562
563                 cd "${TEMP}"
564                 rm -rf "${E2FSPROGS_DIR}" > /dev/null
565         fi
566 }
567
568 compile_fuse() {
569         if [ ! -f "${FUSE_BINCACHE}" ]
570         then
571                 [ ! -f "${FUSE_SRCTAR}" ] &&
572                         gen_die "Could not find fuse source tarball: ${FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
573                 cd "${TEMP}"
574                 rm -rf "${FUSE_DIR}"
575                 tar -zxpf "${FUSE_SRCTAR}"
576                 [ ! -d "${FUSE_DIR}" ] &&
577                         gen_die "fuse directory ${FUSE_DIR} invalid"
578                 cd "${FUSE_DIR}"
579                 print_info 1 'fuse: >> Configuring...'
580                 ./configure  --disable-kernel-module --disable-example >> ${LOGFILE} 2>&1 ||
581                         gen_die 'Configuring fuse failed!'
582                 print_info 1 'fuse: >> Compiling...'
583                 MAKE=${UTILS_MAKE} compile_generic "" ""
584
585                 # Since we're linking statically against libfuse, we don't need to cache the .so
586 #               print_info 1 'libfuse: >> Copying to cache...'
587 #               [ -f "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ] ||
588 #                       gen_die 'libfuse.so does not exist!'
589 #               strip "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ||
590 #                       gen_die 'Could not strip libfuse.so!'
591 #               cd "${TEMP}/${FUSE_DIR}/lib/.libs"
592 #               tar -cjf "${FUSE_BINCACHE}" libfuse*so* ||
593 #                       gen_die 'Could not create fuse bincache!'
594
595                 cd "${TEMP}"
596 #               rm -rf "${FUSE_DIR}" > /dev/null
597         fi
598 }
599
600 compile_unionfs_fuse() {
601         if [ ! -f "${UNIONFS_FUSE_BINCACHE}" ]
602         then
603
604                 # We'll call compile_fuse() from here, since it's not needed directly by anything else
605                 compile_fuse
606
607                 [ ! -f "${UNIONFS_FUSE_SRCTAR}" ] &&
608                         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!"
609                 cd "${TEMP}"
610                 rm -rf "${UNIONFS_FUSE_DIR}"
611                 tar -jxpf "${UNIONFS_FUSE_SRCTAR}"
612                 [ ! -d "${UNIONFS_FUSE_DIR}" ] &&
613                         gen_die "unionfs-fuse directory ${UNIONFS_FUSE_DIR} invalid"
614                 cd "${UNIONFS_FUSE_DIR}"
615                 print_info 1 'unionfs-fuse: >> Compiling...'
616                 sed -i "/^\(CFLAGS\|CPPFLAGS\)/s:^\\(.*\\)$:\\1 -static -I${TEMP}/${FUSE_DIR}/include -L${TEMP}/${FUSE_DIR}/lib/.libs:" Makefile src/Makefile
617                 sed -i "/^LIB = /s:^LIB = \(.*\)$:LIB = -static -L${TEMP}/${FUSE_DIR}/lib/.libs \1 -ldl -lrt:" Makefile src/Makefile
618                 MAKE=${UTILS_MAKE} compile_generic "" ""
619                 print_info 1 'unionfs-fuse: >> Copying to cache...'
620                 [ -f "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ] ||
621                         gen_die 'unionfs binary does not exist!'
622                 strip "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
623                         gen_die 'Could not strip unionfs binary!'
624                 bzip2 "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
625                         gen_die 'bzip2 compression of unionfs binary failed!'
626                 mv "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs.bz2" "${UNIONFS_FUSE_BINCACHE}" ||
627                         gen_die 'Could not copy the unionfs binary to the package directory, does the directory exist?'
628
629                 cd "${TEMP}"
630                 rm -rf "${UNIONFS_FUSE_DIR}" > /dev/null
631         fi
632 }
633
634 compile_iscsi() {
635         if [ ! -f "${ISCSI_BINCACHE}" ]
636         then
637                 [ ! -f "${ISCSI_SRCTAR}" ] &&
638                         gen_die "Could not find iSCSI source tarball: ${ISCSI_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
639                 cd "${TEMP}"
640                 rm -rf "${ISCSI_DIR}"
641                 tar -zxpf "${ISCSI_SRCTAR}"
642                 [ ! -d "${ISCSI_DIR}" ] &&
643                         gen_die "ISCSI directory ${ISCSI_DIR} invalid"
644                                 print_info 1 'iSCSI: >> Compiling...'
645                 cd "${TEMP}/${ISCSI_DIR}"
646
647                 # Only build userspace
648                 MAKE=${UTILS_MAKE} compile_generic "user" ""
649         
650                 # if kernel modules exist, copy them to initramfs, otherwise it will be compiled into the kernel
651                 mkdir -p "${TEMP}/initramfs-iscsi-temp/lib/modules/${RELEASE}/kernel/drivers/scsi/"
652                 for modname in iscsi_tcp libiscsi scsi_transport_iscsi
653                 do
654                         if [ -e "${CMD_KERNEL_DIR}/drivers/scsi/${modname}.ko" ]
655                         then
656                                 cp ${CMD_KERNEL_DIR}/drivers/scsi/${modname}.ko "${TEMP}/initramfs-iscsi-temp/lib/modules/${RELEASE}/kernel/drivers/scsi/"
657                         fi
658                 done
659
660                 cd "${TEMP}/initramfs-iscsi-temp/"
661                 print_info 1 'iscsistart: >> Copying to cache...'
662                 [ -f "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ] ||
663                         gen_die 'iscsistart executable does not exist!'
664                 strip "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ||
665                         gen_die 'Could not strip iscsistart binary!'
666                 bzip2 "${TEMP}/${ISCSI_DIR}/usr/iscsistart" ||
667                         gen_die 'bzip2 compression of iscsistart failed!'
668                 mv "${TEMP}/${ISCSI_DIR}/usr/iscsistart.bz2" "${ISCSI_BINCACHE}" ||
669                         gen_die 'Could not copy the iscsistart binary to the package directory, does the directory exist?'
670
671                 cd "${TEMP}"
672                 rm -rf "${ISCSI_DIR}" > /dev/null
673         fi
674 }
675
676 compile_gpg() {
677         if [ -f "${GPG_BINCACHE}" ]
678         then
679                 print_info 1 "gnupg: >> Using cache"
680         else
681                 [ ! -f "${GPG_SRCTAR}" ] &&
682                         gen_die "Could not find gnupg source tarball: ${GPG_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
683                 cd "${TEMP}"
684                 rm -rf "${GPG_DIR}"
685                 tar -jxf "${GPG_SRCTAR}"
686                 [ ! -d "${GPG_DIR}" ] &&
687                         gen_die "gnupg directory ${GPG_DIR} invalid"
688                 cd "${GPG_DIR}"
689                 print_info 1 'gnupg: >> Configuring...'
690                 # --enable-minimal works, but it doesn't reduce the command length much.
691                 # Given its history and the precision this needs, explicit is cleaner.
692                 LDFLAGS='-static' CFLAGS='-Os' ./configure --prefix=/ \
693                         --enable-static-rnd=linux --disable-dev-random --disable-asm \
694                         --disable-selinux-support --disable-gnupg-iconv --disable-card-support \
695                         --disable-agent-support --disable-bzip2 --disable-exec \
696                         --disable-photo-viewers --disable-keyserver-helpers --disable-ldap \
697                         --disable-hkp --disable-finger --disable-generic --disable-mailto \
698                         --disable-keyserver-path --disable-dns-srv --disable-dns-pka \
699                         --disable-dns-cert --disable-nls --disable-threads --disable-regex \
700                         --disable-optimization --with-included-zlib --without-capabilities \
701                         --without-tar --without-ldap --without-libcurl --without-mailprog \
702                         --without-libpth-prefix --without-libiconv-prefix --without-libintl-prefix\
703                         --without-zlib --without-bzip2 --without-libusb --without-readline \
704                                 >> ${LOGFILE} 2>&1 || gen_die 'Configuring gnupg failed!'
705                 print_info 1 'gnupg: >> Compiling...'
706                 compile_generic "" "utils"
707                 print_info 1 'gnupg: >> Copying to cache...'
708                 [ -f "${TEMP}/${GPG_DIR}/g10/gpg" ] ||
709                         gen_die 'gnupg executable does not exist!'
710                 strip "${TEMP}/${GPG_DIR}/g10/gpg" ||
711                         gen_die 'Could not strip gpg binary!'
712                 bzip2 -z -c "${TEMP}/${GPG_DIR}/g10/gpg" > "${GPG_BINCACHE}" ||
713                         gen_die 'Could not copy the gpg binary to the package directory, does the directory exist?'
714
715                 cd "${TEMP}"
716                 rm -rf "${GPG_DIR}" > /dev/null
717         fi
718 }