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