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