Upgraded to udev 068 and also closing bug #103936.
[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 "${KERN_24}" -eq '1' ]
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 "${KERN_24}" -eq '1' ]
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 "${KERN_24}" -eq '1' ] && 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}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
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}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
245                         gen_die "Could not copy the kernel binary to ${TMPDIR}!"
246                 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
247                         gen_die "Could not copy System.map to ${TMPDIR}!"
248                 if [ "${KERNEL_BINARY_2}" != '' -a "${GENERATE_Z_IMAGE}" = '1' ]
249                 then
250                         cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
251                                 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
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                 
273                 #Fix for hardened/selinux systems to have extened attributes
274                 #per r2d2's request
275                 sed -i Makefile -e "s|#  \(EXTRACFLAGS=-DUNIONFS_XATTR -DFIST_SETXATTR_CONSTVOID\)|\1|g"
276
277                 if [ "${PAT}" -ge '6' ]
278                 then
279                         # Setup the kernel sources to compile modules
280                         cd ${KERNEL_DIR}
281                         compile_generic "modules_prepare" kernel
282                 
283                         cd "${TEMP}"
284                         cd "${UNIONFS_DIR}"
285                         compile_generic unionfs2.6 kernel
286                 else
287                         compile_generic unionfs2.4 kernel
288                 fi
289                 print_info 1 'unionfs: >> Copying to cache...'
290         
291                 mkdir -p ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs
292                 
293                 if [ -f unionfs.ko ]
294                 then 
295                         cp unionfs.ko ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs 
296                 else 
297                         cp unionfs.o ${TEMP}/unionfs/lib/modules/${KV}/kernel/fs 
298                 fi
299         
300                 cd ${TEMP}/unionfs      
301                 /bin/tar -cjf "${UNIONFS_MODULES_BINCACHE}" . ||
302                         gen_die 'Could not create unionfs modules binary cache'
303         
304                 cd "${TEMP}"
305                 rm -rf "${UNIONFS_DIR}" > /dev/null
306                 rm -rf unionfs > /dev/null
307         fi
308 }
309
310 compile_unionfs_utils() {
311         if [ ! -f "${UNIONFS_BINCACHE}" ]
312         then
313                 [ -f "${UNIONFS_SRCTAR}" ] ||
314                         gen_die "Could not find unionfs source tarball: ${UNIONFS_SRCTAR}!"
315                 cd "${TEMP}"
316                 rm -rf ${UNIONFS_DIR} > /dev/null
317                 rm -rf unionfs > /dev/null
318                 mkdir -p unionfs/sbin
319                 /bin/tar -zxpf ${UNIONFS_SRCTAR} ||
320                         gen_die 'Could not extract unionfs source tarball!'
321                 [ -d "${UNIONFS_DIR}" ] ||
322                         gen_die 'Unionfs directory ${UNIONFS_DIR} is invalid!'
323                 cd "${UNIONFS_DIR}"
324                 print_info 1 'unionfs tools: >> Compiling...'
325                 sed -i Makefile -e 's|${CC} -o|${CC} -static -o|g'
326                 compile_generic utils utils
327                 
328                 print_info 1 'unionfs: >> Copying to cache...'
329                 strip uniondbg unionctl
330                 cp uniondbg ${TEMP}/unionfs/sbin/ || 
331                         gen_die 'Could not copy the uniondbg binary to the tmp directory'
332                 cp unionctl ${TEMP}/unionfs/sbin/ ||
333                         gen_die 'Could not copy the unionctl binary to the tmp directory'
334                 cd ${TEMP}/unionfs      
335                 /bin/tar -cjf "${UNIONFS_BINCACHE}" . ||
336                         gen_die 'Could not create unionfs tools binary cache'
337                 
338                 cd "${TEMP}"
339                 rm -rf "${UNIONFS_DIR}" > /dev/null
340                 rm -rf unionfs > /dev/null
341         fi
342 }
343
344 compile_busybox() {
345         if [ ! -f "${BUSYBOX_BINCACHE}" ]
346         then
347                 [ -f "${BUSYBOX_SRCTAR}" ] ||
348                         gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
349                 [ -f "${BUSYBOX_CONFIG}" ] ||
350                         gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
351                 cd "${TEMP}"
352                 rm -rf ${BUSYBOX_DIR} > /dev/null
353                 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
354                         gen_die 'Could not extract busybox source tarball!'
355                 [ -d "${BUSYBOX_DIR}" ] ||
356                         gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
357                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
358                 sed -i ${BUSYBOX_DIR}/.config -e 's/#\? \?CONFIG_FEATURE_INSTALLER[ =].*/CONFIG_FEATURE_INSTALLER=y/g'
359                 cd "${BUSYBOX_DIR}"
360                 print_info 1 'busybox: >> Configuring...'
361                 yes '' 2>/dev/null | compile_generic oldconfig utils
362                 print_info 1 'busybox: >> Compiling...'
363                 compile_generic all utils
364                 print_info 1 'busybox: >> Copying to cache...'
365                 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
366                         gen_die 'Busybox executable does not exist!'
367                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
368                         gen_die 'Could not strip busybox binary!'
369                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" ||
370                         gen_die 'bzip2 compression of busybox failed!'
371                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" ||
372                         gen_die 'Could not copy the busybox binary to the package directory, does the directory exist?'
373
374                 cd "${TEMP}"
375                 rm -rf "${BUSYBOX_DIR}" > /dev/null
376         fi
377 }
378
379 compile_lvm2() {
380         compile_device_mapper
381         if [ ! -f "${LVM2_BINCACHE}" ]
382         then
383                 [ -f "${LVM2_SRCTAR}" ] ||
384                         gen_die "Could not find LVM2 source tarball: ${LVM2_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
385                 cd "${TEMP}"
386                 rm -rf ${LVM2_DIR} > /dev/null
387                 /bin/tar -zxpf ${LVM2_SRCTAR} ||
388                         gen_die 'Could not extract LVM2 source tarball!'
389                 [ -d "${LVM2_DIR}" ] ||
390                         gen_die 'LVM2 directory ${LVM2_DIR} is invalid!'
391                 rm -rf "${TEMP}/device-mapper" > /dev/null
392                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
393                         gen_die "Could not extract device-mapper binary cache!";
394                 
395                 cd "${LVM2_DIR}"
396                 print_info 1 'lvm2: >> Configuring...'
397                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
398                         CFLAGS="-I${TEMP}/device-mapper/include" \
399                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
400                         ./configure --enable-static_link --prefix=${TEMP}/lvm2 >> ${DEBUGFILE} 2>&1 ||
401                                 gen_die 'Configure of lvm2 failed!'
402                 print_info 1 'lvm2: >> Compiling...'
403                         compile_generic '' utils
404                         compile_generic 'install' utils
405
406                 cd "${TEMP}/lvm2"
407                 print_info 1 '      >> Copying to bincache...'
408                 strip "sbin/lvm.static" ||
409                         gen_die 'Could not strip lvm.static!'
410                 /bin/tar -cjf "${LVM2_BINCACHE}" sbin/lvm.static ||
411                         gen_die 'Could not create binary cache'
412
413                 cd "${TEMP}"
414                 rm -rf "${TEMP}/device-mapper" > /dev/null
415                 rm -rf "${LVM2_DIR}" lvm2
416         fi
417 }
418
419 compile_dmraid() {
420         compile_device_mapper
421         if [ ! -f "${DMRAID_BINCACHE}" ]
422         then
423                 [ -f "${DMRAID_SRCTAR}" ] ||
424                         gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
425                 cd "${TEMP}"
426                 rm -rf ${DMRAID_DIR} > /dev/null
427                 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
428                         gen_die 'Could not extract DMRAID source tarball!'
429                 [ -d "${DMRAID_DIR}" ] ||
430                         gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
431                 rm -rf "${TEMP}/device-mapper" > /dev/null
432                 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
433                         gen_die "Could not extract device-mapper binary cache!";
434                 
435                 cd "${DMRAID_DIR}"
436                 print_info 1 'dmraid: >> Configuring...'
437                 
438                         LDFLAGS="-L${TEMP}/device-mapper/lib" \
439                         CFLAGS="-I${TEMP}/device-mapper/include" \
440                         CPPFLAGS="-I${TEMP}/device-mapper/include" \
441                         ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${DEBUGFILE} 2>&1 ||
442                                 gen_die 'Configure of dmraid failed!'
443                 mkdir -p "${TEMP}/dmraid"
444                 print_info 1 'dmraid: >> Compiling...'
445                         compile_generic '' utils
446                         #compile_generic 'install' utils
447                         mkdir ${TEMP}/dmraid/sbin
448                         install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
449                 print_info 1 '      >> Copying to bincache...'
450                 cd "${TEMP}/dmraid"
451                 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
452                         gen_die 'Could not create binary cache'
453
454                 cd "${TEMP}"
455                 rm -rf "${TEMP}/device-mapper" > /dev/null
456                 rm -rf "${DMRAID_DIR}" dmraid
457         fi
458 }
459
460 compile_modutils() {
461         # I've disabled dietlibc support for the time being since the
462         # version we use misses a few needed system calls.
463
464         local ARGS
465         if [ ! -f "${MODUTILS_BINCACHE}" ]
466         then
467                 [ ! -f "${MODUTILS_SRCTAR}" ] &&
468                         gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}!"
469                 cd "${TEMP}"
470                 rm -rf "${MODUTILS_DIR}"
471                 /bin/tar -jxpf "${MODUTILS_SRCTAR}"
472                 [ ! -d "${MODUTILS_DIR}" ] &&
473                         gen_die "Modutils directory ${MODUTILS_DIR} invalid!"
474                 cd "${MODUTILS_DIR}"
475                 print_info 1 "modutils: >> Configuring..."
476
477 #               if [ "${USE_DIETLIBC}" -eq '1' ]
478 #               then
479 #                       extract_dietlibc_bincache
480 #                       OLD_CC="${UTILS_CC}"
481 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
482 #               fi
483
484                 export_utils_args
485                 export ARCH=${ARCH}
486                 ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 ||
487                         gen_die 'Configuring modutils failed!'
488                 unset_utils_args
489
490                 print_info 1 'modutils: >> Compiling...'
491                 compile_generic all utils
492
493 #               if [ "${USE_DIETLIBC}" -eq '1' ]
494 #               then
495 #                       clean_dietlibc_bincache
496 #                       UTILS_CC="${OLD_CC}"
497 #               fi
498
499                 print_info 1 'modutils: >> Copying to cache...'
500                 [ -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] ||
501                         gen_die 'insmod.static does not exist after the compilation of modutils!'
502                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
503                         gen_die 'Could not strip insmod.static!'
504                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ||
505                         gen_die 'Compression of insmod.static failed!'
506                 mv "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" "${MODUTILS_BINCACHE}" ||
507                         gen_die 'Could not move the compressed insmod binary to the package cache!'
508
509                 cd "${TEMP}"
510                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
511         fi
512 }
513
514 compile_module_init_tools() {
515         # I've disabled dietlibc support for the time being since the
516         # version we use misses a few needed system calls.
517
518         local ARGS
519         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
520         then
521                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] &&
522                         gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
523                 cd "${TEMP}"
524                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
525                 /bin/tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
526                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] &&
527                         gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} is invalid"
528                 cd "${MODULE_INIT_TOOLS_DIR}"
529                 print_info 1 'module-init-tools: >> Configuring'
530
531 #               if [ "${USE_DIETLIBC}" -eq '1' ]
532 #               then
533 #                       extract_dietlibc_bincache
534 #                       OLD_CC="${UTILS_CC}"
535 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
536 #               fi
537
538                 export_utils_args
539                 ./configure >> ${DEBUGFILE} 2>&1 ||
540                         gen_die 'Configure of module-init-tools failed!'
541                 unset_utils_args
542                 print_info 1 '                   >> Compiling...'
543                 compile_generic "all" utils
544
545 #               if [ "${USE_DIETLIBC}" -eq '1' ]
546 #               then
547 #                       clean_dietlibc_bincache
548 #                       UTILS_CC="${OLD_CC}"
549 #               fi
550
551                 print_info 1 '                   >> Copying to cache...'
552                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] ||
553                         gen_die 'insmod.static does not exist after the compilation of module-init-tools!'
554                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
555                         gen_die 'Could not strip insmod.static!'
556                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ||
557                         gen_die 'Compression of insmod.static failed!'
558                 [ -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] ||
559                         gen_die 'Could not find compressed insmod.static.bz2 binary!'
560                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}" ||
561                         gen_die 'Could not move the compressed insmod binary to the package cache!'
562
563                 cd "${TEMP}"
564                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
565         fi
566 }
567
568 compile_devfsd() {
569         # I've disabled dietlibc support for the time being since the
570         # version we use misses a few needed system calls.
571
572         local ARGS
573         if [ ! -f "${DEVFSD_BINCACHE}" ]
574         then
575                 [ ! -f "${DEVFSD_SRCTAR}" ] &&
576                         gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
577                 cd "${TEMP}"
578                 rm -rf "${DEVFSD_DIR}"
579                 /bin/tar -jxpf "${DEVFSD_SRCTAR}"
580                 [ ! -d "${DEVFSD_DIR}" ] &&
581                         gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
582                 cd "${DEVFSD_DIR}"
583
584 #               if [ "${USE_DIETLIBC}" -eq '1' ]
585 #               then
586 #                       extract_dietlibc_bincache
587 #                       OLD_CC="${UTILS_CC}"
588 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
589 #               fi
590
591                 print_info 1 'devfsd: >> Compiling...'
592 #               if [ "${USE_DIETLIBC}" -eq '1' ]
593 #               then
594 #                       compile_generic 'has_dlopen=0 has_rpcsvc=0' utils
595 #               else
596                         compile_generic 'LDFLAGS=-static' utils
597 #               fi
598
599 #               if [ "${USE_DIETLIBC}" -eq '1' ]
600 #               then
601 #                       clean_dietlibc_bincache
602 #                       UTILS_CC="${OLD_CC}"
603 #               fi
604
605                 print_info 1 '        >> Copying to cache...'
606                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] || gen_die 'The devfsd executable does not exist after the compilation of devfsd!'
607                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Could not strip devfsd!'
608                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die 'Compression of devfsd failed!'
609                 [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] || gen_die 'Could not find compressed devfsd.bz2 binary!'
610                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die 'Could not move compressed binary to the package cache!'
611
612 #               [ -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf" ] || gen_die 'devfsd.conf does not exist after the compilation of devfsd!'
613 #               bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd.conf" || gen_die 'Compression of devfsd.conf failed!'
614 #               mv "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" "${DEVFSD_CONF_BINCACHE}" || gen_die 'Could not move the compressed configuration to the package cache!'
615
616                 cd "${TEMP}"
617                 rm -rf "${DEVFSD_DIR}" > /dev/null
618         fi
619 }
620
621 compile_device_mapper() {
622         if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
623         then
624                 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
625                         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!"
626                 cd "${TEMP}"
627                 rm -rf "${DEVICE_MAPPER_DIR}"
628                 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
629                 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
630                         gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
631                 cd "${DEVICE_MAPPER_DIR}"
632                 ./configure  --prefix=${TEMP}/device-mapper --enable-static_link >> ${DEBUGFILE} 2>&1 ||
633                         gen_die 'Configuring device-mapper failed!'
634                 print_info 1 'device-mapper: >> Compiling...'
635                 compile_generic '' utils
636                 compile_generic 'install' utils
637                 print_info 1 '        >> Copying to cache...'
638                 cd "${TEMP}"
639                 rm -r "${TEMP}/device-mapper/man" ||
640                         gen_die 'Could not remove manual pages!'
641                 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
642                         gen_die 'Could not strip dmsetup binary!'
643                 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
644                         gen_die 'Could not tar up the device-mapper binary!'
645                 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
646                         gen_die 'device-mapper cache not created!'
647                 cd "${TEMP}"
648                 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
649                 rm -rf "${TEMP}/device-mapper" > /dev/null
650         fi
651 }
652
653 compile_dietlibc() {
654         local BUILD_DIETLIBC
655         local ORIGTEMP
656
657         BUILD_DIETLIBC=0
658         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
659         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
660         if ! isTrue "${BUILD_DIETLIBC}"
661         then
662                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
663                 if [ "${TEMP}" != "${ORIGTEMP}" ]
664                 then
665                         print_warning 1 'dietlibc: Bincache exists, but the current temporary directory'
666                         print_warning 1 '          is different to the original. Rebuilding.'
667                         BUILD_DIETLIBC=1
668                 fi
669         fi
670
671         if [ "${BUILD_DIETLIBC}" -eq '1' ]
672         then
673                 [ -f "${DIETLIBC_SRCTAR}" ] ||
674                         gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
675                 cd "${TEMP}"
676                 rm -rf "${DIETLIBC_DIR}" > /dev/null
677                 /bin/tar -jxpf "${DIETLIBC_SRCTAR}" ||
678                         gen_die 'Could not extract dietlibc source tarball'
679                 [ -d "${DIETLIBC_DIR}" ] ||
680                         gen_die "Dietlibc directory ${DIETLIBC_DIR} is invalid!"
681                 cd "${DIETLIBC_DIR}"
682                 print_info 1 "dietlibc: >> Compiling..."
683                 compile_generic "prefix=${TEMP}/diet" utils
684                 print_info 1 "          >> Installing..."
685                 compile_generic "prefix=${TEMP}/diet install" utils
686                 print_info 1 "          >> Copying to bincache..."
687                 cd ${TEMP}
688                 /bin/tar -jcpf "${DIETLIBC_BINCACHE}" diet ||
689                         gen_die 'Could not tar up the dietlibc binary!'
690                 [ -f "${DIETLIBC_BINCACHE}" ] ||
691                         gen_die 'Dietlibc cache not created!'
692                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
693
694                 cd "${TEMP}"
695                 rm -rf "${DIETLIBC_DIR}" > /dev/null
696                 rm -rf "${TEMP}/diet" > /dev/null
697         fi
698 }
699
700 compile_udev() {
701         if [ ! -f "${UDEV_BINCACHE}" ]
702         then
703                 cd "${TEMP}"
704                 rm -rf "${UDEV_DIR}" udev
705                 [ ! -f "${UDEV_SRCTAR}" ] &&
706                         gen_die "Could not find udev tarball: ${UDEV_SRCTAR}"
707                 /bin/tar -jxpf "${UDEV_SRCTAR}" ||
708                         gen_die 'Could not extract udev tarball'
709                 [ ! -d "${UDEV_DIR}" ] &&
710                         gen_die "Udev tarball ${UDEV_SRCTAR} is invalid"
711
712                 cd "${UDEV_DIR}"
713                 print_info 1 'udev: >> Compiling...'
714
715                 ln -snf "${KERNEL_DIR}" klibc/linux || gen_die "Could not link to ${KERNEL_DIR}"
716                 if [ "${ARCH}" = 'um' ]
717                 then
718                         compile_generic "ARCH=um KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" runtask
719                 elif [ "${ARCH}" = 'sparc64' ]
720                 then
721                         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
722                 else
723                         compile_generic "KERNEL_DIR=$KERNEL_DIR USE_KLIBC=true USE_LOG=false DEBUG=false udevdir=/dev all etc/udev/udev.conf" runtask
724                 fi
725
726
727                 strip udev || gen_die 'Failed to strip the udev binary!'
728                 if [ -e udevstart ]
729                 then
730                         strip udevstart || gen_die 'Failed to strip the udevstart binary!'
731                 fi
732                 
733                 if [ -e udevsend ]
734                 then
735                         strip udevsend || gen_die 'Failed to strip the udevsend binary!'
736                 fi
737
738                 print_info 1 '      >> Installing...'
739                 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" ||
740                         gen_die 'Could not create directory hierarchy'
741                 install -m 0755 udev "${TEMP}/udev/sbin" ||
742                         gen_die 'Could not install udev binary!'
743                 
744                 if [ -e udevstart ]
745                 then
746                         install -m 0755 udevstart "${TEMP}/udev/sbin" ||
747                                 gen_die 'Could not install udevstart binary!'
748                 fi
749                 
750                 if [ -e udevsend ]
751                 then
752                         install -m 0755 udevsend "${TEMP}/udev/sbin" ||
753                                 gen_die 'Could not install udevsend binary!'
754                 fi
755
756                 install -m 0644 etc/udev/udev.conf "${TEMP}/udev/etc/udev" ||
757                                 gen_die 'Could not install udev configuration!'
758                 install -m 0644 etc/udev/gentoo/udev.rules "${TEMP}/udev/etc/udev/rules.d/50-udev.rules" ||
759                                 gen_die 'Could not install udev rules!'
760 #               install -m 0644 etc/udev/udev.permissions "${TEMP}/udev/etc/udev/permissions.d/50-udev.permissions" ||
761 #                               gen_die 'Could not install udev permissions!'
762                 install -m 0755 extras/ide-devfs.sh "${TEMP}/udev/etc/udev/scripts" ||
763                         gen_die 'Could not install udev scripts!'
764
765                 cd "${TEMP}/udev"
766                 print_info 1 '      >> Copying to bincache...'
767                 /bin/tar -cjf "${UDEV_BINCACHE}" * ||
768                         gen_die 'Could not create binary cache'
769
770                 cd "${TEMP}"
771                 rm -rf "${UDEV_DIR}" udev
772         fi
773 }
774
775 compile_e2fsprogs() {
776         if [ ! -f "${BLKID_BINCACHE}" ]
777         then
778                 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
779                         gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
780                 cd "${TEMP}"
781                 rm -rf "${E2FSPROGS_DIR}"
782                 tar -zxpf "${E2FSPROGS_SRCTAR}"
783                 [ ! -d "${E2FSPROGS_DIR}" ] &&
784                         gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
785                 cd "${E2FSPROGS_DIR}"
786                 print_info 1 'e2fsprogs: >> Configuring...'
787                 ./configure  --with-ldopts=-static >> ${DEBUGFILE} 2>&1 ||
788                         gen_die 'Configuring e2fsprogs failed!'
789                 print_info 1 'e2fsprogs: >> Compiling...'
790                 MAKE=${UTILS_MAKE} compile_generic "" ""
791                 print_info 1 'blkid: >> Copying to cache...'
792                 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
793                         gen_die 'Blkid executable does not exist!'
794                 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
795                         gen_die 'Could not strip blkid binary!'
796                 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
797                         gen_die 'bzip2 compression of blkid failed!'
798                 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
799                         gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
800
801                 cd "${TEMP}"
802                 rm -rf "${E2FSPROGS_DIR}" > /dev/null
803         fi
804 }