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