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