mkdir -> mkdir -p
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2
3 compile_kernel_args()
4 {
5         local ARGS
6
7         ARGS=''
8         if [ "${KERNEL_CC}" != '' ]
9         then
10                 ARGS="CC=\"${KERNEL_CC}\""
11         fi
12         if [ "${KERNEL_LD}" != '' ]
13         then
14                 ARGS="${ARGS} LD=\"${KERNEL_LD}\""
15         fi
16         if [ "${KERNEL_AS}" != '' ]
17         then
18                 ARGS="${ARGS} AS=\"${KERNEL_AS}\""
19         fi
20
21         echo -n "${ARGS}"
22 }
23
24 compile_utils_args()
25 {
26         local ARGS
27
28         ARGS=''
29         if [ "${UTILS_CC}" != '' ]
30         then
31                 ARGS="CC=\"${UTILS_CC}\""
32         fi
33         if [ "${UTILS_LD}" != '' ]
34         then
35                 ARGS="${ARGS} LD=\"${UTILS_LD}\""
36         fi
37         if [ "${UTILS_AS}" != '' ]
38         then
39                 ARGS="${ARGS} AS=\"${UTILS_AS}\""
40         fi
41
42         echo -n "${ARGS}"
43 }
44
45 export_utils_args()
46 {
47         if [ "${UTILS_CC}" != '' ]
48         then
49                 export CC="${UTILS_CC}"
50         fi
51         if [ "${UTILS_LD}" != '' ]
52         then
53                 export LD="${UTILS_LD}"
54         fi
55         if [ "${UTILS_AS}" != '' ]
56         then
57                 export AS="${UTILS_AS}"
58         fi
59 }
60
61 unset_utils_args()
62 {
63         if [ "${UTILS_CC}" != '' ]
64         then
65                 unset CC
66         fi
67         if [ "${UTILS_LD}" != '' ]
68         then
69                 unset LD
70         fi
71         if [ "${UTILS_AS}" != '' ]
72         then
73                 unset AS
74         fi
75 }
76
77 export_kernel_args()
78 {
79         if [ "${KERNEL_CC}" != '' ]
80         then
81                 export CC="${KERNEL_CC}"
82         fi
83         if [ "${KERNEL_LD}" != '' ]
84         then
85                 export LD="${KERNEL_LD}"
86         fi
87         if [ "${KERNEL_AS}" != '' ]
88         then
89                 export AS="${KERNEL_AS}"
90         fi
91 }
92
93 unset_kernel_args()
94 {
95         if [ "${KERNEL_CC}" != '' ]
96         then
97                 unset CC
98         fi
99         if [ "${KERNEL_LD}" != '' ]
100         then
101                 unset LD
102         fi
103         if [ "${KERNEL_AS}" != '' ]
104         then
105                 unset AS
106         fi
107 }
108
109 compile_generic() {
110         local RET
111         [ "$#" -lt '2' ] &&
112                 gen_die 'compile_generic(): improper usage!'
113
114         if [ "${2}" = 'kernel' ] || [ "${2}" = 'runtask' ]
115         then
116                 export_kernel_args
117                 MAKE=${KERNEL_MAKE}
118         elif [ "${2}" = 'utils' ]
119         then
120                 export_utils_args
121                 MAKE=${UTILS_MAKE}
122         fi
123         case "$2" in
124                 kernel) ARGS="`compile_kernel_args`" ;;
125                 utils) ARGS="`compile_utils_args`" ;;
126                 *) ARGS="" ;; # includes runtask
127         esac
128                 
129
130         # the eval usage is needed in the next set of code
131         # as ARGS can contain spaces and quotes, eg:
132         # ARGS='CC="ccache gcc"'
133         if [ "${2}" == 'runtask' ]
134         then
135                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${1}" 1 0 1
136                 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${1}
137                 RET=$?
138         elif [ "${DEBUGLEVEL}" -gt "1" ]
139         then
140                 # Output to stdout and debugfile
141                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1}" 1 0 1
142                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${1} 2>&1 | tee -a ${DEBUGFILE}
143                 RET=${PIPESTATUS[0]}
144         else
145                 # Output to debugfile only
146                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1}" 1 0 1
147                 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${1} >> ${DEBUGFILE} 2>&1
148                 RET=$?
149         fi
150         [ "${RET}" -ne '0' ] &&
151                 gen_die "Failed to compile the \"${1}\" target..."
152
153         unset MAKE
154         unset ARGS
155         if [ "${2}" = 'kernel' ]
156         then
157                 unset_kernel_args
158         elif [ "${2}" = 'utils' ]
159         then
160                 unset_utils_args
161         fi
162 }
163
164 extract_dietlibc_bincache() {
165         cd "${TEMP}"
166         rm -rf "${TEMP}/diet" > /dev/null
167         tar -jxpf "${DIETLIBC_BINCACHE}" ||
168                 gen_die 'Could not extract dietlibc bincache!'
169         [ ! -d "${TEMP}/diet" ] &&
170                 gen_die "${TEMP}/diet directory not found!"
171         cd - > /dev/null
172 }
173
174 clean_dietlibc_bincache() {
175         cd "${TEMP}"
176         rm -rf "${TEMP}/diet" > /dev/null
177         cd - > /dev/null
178 }
179
180 compile_dep() {
181         # Only run ``make dep'' for 2.4 kernels
182         if [ "${VER}" -eq '2' -a "${PAT}" -le '4' ]
183         then
184                 print_info 1 "kernel: >> Making dependencies..."
185                 cd ${KERNEL_DIR}
186                 compile_generic dep kernel
187         fi
188 }
189
190 compile_modules() {
191         print_info 1 "        >> Compiling ${KV} modules..."
192         cd ${KERNEL_DIR}
193         compile_generic modules kernel
194         export UNAME_MACHINE="${ARCH}"
195         # On 2.4 kernels, if MAKEOPTS > -j1 it can cause failures
196         if [ "${VER}" -eq '2' -a "${PAT}" -le '4' ]
197         then
198                 MAKEOPTS_SAVE="${MAKEOPTS}"
199                 MAKEOPTS="${MAKEOPTS_SAVE/-j?/-j1}"
200         fi
201         [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
202         compile_generic "modules_install" kernel
203         [ "${VER}" -eq '2' -a "${PAT}" -le '4' ] && MAKEOPTS="${MAKEOPTS_SAVE}"
204         export MAKEOPTS
205         unset UNAME_MACHINE
206 }
207
208 compile_kernel() {
209         [ "${KERNEL_MAKE}" = '' ] &&
210                 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
211         cd ${KERNEL_DIR}
212         print_info 1 "        >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
213         compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
214         if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
215         then
216                 print_info 1 "        >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
217                 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
218         fi
219         if ! isTrue "${CMD_NOINSTALL}"
220         then
221                 cp "${KERNEL_BINARY}" "/boot/kernel-${KV}" ||
222                         gen_die 'Could not copy the kernel binary to /boot!'
223                 cp "System.map" "/boot/System.map-${KV}" ||
224                         gen_die 'Could not copy System.map to /boot!'
225         else
226                 cp "${KERNEL_BINARY}" "${TEMP}/kernel-${KV}" ||
227                         gen_die "Could not copy the kernel binary to ${TEMP}!"
228                 cp "System.map" "${TEMP}/System.map-${KV}" ||
229                         gen_die "Could not copy System.map to ${TEMP}!"
230         fi
231 }
232
233 compile_busybox() {
234         if [ ! -f "${BUSYBOX_BINCACHE}" ]
235         then
236                 [ -f "${BUSYBOX_SRCTAR}" ] ||
237                         gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
238                 [ -f "${BUSYBOX_CONFIG}" ] ||
239                         gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
240                 cd "${TEMP}"
241                 rm -rf ${BUSYBOX_DIR} > /dev/null
242                 tar -jxpf ${BUSYBOX_SRCTAR} ||
243                         gen_die 'Could not extract busybox source tarball!'
244                 [ -d "${BUSYBOX_DIR}" ] ||
245                         gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
246                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
247                 cd "${BUSYBOX_DIR}"
248 # Busybox and dietlibc don't play nice right now
249 #               if [ "${USE_DIETLIBC}" -eq "1" ]
250 #               then
251 #                       extract_dietlibc_bincache
252 #                       OLD_CC="${UTILS_CC}"
253 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
254 #               fi
255                 print_info 1 'busybox: >> Configuring...'
256                 yes '' 2>/dev/null | compile_generic oldconfig utils
257                 print_info 1 'busybox: >> Compiling...'
258                 compile_generic all utils
259 # Busybox and dietlibc don't play nice right now
260 #               if [ "${USE_DIETLIBC}" -eq "1" ]
261 #               then
262 #                       clean_dietlibc_bincache
263 #                       UTILS_CC="${OLD_CC}"
264 #               fi
265                 print_info 1 'busybox: >> Copying to cache...'
266                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
267                         gen_die 'Busybox executable does not exist!'
268                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
269                         gen_die 'Could not strip busybox binary!'
270                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" ||
271                         gen_die 'bzip2 compression of busybox failed!'
272                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" ||
273                         gen_die 'Could not copy the busybox binary to the package directory, does the directory exist?'
274
275                 cd "${TEMP}"
276                 rm -rf "${BUSYBOX_DIR}" > /dev/null
277         fi
278 }
279
280 compile_lvm2() {
281         compile_device_mapper
282         if [ ! -f "${LVM2_BINCACHE}" ]
283         then
284                 [ -f "${LVM2_SRCTAR}" ] ||
285                         gen_die "Could not find LVM2 source tarball: ${LVM2_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
286                 cd "${TEMP}"
287                 rm -rf ${LVM2_DIR} > /dev/null
288                 tar -zxpf ${LVM2_SRCTAR} ||
289                         gen_die 'Could not extract LVM2 source tarball!'
290                 [ -d "${LVM2_DIR}" ] ||
291                         gen_die 'LVM2 directory ${LVM2_DIR} is invalid!'
292                 rm -rf "${TEMP}/device-mapper" > /dev/null
293                 tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
294                         gen_die "Could not extract device-mapper binary cache!";
295                 
296                 cd "${LVM2_DIR}"
297                 print_info 1 'lvm2: >> Configuring...'
298                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
299                         CFLAGS="-I${TEMP}/device-mapper/include" \
300                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
301                         ./configure --enable-static_link --prefix=${TEMP}/lvm2 >> ${DEBUGFILE} 2>&1 ||
302                                 gen_die 'Configure of lvm2 failed!'
303                 print_info 1 'lvm2: >> Compiling...'
304                         compile_generic '' utils
305                         compile_generic 'install' utils
306
307                 cd "${TEMP}/lvm2"
308                 print_info 1 '      >> Copying to bincache...'
309                 strip "sbin/lvm.static" ||
310                         gen_die 'Could not strip lvm.static!'
311                 tar -cjf "${LVM2_BINCACHE}" sbin/lvm.static ||
312                         gen_die 'Could not create binary cache'
313
314                 cd "${TEMP}"
315                 rm -rf "${TEMP}/device-mapper" > /dev/null
316                 rm -rf "${LVM2_DIR}" lvm2
317         fi
318 }
319
320 compile_dmraid() {
321         compile_device_mapper
322         if [ ! -f "${DMRAID_BINCACHE}" ]
323         then
324                 [ -f "${DMRAID_SRCTAR}" ] ||
325                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
326                 cd "${TEMP}"
327                 rm -rf ${DMRAID_DIR} > /dev/null
328                 tar -jxpf ${DMRAID_SRCTAR} ||
329                         gen_die 'Could not extract DMRAID source tarball!'
330                 [ -d "${DMRAID_DIR}" ] ||
331                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
332                 rm -rf "${TEMP}/device-mapper" > /dev/null
333                 tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
334                         gen_die "Could not extract device-mapper binary cache!";
335                 
336                 cd "${DMRAID_DIR}"
337                 print_info 1 'dmraid: >> Configuring...'
338                 
339                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
340                         CFLAGS="-I${TEMP}/device-mapper/include" \
341                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
342                         ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${DEBUGFILE} 2>&1 ||
343                                 gen_die 'Configure of dmraid failed!'
344                 mkdir -p "${TEMP}/dmraid"
345                 print_info 1 'dmraid: >> Compiling...'
346                         compile_generic '' utils
347                         #compile_generic 'install' utils
348                         mkdir ${TEMP}/dmraid/sbin
349                         install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
350                 print_info 1 '      >> Copying to bincache...'
351                 cd "${TEMP}/dmraid"
352                 tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
353                         gen_die 'Could not create binary cache'
354
355                 cd "${TEMP}"
356                 rm -rf "${TEMP}/device-mapper" > /dev/null
357                 rm -rf "${DMRAID_DIR}" dmraid
358         fi
359 }
360
361 compile_modutils() {
362         # I've disabled dietlibc support for the time being since the
363         # version we use misses a few needed system calls.
364
365         local ARGS
366         if [ ! -f "${MODUTILS_BINCACHE}" ]
367         then
368                 [ ! -f "${MODUTILS_SRCTAR}" ] &&
369                         gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}!"
370                 cd "${TEMP}"
371                 rm -rf "${MODUTILS_DIR}"
372                 tar -jxpf "${MODUTILS_SRCTAR}"
373                 [ ! -d "${MODUTILS_DIR}" ] &&
374                         gen_die "Modutils directory ${MODUTILS_DIR} invalid!"
375                 cd "${MODUTILS_DIR}"
376                 print_info 1 "modutils: >> Configuring..."
377
378 #               if [ "${USE_DIETLIBC}" -eq '1' ]
379 #               then
380 #                       extract_dietlibc_bincache
381 #                       OLD_CC="${UTILS_CC}"
382 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
383 #               fi
384
385                 export_utils_args
386                 export ARCH=${ARCH}
387                 ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 ||
388                         gen_die 'Configuring modutils failed!'
389                 unset_utils_args
390
391                 print_info 1 'modutils: >> Compiling...'
392                 compile_generic all utils
393
394 #               if [ "${USE_DIETLIBC}" -eq '1' ]
395 #               then
396 #                       clean_dietlibc_bincache
397 #                       UTILS_CC="${OLD_CC}"
398 #               fi
399
400                 print_info 1 'modutils: >> Copying to cache...'
401                 [ -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] ||
402                         gen_die 'insmod.static does not exist after the compilation of modutils!'
403                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
404                         gen_die 'Could not strip insmod.static!'
405                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
406                         gen_die 'Compression of insmod.static failed!'
407                 mv "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" "${MODUTILS_BINCACHE}" ||
408                         gen_die 'Could not move the compressed insmod binary to the package cache!'
409
410                 cd "${TEMP}"
411                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
412         fi
413 }
414
415 compile_module_init_tools() {
416         # I've disabled dietlibc support for the time being since the
417         # version we use misses a few needed system calls.
418
419         local ARGS
420         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
421         then
422                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] &&
423                         gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
424                 cd "${TEMP}"
425                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
426                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
427                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] &&
428                         gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} is invalid"
429                 cd "${MODULE_INIT_TOOLS_DIR}"
430                 print_info 1 'module-init-tools: >> Configuring'
431
432 #               if [ "${USE_DIETLIBC}" -eq '1' ]
433 #               then
434 #                       extract_dietlibc_bincache
435 #                       OLD_CC="${UTILS_CC}"
436 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
437 #               fi
438
439                 export_utils_args
440                 ./configure >> ${DEBUGFILE} 2>&1 ||
441                         gen_die 'Configure of module-init-tools failed!'
442                 unset_utils_args
443                 print_info 1 '                   >> Compiling...'
444                 compile_generic "all" utils
445
446 #               if [ "${USE_DIETLIBC}" -eq '1' ]
447 #               then
448 #                       clean_dietlibc_bincache
449 #                       UTILS_CC="${OLD_CC}"
450 #               fi
451
452                 print_info 1 '                   >> Copying to cache...'
453                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] ||
454                         gen_die 'insmod.static does not exist after the compilation of module-init-tools!'
455                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
456                         gen_die 'Could not strip insmod.static!'
457                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
458                         gen_die 'Compression of insmod.static failed!'
459                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] ||
460                         gen_die 'Could not find compressed insmod.static.bz2 binary!'
461                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}" ||
462                         gen_die 'Could not move the compressed insmod binary to the package cache!'
463
464                 cd "${TEMP}"
465                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
466         fi
467 }
468
469 compile_devfsd() {
470         # I've disabled dietlibc support for the time being since the
471         # version we use misses a few needed system calls.
472
473         local ARGS
474         if [ ! -f "${DEVFSD_BINCACHE}" ]
475         then
476                 [ ! -f "${DEVFSD_SRCTAR}" ] &&
477                         gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
478                 cd "${TEMP}"
479                 rm -rf "${DEVFSD_DIR}"
480                 tar -jxpf "${DEVFSD_SRCTAR}"
481                 [ ! -d "${DEVFSD_DIR}" ] &&
482                         gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
483                 cd "${DEVFSD_DIR}"
484
485 #               if [ "${USE_DIETLIBC}" -eq '1' ]
486 #               then
487 #                       extract_dietlibc_bincache
488 #                       OLD_CC="${UTILS_CC}"
489 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
490 #               fi
491
492                 print_info 1 'devfsd: >> Compiling...'
493 #               if [ "${USE_DIETLIBC}" -eq '1' ]
494 #               then
495 #                       compile_generic 'has_dlopen=0 has_rpcsvc=0' utils
496 #               else
497                         compile_generic 'LDFLAGS=-static' utils
498 #               fi
499
500 #               if [ "${USE_DIETLIBC}" -eq '1' ]
501 #               then
502 #                       clean_dietlibc_bincache
503 #                       UTILS_CC="${OLD_CC}"
504 #               fi
505
506                 print_info 1 '        >> Copying to cache...'
507                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] || gen_die 'The devfsd executable does not exist after the compilation of devfsd!'
508                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Could not strip devfsd!'
509                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Compression of devfsd failed!'
510                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] || gen_die 'Could not find compressed devfsd.bz2 binary!'
511                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die 'Could not move compressed binary to the package cache!'
512
513 #               [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf" ] || gen_die 'devfsd.conf does not exist after the compilation of devfsd!'
514 #               bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd.conf" || gen_die 'Compression of devfsd.conf failed!'
515 #               mv "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" "${DEVFSD_CONF_BINCACHE}" || gen_die 'Could not move the compressed configuration to the package cache!'
516
517                 cd "${TEMP}"
518                 rm -rf "${DEVFSD_DIR}" > /dev/null
519         fi
520 }
521
522 compile_device_mapper() {
523         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
524         then
525                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
526                         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!"
527                 cd "${TEMP}"
528                 rm -rf "${DEVICE_MAPPER_DIR}"
529                 tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
530                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
531                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
532                 cd "${DEVICE_MAPPER_DIR}"
533                 ./configure  --prefix=${TEMP}/device-mapper --enable-static_link >> ${DEBUGFILE} 2>&1 ||
534                         gen_die 'Configuring device-mapper failed!'
535                 print_info 1 'device-mapper: >> Compiling...'
536                 compile_generic '' utils
537                 compile_generic 'install' utils
538                 print_info 1 '        >> Copying to cache...'
539                 cd "${TEMP}"
540                 rm -r "${TEMP}/device-mapper/man" ||
541                         gen_die 'Could not remove manual pages!'
542                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
543                         gen_die 'Could not strip dmsetup binary!'
544                 tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
545                         gen_die 'Could not tar up the device-mapper binary!'
546                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
547                         gen_die 'device-mapper cache not created!'
548                 cd "${TEMP}"
549                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
550                 rm -rf "${TEMP}/device-mapper" > /dev/null
551         fi
552 }
553
554 compile_dietlibc() {
555         local BUILD_DIETLIBC
556         local ORIGTEMP
557
558         BUILD_DIETLIBC=0
559         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
560         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
561         if ! isTrue "${BUILD_DIETLIBC}"
562         then
563                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
564                 if [ "${TEMP}" != "${ORIGTEMP}" ]
565                 then
566                         print_warning 1 'dietlibc: Bincache exists, but the current temporary directory'
567                         print_warning 1 '          is different to the original. Rebuilding.'
568                         BUILD_DIETLIBC=1
569                 fi
570         fi
571
572         if [ "${BUILD_DIETLIBC}" -eq '1' ]
573         then
574                 [ -f "${DIETLIBC_SRCTAR}" ] ||
575                         gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
576                 cd "${TEMP}"
577                 rm -rf "${DIETLIBC_DIR}" > /dev/null
578                 tar -jxpf "${DIETLIBC_SRCTAR}" ||
579                         gen_die 'Could not extract dietlibc source tarball'
580                 [ -d "${DIETLIBC_DIR}" ] ||
581                         gen_die "Dietlibc directory ${DIETLIBC_DIR} is invalid!"
582                 cd "${DIETLIBC_DIR}"
583                 print_info 1 "dietlibc: >> Compiling..."
584                 compile_generic "prefix=${TEMP}/diet" utils
585                 print_info 1 "          >> Installing..."
586                 compile_generic "prefix=${TEMP}/diet install" utils
587                 print_info 1 "          >> Copying to bincache..."
588                 cd ${TEMP}
589                 tar -jcpf "${DIETLIBC_BINCACHE}" diet ||
590                         gen_die 'Could not tar up the dietlibc binary!'
591                 [ -f "${DIETLIBC_BINCACHE}" ] ||
592                         gen_die 'Dietlibc cache not created!'
593                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
594
595                 cd "${TEMP}"
596                 rm -rf "${DIETLIBC_DIR}" > /dev/null
597                 rm -rf "${TEMP}/diet" > /dev/null
598         fi
599 }
600
601 compile_udev() {
602         if [ ! -f "${UDEV_BINCACHE}" ]
603         then
604                 cd "${TEMP}"
605                 rm -rf "${UDEV_DIR}" udev
606                 [ ! -f "${UDEV_SRCTAR}" ] &&
607                         gen_die "Could not find udev tarball: ${UDEV_SRCTAR}"
608                 tar -jxpf "${UDEV_SRCTAR}" ||
609                         gen_die 'Could not extract udev tarball'
610                 [ ! -d "${UDEV_DIR}" ] &&
611                         gen_die "Udev tarball ${UDEV_SRCTAR} is invalid"
612
613                 cd "${UDEV_DIR}"
614                 print_info 1 'udev: >> Compiling...'
615
616                 ln -snf "${KERNEL_DIR}" klibc/linux || gen_die "Could not link to ${KERNEL_DIR}"
617                 compile_generic "KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" utils
618
619                 strip udev || gen_die 'Failed to strip the udev binary!'
620
621                 print_info 1 '      >> Installing...'
622                 install -d "${TEMP}/udev/etc/udev" "${TEMP}/udev/sbin" "${TEMP}/udev/etc/udev/scripts" "${TEMP}/udev/etc/udev/rules.d" "${TEMP}/udev/etc/udev/permissions.d" ||
623                         gen_die 'Could not create directory hierarchy'
624                 install -m 0755 udev "${TEMP}/udev/sbin" ||
625                         gen_die 'Could not install udev binary!'
626                 install -m 0644 etc/udev/udev.conf "${TEMP}/udev/etc/udev" ||
627                                 gen_die 'Could not install udev configuration!'
628                 install -m 0644 etc/udev/gentoo/udev.rules "${TEMP}/udev/etc/udev/rules.d/50-udev.rules" ||
629                                 gen_die 'Could not install udev rules!'
630                 install -m 0644 etc/udev/udev.permissions "${TEMP}/udev/etc/udev/permissions.d/50-udev.permissions" ||
631                                 gen_die 'Could not install udev permissions!'
632                 install -m 0755 extras/ide-devfs.sh "${TEMP}/udev/etc/udev/scripts" ||
633                         gen_die 'Could not install udev scripts!'
634
635                 cd "${TEMP}/udev"
636                 print_info 1 '      >> Copying to bincache...'
637                 tar -cjf "${UDEV_BINCACHE}" * ||
638                         gen_die 'Could not create binary cache'
639
640                 cd "${TEMP}"
641                 rm -rf "${UDEV_DIR}" udev
642         fi
643 }
644