>> 3.2.0_beta1; now with extra froz-faktor <TM>.
[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-${KNAME}-${ARCH}-${KV}" ||
222                         gen_die 'Could not copy the kernel binary to /boot!'
223                 cp "System.map" "/boot/System.map-${KNAME}-${ARCH}-${KV}" ||
224                         gen_die 'Could not copy System.map to /boot!'
225                 if [ "${KERNEL_BINARY_2}" != '' ]
226                 then
227                         cp "${KERNEL_BINARY_2}" "/boot/kernelz-${KV}" ||
228                                 gen_die 'Could not copy the kernelz binary to /boot!'
229                 fi
230         else
231                 cp "${KERNEL_BINARY}" "${TEMP}/kernel-${KNAME}-${ARCH}-${KV}" ||
232                         gen_die "Could not copy the kernel binary to ${TEMP}!"
233                 cp "System.map" "${TEMP}/System.map-${KNAME}-${ARCH}-${KV}" ||
234                         gen_die "Could not copy System.map to ${TEMP}!"
235                 if [ "${KERNEL_BINARY_2}" != '' ]
236                 then
237                         cp "${KERNEL_BINARY_2}" "${TEMP}/kernelz-${KV}" ||
238                                 gen_die "Could not copy the kernelz binary to ${TEMP}!"
239                 fi
240         fi
241 }
242
243 compile_busybox() {
244         if [ ! -f "${BUSYBOX_BINCACHE}" ]
245         then
246                 [ -f "${BUSYBOX_SRCTAR}" ] ||
247                         gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
248                 [ -f "${BUSYBOX_CONFIG}" ] ||
249                         gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
250                 cd "${TEMP}"
251                 rm -rf ${BUSYBOX_DIR} > /dev/null
252                 tar -jxpf ${BUSYBOX_SRCTAR} ||
253                         gen_die 'Could not extract busybox source tarball!'
254                 [ -d "${BUSYBOX_DIR}" ] ||
255                         gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
256                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
257                 sed -i ${BUSYBOX_DIR}/.config -e 's/#\? \?CONFIG_FEATURE_INSTALLER[ =].*/CONFIG_FEATURE_INSTALLER=y/g'
258                 cd "${BUSYBOX_DIR}"
259                 print_info 1 'busybox: >> Configuring...'
260                 yes '' 2>/dev/null | compile_generic oldconfig utils
261                 print_info 1 'busybox: >> Compiling...'
262                 compile_generic all utils
263                 print_info 1 'busybox: >> Copying to cache...'
264                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
265                         gen_die 'Busybox executable does not exist!'
266                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
267                         gen_die 'Could not strip busybox binary!'
268                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" ||
269                         gen_die 'bzip2 compression of busybox failed!'
270                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" ||
271                         gen_die 'Could not copy the busybox binary to the package directory, does the directory exist?'
272
273                 cd "${TEMP}"
274                 rm -rf "${BUSYBOX_DIR}" > /dev/null
275         fi
276 }
277
278 compile_lvm2() {
279         compile_device_mapper
280         if [ ! -f "${LVM2_BINCACHE}" ]
281         then
282                 [ -f "${LVM2_SRCTAR}" ] ||
283                         gen_die "Could not find LVM2 source tarball: ${LVM2_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
284                 cd "${TEMP}"
285                 rm -rf ${LVM2_DIR} > /dev/null
286                 tar -zxpf ${LVM2_SRCTAR} ||
287                         gen_die 'Could not extract LVM2 source tarball!'
288                 [ -d "${LVM2_DIR}" ] ||
289                         gen_die 'LVM2 directory ${LVM2_DIR} is invalid!'
290                 rm -rf "${TEMP}/device-mapper" > /dev/null
291                 tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
292                         gen_die "Could not extract device-mapper binary cache!";
293                 
294                 cd "${LVM2_DIR}"
295                 print_info 1 'lvm2: >> Configuring...'
296                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
297                         CFLAGS="-I${TEMP}/device-mapper/include" \
298                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
299                         ./configure --enable-static_link --prefix=${TEMP}/lvm2 >> ${DEBUGFILE} 2>&1 ||
300                                 gen_die 'Configure of lvm2 failed!'
301                 print_info 1 'lvm2: >> Compiling...'
302                         compile_generic '' utils
303                         compile_generic 'install' utils
304
305                 cd "${TEMP}/lvm2"
306                 print_info 1 '      >> Copying to bincache...'
307                 strip "sbin/lvm.static" ||
308                         gen_die 'Could not strip lvm.static!'
309                 tar -cjf "${LVM2_BINCACHE}" sbin/lvm.static ||
310                         gen_die 'Could not create binary cache'
311
312                 cd "${TEMP}"
313                 rm -rf "${TEMP}/device-mapper" > /dev/null
314                 rm -rf "${LVM2_DIR}" lvm2
315         fi
316 }
317
318 compile_dmraid() {
319         compile_device_mapper
320         if [ ! -f "${DMRAID_BINCACHE}" ]
321         then
322                 [ -f "${DMRAID_SRCTAR}" ] ||
323                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
324                 cd "${TEMP}"
325                 rm -rf ${DMRAID_DIR} > /dev/null
326                 tar -jxpf ${DMRAID_SRCTAR} ||
327                         gen_die 'Could not extract DMRAID source tarball!'
328                 [ -d "${DMRAID_DIR}" ] ||
329                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
330                 rm -rf "${TEMP}/device-mapper" > /dev/null
331                 tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
332                         gen_die "Could not extract device-mapper binary cache!";
333                 
334                 cd "${DMRAID_DIR}"
335                 print_info 1 'dmraid: >> Configuring...'
336                 
337                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
338                         CFLAGS="-I${TEMP}/device-mapper/include" \
339                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
340                         ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${DEBUGFILE} 2>&1 ||
341                                 gen_die 'Configure of dmraid failed!'
342                 mkdir -p "${TEMP}/dmraid"
343                 print_info 1 'dmraid: >> Compiling...'
344                         compile_generic '' utils
345                         #compile_generic 'install' utils
346                         mkdir ${TEMP}/dmraid/sbin
347                         install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
348                 print_info 1 '      >> Copying to bincache...'
349                 cd "${TEMP}/dmraid"
350                 tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
351                         gen_die 'Could not create binary cache'
352
353                 cd "${TEMP}"
354                 rm -rf "${TEMP}/device-mapper" > /dev/null
355                 rm -rf "${DMRAID_DIR}" dmraid
356         fi
357 }
358
359 compile_modutils() {
360         # I've disabled dietlibc support for the time being since the
361         # version we use misses a few needed system calls.
362
363         local ARGS
364         if [ ! -f "${MODUTILS_BINCACHE}" ]
365         then
366                 [ ! -f "${MODUTILS_SRCTAR}" ] &&
367                         gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}!"
368                 cd "${TEMP}"
369                 rm -rf "${MODUTILS_DIR}"
370                 tar -jxpf "${MODUTILS_SRCTAR}"
371                 [ ! -d "${MODUTILS_DIR}" ] &&
372                         gen_die "Modutils directory ${MODUTILS_DIR} invalid!"
373                 cd "${MODUTILS_DIR}"
374                 print_info 1 "modutils: >> Configuring..."
375
376 #               if [ "${USE_DIETLIBC}" -eq '1' ]
377 #               then
378 #                       extract_dietlibc_bincache
379 #                       OLD_CC="${UTILS_CC}"
380 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
381 #               fi
382
383                 export_utils_args
384                 export ARCH=${ARCH}
385                 ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 ||
386                         gen_die 'Configuring modutils failed!'
387                 unset_utils_args
388
389                 print_info 1 'modutils: >> Compiling...'
390                 compile_generic all utils
391
392 #               if [ "${USE_DIETLIBC}" -eq '1' ]
393 #               then
394 #                       clean_dietlibc_bincache
395 #                       UTILS_CC="${OLD_CC}"
396 #               fi
397
398                 print_info 1 'modutils: >> Copying to cache...'
399                 [ -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] ||
400                         gen_die 'insmod.static does not exist after the compilation of modutils!'
401                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
402                         gen_die 'Could not strip insmod.static!'
403                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
404                         gen_die 'Compression of insmod.static failed!'
405                 mv "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" "${MODUTILS_BINCACHE}" ||
406                         gen_die 'Could not move the compressed insmod binary to the package cache!'
407
408                 cd "${TEMP}"
409                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
410         fi
411 }
412
413 compile_module_init_tools() {
414         # I've disabled dietlibc support for the time being since the
415         # version we use misses a few needed system calls.
416
417         local ARGS
418         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
419         then
420                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] &&
421                         gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
422                 cd "${TEMP}"
423                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
424                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
425                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] &&
426                         gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} is invalid"
427                 cd "${MODULE_INIT_TOOLS_DIR}"
428                 print_info 1 'module-init-tools: >> Configuring'
429
430 #               if [ "${USE_DIETLIBC}" -eq '1' ]
431 #               then
432 #                       extract_dietlibc_bincache
433 #                       OLD_CC="${UTILS_CC}"
434 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
435 #               fi
436
437                 export_utils_args
438                 ./configure >> ${DEBUGFILE} 2>&1 ||
439                         gen_die 'Configure of module-init-tools failed!'
440                 unset_utils_args
441                 print_info 1 '                   >> Compiling...'
442                 compile_generic "all" utils
443
444 #               if [ "${USE_DIETLIBC}" -eq '1' ]
445 #               then
446 #                       clean_dietlibc_bincache
447 #                       UTILS_CC="${OLD_CC}"
448 #               fi
449
450                 print_info 1 '                   >> Copying to cache...'
451                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] ||
452                         gen_die 'insmod.static does not exist after the compilation of module-init-tools!'
453                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
454                         gen_die 'Could not strip insmod.static!'
455                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
456                         gen_die 'Compression of insmod.static failed!'
457                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] ||
458                         gen_die 'Could not find compressed insmod.static.bz2 binary!'
459                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}" ||
460                         gen_die 'Could not move the compressed insmod binary to the package cache!'
461
462                 cd "${TEMP}"
463                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
464         fi
465 }
466
467 compile_devfsd() {
468         # I've disabled dietlibc support for the time being since the
469         # version we use misses a few needed system calls.
470
471         local ARGS
472         if [ ! -f "${DEVFSD_BINCACHE}" ]
473         then
474                 [ ! -f "${DEVFSD_SRCTAR}" ] &&
475                         gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
476                 cd "${TEMP}"
477                 rm -rf "${DEVFSD_DIR}"
478                 tar -jxpf "${DEVFSD_SRCTAR}"
479                 [ ! -d "${DEVFSD_DIR}" ] &&
480                         gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
481                 cd "${DEVFSD_DIR}"
482
483 #               if [ "${USE_DIETLIBC}" -eq '1' ]
484 #               then
485 #                       extract_dietlibc_bincache
486 #                       OLD_CC="${UTILS_CC}"
487 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
488 #               fi
489
490                 print_info 1 'devfsd: >> Compiling...'
491 #               if [ "${USE_DIETLIBC}" -eq '1' ]
492 #               then
493 #                       compile_generic 'has_dlopen=0 has_rpcsvc=0' utils
494 #               else
495                         compile_generic 'LDFLAGS=-static' utils
496 #               fi
497
498 #               if [ "${USE_DIETLIBC}" -eq '1' ]
499 #               then
500 #                       clean_dietlibc_bincache
501 #                       UTILS_CC="${OLD_CC}"
502 #               fi
503
504                 print_info 1 '        >> Copying to cache...'
505                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] || gen_die 'The devfsd executable does not exist after the compilation of devfsd!'
506                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Could not strip devfsd!'
507                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Compression of devfsd failed!'
508                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] || gen_die 'Could not find compressed devfsd.bz2 binary!'
509                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die 'Could not move compressed binary to the package cache!'
510
511 #               [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf" ] || gen_die 'devfsd.conf does not exist after the compilation of devfsd!'
512 #               bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd.conf" || gen_die 'Compression of devfsd.conf failed!'
513 #               mv "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" "${DEVFSD_CONF_BINCACHE}" || gen_die 'Could not move the compressed configuration to the package cache!'
514
515                 cd "${TEMP}"
516                 rm -rf "${DEVFSD_DIR}" > /dev/null
517         fi
518 }
519
520 compile_device_mapper() {
521         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
522         then
523                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
524                         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!"
525                 cd "${TEMP}"
526                 rm -rf "${DEVICE_MAPPER_DIR}"
527                 tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
528                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
529                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
530                 cd "${DEVICE_MAPPER_DIR}"
531                 ./configure  --prefix=${TEMP}/device-mapper --enable-static_link >> ${DEBUGFILE} 2>&1 ||
532                         gen_die 'Configuring device-mapper failed!'
533                 print_info 1 'device-mapper: >> Compiling...'
534                 compile_generic '' utils
535                 compile_generic 'install' utils
536                 print_info 1 '        >> Copying to cache...'
537                 cd "${TEMP}"
538                 rm -r "${TEMP}/device-mapper/man" ||
539                         gen_die 'Could not remove manual pages!'
540                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
541                         gen_die 'Could not strip dmsetup binary!'
542                 tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
543                         gen_die 'Could not tar up the device-mapper binary!'
544                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
545                         gen_die 'device-mapper cache not created!'
546                 cd "${TEMP}"
547                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
548                 rm -rf "${TEMP}/device-mapper" > /dev/null
549         fi
550 }
551
552 compile_dietlibc() {
553         local BUILD_DIETLIBC
554         local ORIGTEMP
555
556         BUILD_DIETLIBC=0
557         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
558         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
559         if ! isTrue "${BUILD_DIETLIBC}"
560         then
561                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
562                 if [ "${TEMP}" != "${ORIGTEMP}" ]
563                 then
564                         print_warning 1 'dietlibc: Bincache exists, but the current temporary directory'
565                         print_warning 1 '          is different to the original. Rebuilding.'
566                         BUILD_DIETLIBC=1
567                 fi
568         fi
569
570         if [ "${BUILD_DIETLIBC}" -eq '1' ]
571         then
572                 [ -f "${DIETLIBC_SRCTAR}" ] ||
573                         gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
574                 cd "${TEMP}"
575                 rm -rf "${DIETLIBC_DIR}" > /dev/null
576                 tar -jxpf "${DIETLIBC_SRCTAR}" ||
577                         gen_die 'Could not extract dietlibc source tarball'
578                 [ -d "${DIETLIBC_DIR}" ] ||
579                         gen_die "Dietlibc directory ${DIETLIBC_DIR} is invalid!"
580                 cd "${DIETLIBC_DIR}"
581                 print_info 1 "dietlibc: >> Compiling..."
582                 compile_generic "prefix=${TEMP}/diet" utils
583                 print_info 1 "          >> Installing..."
584                 compile_generic "prefix=${TEMP}/diet install" utils
585                 print_info 1 "          >> Copying to bincache..."
586                 cd ${TEMP}
587                 tar -jcpf "${DIETLIBC_BINCACHE}" diet ||
588                         gen_die 'Could not tar up the dietlibc binary!'
589                 [ -f "${DIETLIBC_BINCACHE}" ] ||
590                         gen_die 'Dietlibc cache not created!'
591                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
592
593                 cd "${TEMP}"
594                 rm -rf "${DIETLIBC_DIR}" > /dev/null
595                 rm -rf "${TEMP}/diet" > /dev/null
596         fi
597 }
598
599 compile_udev() {
600         if [ ! -f "${UDEV_BINCACHE}" ]
601         then
602                 cd "${TEMP}"
603                 rm -rf "${UDEV_DIR}" udev
604                 [ ! -f "${UDEV_SRCTAR}" ] &&
605                         gen_die "Could not find udev tarball: ${UDEV_SRCTAR}"
606                 tar -jxpf "${UDEV_SRCTAR}" ||
607                         gen_die 'Could not extract udev tarball'
608                 [ ! -d "${UDEV_DIR}" ] &&
609                         gen_die "Udev tarball ${UDEV_SRCTAR} is invalid"
610
611                 cd "${UDEV_DIR}"
612                 print_info 1 'udev: >> Compiling...'
613
614                 ln -snf "${KERNEL_DIR}" klibc/linux || gen_die "Could not link to ${KERNEL_DIR}"
615                 compile_generic "KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" utils
616
617                 strip udev || gen_die 'Failed to strip the udev binary!'
618
619                 print_info 1 '      >> Installing...'
620                 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" ||
621                         gen_die 'Could not create directory hierarchy'
622                 install -m 0755 udev "${TEMP}/udev/sbin" ||
623                         gen_die 'Could not install udev binary!'
624                 install -m 0644 etc/udev/udev.conf "${TEMP}/udev/etc/udev" ||
625                                 gen_die 'Could not install udev configuration!'
626                 install -m 0644 etc/udev/gentoo/udev.rules "${TEMP}/udev/etc/udev/rules.d/50-udev.rules" ||
627                                 gen_die 'Could not install udev rules!'
628                 install -m 0644 etc/udev/udev.permissions "${TEMP}/udev/etc/udev/permissions.d/50-udev.permissions" ||
629                                 gen_die 'Could not install udev permissions!'
630                 install -m 0755 extras/ide-devfs.sh "${TEMP}/udev/etc/udev/scripts" ||
631                         gen_die 'Could not install udev scripts!'
632
633                 cd "${TEMP}/udev"
634                 print_info 1 '      >> Copying to bincache...'
635                 tar -cjf "${UDEV_BINCACHE}" * ||
636                         gen_die 'Could not create binary cache'
637
638                 cd "${TEMP}"
639                 rm -rf "${UDEV_DIR}" udev
640         fi
641 }
642