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