70a2c79821c9d4a016dc33bc788677cc364eb7cc
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2
3 compile_kernel_args()
4 {
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         fi
25         echo -n "${ARGS}"
26 }
27
28 compile_utils_args()
29 {
30         local ARGS
31
32         ARGS=''
33         if [ "${UTILS_ARCH}" != '' ]
34         then
35                 ARGS="ARCH=\"${UTILS_ARCH}\""
36         fi
37         if [ "${UTILS_CC}" != '' ]
38         then
39                 ARGS="CC=\"${UTILS_CC}\""
40         fi
41         if [ "${UTILS_LD}" != '' ]
42         then
43                 ARGS="${ARGS} LD=\"${UTILS_LD}\""
44         fi
45         if [ "${UTILS_AS}" != '' ]
46         then
47                 ARGS="${ARGS} AS=\"${UTILS_AS}\""
48         fi
49
50         echo -n "${ARGS}"
51 }
52
53 export_utils_args()
54 {
55         save_args
56         if [ "${UTILS_ARCH}" != '' ]
57         then
58                 export ARCH="${UTILS_ARCH}"
59         fi
60         if [ "${UTILS_CC}" != '' ]
61         then
62                 export CC="${UTILS_CC}"
63         fi
64         if [ "${UTILS_LD}" != '' ]
65         then
66                 export LD="${UTILS_LD}"
67         fi
68         if [ "${UTILS_AS}" != '' ]
69         then
70                 export AS="${UTILS_AS}"
71         fi
72 }
73
74 unset_utils_args()
75 {
76         if [ "${UTILS_ARCH}" != '' ]
77         then
78                 unset ARCH
79         fi
80         if [ "${UTILS_CC}" != '' ]
81         then
82                 unset CC
83         fi
84         if [ "${UTILS_LD}" != '' ]
85         then
86                 unset LD
87         fi
88         if [ "${UTILS_AS}" != '' ]
89         then
90                 unset AS
91         fi
92         reset_args
93 }
94
95 export_kernel_args()
96 {
97         if [ "${KERNEL_CC}" != '' ]
98         then
99                 export CC="${KERNEL_CC}"
100         fi
101         if [ "${KERNEL_LD}" != '' ]
102         then
103                 export LD="${KERNEL_LD}"
104         fi
105         if [ "${KERNEL_AS}" != '' ]
106         then
107                 export AS="${KERNEL_AS}"
108         fi
109         if [ "${KERNEL_CROSS_COMPILE}" != '' ]
110         then
111                 export CROSS_COMPILE="${KERNEL_CROSS_COMPILE}"
112         fi
113 }
114
115 unset_kernel_args()
116 {
117         if [ "${KERNEL_CC}" != '' ]
118         then
119                 unset CC
120         fi
121         if [ "${KERNEL_LD}" != '' ]
122         then
123                 unset LD
124         fi
125         if [ "${KERNEL_AS}" != '' ]
126         then
127                 unset AS
128         fi
129         if [ "${KERNEL_CROSS_COMPILE}" != '' ]
130         then
131                 unset CROSS_COMPILE
132         fi
133 }
134 save_args()
135 {
136         if [ "${ARCH}" != '' ]
137         then
138                 export ORIG_ARCH="${ARCH}"
139         fi
140         if [ "${CC}" != '' ]
141         then
142                 export ORIG_CC="${CC}"
143         fi
144         if [ "${LD}" != '' ]
145         then
146                 export ORIG_LD="${LD}"
147         fi
148         if [ "${AS}" != '' ]
149         then
150                 export ORIG_AS="${AS}"
151         fi
152         if [ "${CROSS_COMPILE}" != '' ]
153         then
154                 export ORIG_CROSS_COMPILE="${CROSS_COMPILE}"
155         fi
156 }
157 reset_args()
158 {
159         if [ "${ORIG_ARCH}" != '' ]
160         then
161                 export ARCH="${ORIG_ARCH}"
162                 unset ORIG_ARCH
163         fi
164         if [ "${ORIG_CC}" != '' ]
165         then
166                 export CC="${ORIG_CC}"
167                 unset ORIG_CC
168         fi
169         if [ "${ORIG_LD}" != '' ]
170         then
171                 export LD="${ORIG_LD}"
172                 unset ORIG_LD
173         fi
174         if [ "${ORIG_AS}" != '' ]
175         then
176                 export AS="${ORIG_AS}"
177                 unset ORIG_AS
178         fi
179         if [ "${ORIG_CROSS_COMPILE}" != '' ]
180         then
181                 export CROSS_COMPILE="${ORIG_CROSS_COMPILE}"
182                 unset ORIG_CROSS_COMPILE
183         fi
184 }
185
186
187 compile_generic() {
188         local RET
189         [ "$#" -lt '2' ] &&
190                 gen_die 'compile_generic(): improper usage!'
191         local target=${1}
192         local argstype=${2}
193
194         if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
195         then
196                 export_kernel_args
197                 MAKE=${KERNEL_MAKE}
198         elif [ "${2}" = 'utils' ]
199         then
200                 export_utils_args
201                 MAKE=${UTILS_MAKE}
202         fi
203         case "${argstype}" in
204                 kernel) ARGS="`compile_kernel_args`" ;;
205                 utils) ARGS="`compile_utils_args`" ;;
206                 *) ARGS="" ;; # includes runtask
207         esac
208         shift 2
209
210
211         # the eval usage is needed in the next set of code
212         # as ARGS can contain spaces and quotes, eg:
213         # ARGS='CC="ccache gcc"'
214         if [ "${argstype}" == 'runtask' ]
215         then
216                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
217                 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
218                 RET=$?
219         elif [ "${LOGLEVEL}" -gt "1" ]
220         then
221                 # Output to stdout and logfile
222                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
223                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
224                 RET=${PIPESTATUS[0]}
225         else
226                 # Output to logfile only
227                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
228                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
229                 RET=$?
230         fi
231         [ "${RET}" -ne '0' ] &&
232                 gen_die "Failed to compile the \"${target}\" target..."
233
234         unset MAKE
235         unset ARGS
236         if [ "${argstype}" = 'kernel' ]
237         then
238                 unset_kernel_args
239         elif [ "${argstype}" = 'utils' ]
240         then
241                 unset_utils_args
242         fi
243 }
244
245 extract_dietlibc_bincache() {
246         cd "${TEMP}"
247         rm -rf "${TEMP}/diet" > /dev/null
248         /bin/tar -jxpf "${DIETLIBC_BINCACHE}" ||
249                 gen_die 'Could not extract dietlibc bincache!'
250         [ ! -d "${TEMP}/diet" ] &&
251                 gen_die "${TEMP}/diet directory not found!"
252         cd - > /dev/null
253 }
254
255 clean_dietlibc_bincache() {
256         cd "${TEMP}"
257         rm -rf "${TEMP}/diet" > /dev/null
258         cd - > /dev/null
259 }
260
261 compile_dep() {
262         # Only run ``make dep'' for 2.4 kernels
263         if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
264         then
265                 print_info 1 "kernel: >> Making dependencies..."
266                 cd ${KERNEL_DIR}
267                 compile_generic dep kernel
268         fi
269 }
270
271 compile_modules() {
272         print_info 1 "        >> Compiling ${KV} modules..."
273         cd ${KERNEL_DIR}
274         compile_generic modules kernel
275         export UNAME_MACHINE="${ARCH}"
276         # On 2.4 kernels, if MAKEOPTS > -j1 it can cause failures
277         if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
278         then
279                 MAKEOPTS_SAVE="${MAKEOPTS}"
280                 MAKEOPTS="${MAKEOPTS_SAVE/-j?/-j1}"
281         fi
282         [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
283         compile_generic "modules_install" kernel
284         [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ] && MAKEOPTS="${MAKEOPTS_SAVE}"
285         export MAKEOPTS
286         unset UNAME_MACHINE
287 }
288
289 compile_kernel() {
290         [ "${KERNEL_MAKE}" = '' ] &&
291                 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
292         cd ${KERNEL_DIR}
293         print_info 1 "        >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
294         compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
295         if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
296         then
297                 print_info 1 "        >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
298                 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
299         fi
300         if ! isTrue "${CMD_NOINSTALL}"
301         then
302                 copy_image_with_preserve "kernel" \
303                         "${KERNEL_BINARY}" \
304                         "kernel-${KNAME}-${ARCH}-${KV}"
305
306                 copy_image_with_preserve "System.map" \
307                         "System.map" \
308                         "System.map-${KNAME}-${ARCH}-${KV}"
309
310                 if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
311                 then
312                         copy_image_with_preserve "kernelz" \
313                                 "${KERNEL_BINARY_2}" \
314                                 "kernelz-${KV}"
315                 fi
316         else
317                 cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
318                         gen_die "Could not copy the kernel binary to ${TMPDIR}!"
319                 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
320                         gen_die "Could not copy System.map to ${TMPDIR}!"
321                 if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
322                 then
323                         cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
324                                 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
325                 fi
326         fi
327 }
328
329 compile_unionfs_modules() {
330         if [ ! -f "${UNIONFS_MODULES_BINCACHE}" ]
331         then
332                 [ -f "${UNIONFS_SRCTAR}" ] ||
333                         gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!"
334                 cd "${TEMP}"
335                 rm -rf ${UNIONFS_DIR} > /dev/null
336                 rm -rf unionfs* > /dev/null
337                 mkdir unionfs
338                 /bin/tar xzpf ${UNIONFS_SRCTAR} ||
339                         gen_die 'Could not extract unionfs source tarball!'
340                 [ -d "${UNIONFS_DIR}" ] ||
341                         gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!'
342                 cd "${UNIONFS_DIR}"
343                 print_info 1 'unionfs modules: >> Compiling...'
344                 echo "LINUXSRC=${KERNEL_DIR}" >> fistdev.mk
345                 echo 'TOPINC=-I$(LINUXSRC)/include' >> fistdev.mk
346                 echo "MODDIR= /lib/modules/${KV}" >> fistdev.mk
347                 echo "KVERS=${KV}" >> fistdev.mk
348                 echo "KERNELVERSION=${KV}" >> fistdev.mk
349                 # Fix for hardened/selinux systems to have extened attributes
350                 # per r2d2's request.  Also add -DUNIONFS_UNSUPPORTED for 2.6.16
351                 echo "EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID -DUNIONFS_UNSUPPORTED" \
352                         >> fistdev.mk
353                 # Here we do something really nasty and disable debugging, along with
354                 # change our default CFLAGS
355                 echo "UNIONFS_DEBUG_CFLAG=-DUNIONFS_NDEBUG" >> fistdev.mk
356                 echo "UNIONFS_OPT_CFLAG= -O2 -pipe" >> fistdev.mk
357
358                 if [ "${PAT}" -ge '6' ]
359                 then
360                         # ARCH is used by unionfs - and conflicts with genkernel
361                         ARCH_PUSH=${ARCH}
362                         unset ARCH
363                         # Compile unionfs module within the unionfs
364                         # environment not within the kernelsrc dir
365                         make unionfs.ko || gen_die 'failed to compile unionfs'
366                         ARCH=${ARCH_PUSH}
367                 else
368                         gen_die 'unionfs is only supported on 2.6 targets'
369                 fi
370                 print_info 1 'unionfs: >> Copying to cache...'
371         
372                 mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs
373                 
374                 if [ -f unionfs.ko ]
375                 then 
376                         cp -f unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs
377                 else
378                         cp -f unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs/unionfs
379                 fi
380         
381                 cd ${TEMP}/unionfs
382                 /bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . ||
383                         gen_die 'Could not create unionfs modules binary cache'
384         
385                 cd "${TEMP}"
386                 rm -rf "${UNIONFS_DIR}" > /dev/null
387                 rm -rf unionfs > /dev/null
388         fi
389 }
390
391 compile_unionfs_utils() {
392         if [ ! -f "${UNIONFS_BINCACHE}" ]
393         then
394                 [ -f "${UNIONFS_SRCTAR}" ] ||
395                         gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!"
396                 cd "${TEMP}"
397                 rm -rf ${UNIONFS_DIR} > /dev/null
398                 rm -rf unionfs* > /dev/null
399                 mkdir -p unionfs/sbin
400                 /bin/tar -zxpf ${UNIONFS_SRCTAR} ||
401                         gen_die 'Could not extract unionfs source tarball!'
402                 [ -d "${UNIONFS_DIR}" ] ||
403                         gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!'
404                 cd "${UNIONFS_DIR}"
405                 print_info 1 'unionfs tools: >> Compiling...'
406                 sed -i utils/Makefile -e 's|${CC} -o|${CC} -static -o|g'
407                 sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g'
408                 compile_generic utils utils
409
410                 if [ ! -e "uniondbg" ]; then
411                         cd utils
412                 fi
413                 print_info 1 'unionfs: >> Copying to cache...'
414                 strip uniondbg unionctl
415                 cp uniondbg ${TEMP}/unionfs/sbin/ || 
416                         gen_die 'Could not copy the uniondbg binary to the tmp directory'
417                 cp unionctl ${TEMP}/unionfs/sbin/ ||
418                         gen_die 'Could not copy the unionctl binary to the tmp directory'
419                 cd ${TEMP}/unionfs
420                 /bin/tar -cjf "${UNIONFS_BINCACHE}" . ||
421                         gen_die 'Could not create unionfs tools binary cache'
422                 
423                 cd "${TEMP}"
424                 rm -rf "${UNIONFS_DIR}" > /dev/null
425                 rm -rf unionfs > /dev/null
426         fi
427 }
428
429 compile_busybox() {
430         [ -f "${BUSYBOX_SRCTAR}" ] ||
431                 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
432         [ -f "${BUSYBOX_CONFIG}" ] ||
433                 gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
434         cd "${TEMP}"
435         rm -rf "${BUSYBOX_DIR}" > /dev/null
436         /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
437                 gen_die 'Could not extract busybox source tarball!'
438         [ -d "${BUSYBOX_DIR}" ] ||
439                 gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
440         cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
441         sed -i ${BUSYBOX_DIR}/.config -e 's/#\? \?CONFIG_FEATURE_INSTALLER[ =].*/CONFIG_FEATURE_INSTALLER=y/g'
442         cd "${BUSYBOX_DIR}"
443         patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm.patch"
444         print_info 1 'busybox: >> Configuring...'
445         yes '' 2>/dev/null | compile_generic oldconfig utils
446
447         # Delete cache if stored config's MD5 does not match one to be used
448         if [ -f "${BUSYBOX_BINCACHE}" -a -f "${BUSYBOX_CONFIG}" ]
449         then
450                 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config | md5sum)
451                 newconfig_md5=$(md5sum < .config)
452                 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
453                 then
454                         print_info 1 "busybox: >> Removing stale cache..."
455                         rm -rf "${BUSYBOX_BINCACHE}"
456                 else
457                         print_info 1 "busybox: >> Using cache"
458                 fi
459         fi
460
461         if [ ! -f "${BUSYBOX_BINCACHE}" ]
462         then
463                 print_info 1 'busybox: >> Compiling...'
464                 compile_generic all utils
465                 print_info 1 'busybox: >> Copying to cache...'
466                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
467                         gen_die 'Busybox executable does not exist!'
468                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
469                         gen_die 'Could not strip busybox binary!'
470                 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config ||
471                         gen_die 'Could not create the busybox bincache!'
472         fi
473
474         cd "${TEMP}"
475         rm -rf "${BUSYBOX_DIR}" > /dev/null
476 }
477
478 compile_lvm() {
479         compile_device_mapper
480         if [ ! -f "${LVM_BINCACHE}" ]
481         then
482                 [ -f "${LVM_SRCTAR}" ] ||
483                         gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
484                 cd "${TEMP}"
485                 rm -rf ${LVM_DIR} > /dev/null
486                 /bin/tar -zxpf ${LVM_SRCTAR} ||
487                         gen_die 'Could not extract LVM source tarball!'
488                 [ -d "${LVM_DIR}" ] ||
489                         gen_die 'LVM directory ${LVM_DIR} is invalid!'
490                 rm -rf "${TEMP}/device-mapper" > /dev/null
491                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
492                         gen_die "Could not extract device-mapper binary cache!";
493                 
494                 cd "${LVM_DIR}"
495                 print_info 1 'lvm: >> Configuring...'
496                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
497                         CFLAGS="-I${TEMP}/device-mapper/include" \
498                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
499                         ./configure --enable-static_link --prefix=${TEMP}/lvm >> ${LOGFILE} 2>&1 ||
500                                 gen_die 'Configure of lvm failed!'
501                 print_info 1 'lvm: >> Compiling...'
502                         compile_generic '' utils
503                         compile_generic 'install' utils
504
505                 cd "${TEMP}/lvm"
506                 print_info 1 '      >> Copying to bincache...'
507                 strip "sbin/lvm.static" ||
508                         gen_die 'Could not strip lvm.static!'
509                 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
510                         gen_die 'Could not create binary cache'
511
512                 cd "${TEMP}"
513                 rm -rf "${TEMP}/device-mapper" > /dev/null
514                 rm -rf "${LVM_DIR}" lvm
515         fi
516 }
517
518 compile_dmraid() {
519         compile_device_mapper
520         if [ ! -f "${DMRAID_BINCACHE}" ]
521         then
522                 [ -f "${DMRAID_SRCTAR}" ] ||
523                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
524                 cd "${TEMP}"
525                 rm -rf ${DMRAID_DIR} > /dev/null
526                 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
527                         gen_die 'Could not extract DMRAID source tarball!'
528                 [ -d "${DMRAID_DIR}" ] ||
529                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
530                 rm -rf "${TEMP}/device-mapper" > /dev/null
531                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
532                         gen_die "Could not extract device-mapper binary cache!";
533                 
534                 cd "${DMRAID_DIR}"
535                 print_info 1 'dmraid: >> Configuring...'
536                 
537                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
538                         CFLAGS="-I${TEMP}/device-mapper/include" \
539                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
540                         ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
541                                 gen_die 'Configure of dmraid failed!'
542                                 
543                         # We dont necessarily have selinux installed yet... look into
544                         # selinux global support in the future.
545                         sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
546                         ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
547                 mkdir -p "${TEMP}/dmraid"
548                 print_info 1 'dmraid: >> Compiling...'
549                         compile_generic '' utils
550                         #compile_generic 'install' utils
551                         mkdir ${TEMP}/dmraid/sbin
552                         install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
553                 print_info 1 '      >> Copying to bincache...'
554                 cd "${TEMP}/dmraid"
555                 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
556                         gen_die 'Could not create binary cache'
557
558                 cd "${TEMP}"
559                 rm -rf "${TEMP}/device-mapper" > /dev/null
560                 rm -rf "${DMRAID_DIR}" dmraid
561         fi
562 }
563
564 compile_devfsd() {
565         local ARGS
566         if [ ! -f "${DEVFSD_BINCACHE}" ]
567         then
568                 [ ! -f "${DEVFSD_SRCTAR}" ] &&
569                         gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
570                 cd "${TEMP}"
571                 rm -rf "${DEVFSD_DIR}"
572                 /bin/tar -jxpf "${DEVFSD_SRCTAR}"
573                 [ ! -d "${DEVFSD_DIR}" ] &&
574                         gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
575                 cd "${DEVFSD_DIR}"
576
577                 print_info 1 'devfsd: >> Compiling...'
578                 compile_generic 'LDFLAGS=-static' utils
579
580                 print_info 1 '        >> Copying to cache...'
581                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] || gen_die 'The devfsd executable does not exist after the compilation of devfsd!'
582                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Could not strip devfsd!'
583                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Compression of devfsd failed!'
584                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] || gen_die 'Could not find compressed devfsd.bz2 binary!'
585                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die 'Could not move compressed binary to the package cache!'
586
587                 cd "${TEMP}"
588                 rm -rf "${DEVFSD_DIR}" > /dev/null
589         fi
590 }
591
592 compile_device_mapper() {
593         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
594         then
595                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
596                         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!"
597                 cd "${TEMP}"
598                 rm -rf "${DEVICE_MAPPER_DIR}"
599                 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
600                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
601                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
602                 cd "${DEVICE_MAPPER_DIR}"
603                 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
604                         --disable-selinux >> ${LOGFILE} 2>&1 ||
605                         gen_die 'Configuring device-mapper failed!'
606                 print_info 1 'device-mapper: >> Compiling...'
607                 compile_generic '' utils
608                 compile_generic 'install' utils
609                 print_info 1 '        >> Copying to cache...'
610                 cd "${TEMP}"
611                 rm -rf "${TEMP}/device-mapper/man" ||
612                         gen_die 'Could not remove manual pages!'
613                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
614                         gen_die 'Could not strip dmsetup binary!'
615                 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
616                         gen_die 'Could not tar up the device-mapper binary!'
617                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
618                         gen_die 'device-mapper cache not created!'
619                 cd "${TEMP}"
620                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
621                 rm -rf "${TEMP}/device-mapper" > /dev/null
622         fi
623 }
624
625 compile_e2fsprogs() {
626         if [ ! -f "${BLKID_BINCACHE}" ]
627         then
628                 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
629                         gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
630                 cd "${TEMP}"
631                 rm -rf "${E2FSPROGS_DIR}"
632                 tar -zxpf "${E2FSPROGS_SRCTAR}"
633                 [ ! -d "${E2FSPROGS_DIR}" ] &&
634                         gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
635                 cd "${E2FSPROGS_DIR}"
636                 print_info 1 'e2fsprogs: >> Configuring...'
637                 ./configure  --with-ldopts=-static >> ${LOGFILE} 2>&1 ||
638                         gen_die 'Configuring e2fsprogs failed!'
639                 print_info 1 'e2fsprogs: >> Compiling...'
640                 MAKE=${UTILS_MAKE} compile_generic "" ""
641                 print_info 1 'blkid: >> Copying to cache...'
642                 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
643                         gen_die 'Blkid executable does not exist!'
644                 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
645                         gen_die 'Could not strip blkid binary!'
646                 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
647                         gen_die 'bzip2 compression of blkid failed!'
648                 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
649                         gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
650
651                 cd "${TEMP}"
652                 rm -rf "${E2FSPROGS_DIR}" > /dev/null
653         fi
654 }