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