3 compile_kernel_args() {
7 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
9 ARGS="${ARGS} CROSS_COMPILE=\"${KERNEL_CROSS_COMPILE}\""
11 if [ "${KERNEL_CC}" != '' ]
13 ARGS="CC=\"${KERNEL_CC}\""
15 if [ "${KERNEL_LD}" != '' ]
17 ARGS="${ARGS} LD=\"${KERNEL_LD}\""
19 if [ "${KERNEL_AS}" != '' ]
21 ARGS="${ARGS} AS=\"${KERNEL_AS}\""
23 if [ -n "${KERNEL_ARCH}" ]
25 ARGS="${ARGS} ARCH=\"${KERNEL_ARCH}\""
36 if [ "${UTILS_ARCH}" != '' ]
38 ARGS="ARCH=\"${UTILS_ARCH}\""
40 if [ "${UTILS_CC}" != '' ]
42 ARGS="CC=\"${UTILS_CC}\""
44 if [ "${UTILS_LD}" != '' ]
46 ARGS="${ARGS} LD=\"${UTILS_LD}\""
48 if [ "${UTILS_AS}" != '' ]
50 ARGS="${ARGS} AS=\"${UTILS_AS}\""
59 if [ "${UTILS_ARCH}" != '' ]
61 export ARCH="${UTILS_ARCH}"
63 if [ "${UTILS_CC}" != '' ]
65 export CC="${UTILS_CC}"
67 if [ "${UTILS_LD}" != '' ]
69 export LD="${UTILS_LD}"
71 if [ "${UTILS_AS}" != '' ]
73 export AS="${UTILS_AS}"
79 if [ "${UTILS_ARCH}" != '' ]
83 if [ "${UTILS_CC}" != '' ]
87 if [ "${UTILS_LD}" != '' ]
91 if [ "${UTILS_AS}" != '' ]
100 if [ "${KERNEL_CC}" != '' ]
102 export CC="${KERNEL_CC}"
104 if [ "${KERNEL_LD}" != '' ]
106 export LD="${KERNEL_LD}"
108 if [ "${KERNEL_AS}" != '' ]
110 export AS="${KERNEL_AS}"
112 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
114 export CROSS_COMPILE="${KERNEL_CROSS_COMPILE}"
120 if [ "${KERNEL_CC}" != '' ]
124 if [ "${KERNEL_LD}" != '' ]
128 if [ "${KERNEL_AS}" != '' ]
132 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
139 if [ "${ARCH}" != '' ]
141 export ORIG_ARCH="${ARCH}"
145 export ORIG_CC="${CC}"
149 export ORIG_LD="${LD}"
153 export ORIG_AS="${AS}"
155 if [ "${CROSS_COMPILE}" != '' ]
157 export ORIG_CROSS_COMPILE="${CROSS_COMPILE}"
162 if [ "${ORIG_ARCH}" != '' ]
164 export ARCH="${ORIG_ARCH}"
167 if [ "${ORIG_CC}" != '' ]
169 export CC="${ORIG_CC}"
172 if [ "${ORIG_LD}" != '' ]
174 export LD="${ORIG_LD}"
177 if [ "${ORIG_AS}" != '' ]
179 export AS="${ORIG_AS}"
182 if [ "${ORIG_CROSS_COMPILE}" != '' ]
184 export CROSS_COMPILE="${ORIG_CROSS_COMPILE}"
185 unset ORIG_CROSS_COMPILE
193 if [ -d "${GK_SHARE}/patches/${util}/${version}" ]
195 print_info 1 "${util}: >> Applying patches..."
196 for i in ${GK_SHARE}/patches/${util}/${version}/*
201 patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null
208 if [ ${patch_success} != 1 ]
211 gen_die "could not apply patch ${i} for ${util}-${version}"
220 gen_die 'compile_generic(): improper usage!'
224 if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
228 elif [ "${2}" = 'utils' ]
233 case "${argstype}" in
234 kernel) ARGS="`compile_kernel_args`" ;;
235 utils) ARGS="`compile_utils_args`" ;;
236 *) ARGS="" ;; # includes runtask
240 # the eval usage is needed in the next set of code
241 # as ARGS can contain spaces and quotes, eg:
242 # ARGS='CC="ccache gcc"'
243 if [ "${argstype}" == 'runtask' ]
245 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
246 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
248 elif [ "${LOGLEVEL}" -gt "1" ]
250 # Output to stdout and logfile
251 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
252 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
255 # Output to logfile only
256 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
257 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
260 [ "${RET}" -ne '0' ] &&
261 gen_die "Failed to compile the \"${target}\" target..."
265 if [ "${argstype}" = 'kernel' ]
268 elif [ "${argstype}" = 'utils' ]
274 extract_dietlibc_bincache() {
276 rm -rf "${TEMP}/diet" > /dev/null
277 /bin/tar -jxpf "${DIETLIBC_BINCACHE}" ||
278 gen_die 'Could not extract dietlibc bincache!'
279 [ ! -d "${TEMP}/diet" ] &&
280 gen_die "${TEMP}/diet directory not found!"
284 clean_dietlibc_bincache() {
286 rm -rf "${TEMP}/diet" > /dev/null
291 # Only run ``make dep'' for 2.4 kernels
292 if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
294 print_info 1 "kernel: >> Making dependencies..."
296 compile_generic dep kernel
301 print_info 1 " >> Compiling ${KV} modules..."
303 compile_generic modules kernel
304 export UNAME_MACHINE="${ARCH}"
305 # On 2.4 kernels, if MAKEOPTS > -j1 it can cause failures
306 if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
308 MAKEOPTS_SAVE="${MAKEOPTS}"
309 MAKEOPTS="${MAKEOPTS_SAVE/-j?/-j1}"
311 [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
312 compile_generic "modules_install" kernel
313 [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ] && MAKEOPTS="${MAKEOPTS_SAVE}"
319 [ "${KERNEL_MAKE}" = '' ] &&
320 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
322 print_info 1 " >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
323 compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
324 if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
326 print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
327 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
329 if ! isTrue "${CMD_NOINSTALL}"
331 copy_image_with_preserve "kernel" \
333 "kernel-${KNAME}-${ARCH}-${KV}"
335 copy_image_with_preserve "System.map" \
337 "System.map-${KNAME}-${ARCH}-${KV}"
339 if isTrue "${GENZIMAGE}"
341 copy_image_with_preserve "kernelz" \
342 "${KERNEL_BINARY_2}" \
346 cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
347 gen_die "Could not copy the kernel binary to ${TMPDIR}!"
348 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
349 gen_die "Could not copy System.map to ${TMPDIR}!"
350 if isTrue "${GENZIMAGE}"
352 cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
353 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
359 [ -f "${BUSYBOX_SRCTAR}" ] ||
360 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
361 [ -f "${BUSYBOX_CONFIG}" ] ||
362 gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
364 rm -rf "${BUSYBOX_DIR}" > /dev/null
365 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
366 gen_die 'Could not extract busybox source tarball!'
367 [ -d "${BUSYBOX_DIR}" ] ||
368 gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
369 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
370 # sed -i ${BUSYBOX_DIR}/.config -e 's/#\? \?CONFIG_FEATURE_INSTALLER[ =].*/CONFIG_FEATURE_INSTALLER=y/g'
372 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm.patch"
373 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm2.patch"
374 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm3.patch"
375 apply_patches busybox ${BUSYBOX_VER}
376 print_info 1 'busybox: >> Configuring...'
377 yes '' 2>/dev/null | compile_generic oldconfig utils
379 # Delete cache if stored config's MD5 does not match one to be used
380 if [ -f "${BUSYBOX_BINCACHE}" -a -f "${BUSYBOX_CONFIG}" ]
382 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config | md5sum)
383 newconfig_md5=$(md5sum < .config)
384 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
386 print_info 1 "busybox: >> Removing stale cache..."
387 rm -rf "${BUSYBOX_BINCACHE}"
389 print_info 1 "busybox: >> Using cache"
393 if [ ! -f "${BUSYBOX_BINCACHE}" ]
395 print_info 1 'busybox: >> Compiling...'
396 compile_generic all utils
397 print_info 1 'busybox: >> Copying to cache...'
398 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
399 gen_die 'Busybox executable does not exist!'
400 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
401 gen_die 'Could not strip busybox binary!'
402 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config ||
403 gen_die 'Could not create the busybox bincache!'
407 rm -rf "${BUSYBOX_DIR}" > /dev/null
411 compile_device_mapper
412 if [ ! -f "${LVM_BINCACHE}" ]
414 [ -f "${LVM_SRCTAR}" ] ||
415 gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
417 rm -rf ${LVM_DIR} > /dev/null
418 /bin/tar -zxpf ${LVM_SRCTAR} ||
419 gen_die 'Could not extract LVM source tarball!'
420 [ -d "${LVM_DIR}" ] ||
421 gen_die 'LVM directory ${LVM_DIR} is invalid!'
422 rm -rf "${TEMP}/device-mapper" > /dev/null
423 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
424 gen_die "Could not extract device-mapper binary cache!";
427 print_info 1 'lvm: >> Configuring...'
428 LDFLAGS="-L${TEMP}/device-mapper/lib" \
429 CFLAGS="-I${TEMP}/device-mapper/include" \
430 CPPFLAGS="-I${TEMP}/device-mapper/include" \
431 ./configure --enable-static_link --prefix=${TEMP}/lvm >> ${LOGFILE} 2>&1 ||
432 gen_die 'Configure of lvm failed!'
433 print_info 1 'lvm: >> Compiling...'
434 compile_generic '' utils
435 compile_generic 'install' utils
438 print_info 1 ' >> Copying to bincache...'
439 strip "sbin/lvm.static" ||
440 gen_die 'Could not strip lvm.static!'
441 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
442 gen_die 'Could not create binary cache'
445 rm -rf "${TEMP}/device-mapper" > /dev/null
446 rm -rf "${LVM_DIR}" lvm
451 compile_device_mapper
452 if [ ! -f "${DMRAID_BINCACHE}" ]
454 [ -f "${DMRAID_SRCTAR}" ] ||
455 gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
457 rm -rf ${DMRAID_DIR} > /dev/null
458 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
459 gen_die 'Could not extract DMRAID source tarball!'
460 [ -d "${DMRAID_DIR}" ] ||
461 gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
462 rm -rf "${TEMP}/device-mapper" > /dev/null
463 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
464 gen_die "Could not extract device-mapper binary cache!";
467 print_info 1 'dmraid: >> Configuring...'
469 LDFLAGS="-L${TEMP}/device-mapper/lib" \
470 CFLAGS="-I${TEMP}/device-mapper/include" \
471 CPPFLAGS="-I${TEMP}/device-mapper/include" \
472 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
473 gen_die 'Configure of dmraid failed!'
475 # We dont necessarily have selinux installed yet... look into
476 # selinux global support in the future.
477 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
478 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
479 mkdir -p "${TEMP}/dmraid"
480 print_info 1 'dmraid: >> Compiling...'
481 # Force dmraid to be built with -j1 for bug #188273
482 MAKEOPTS=-j1 compile_generic '' utils
483 #compile_generic 'install' utils
484 mkdir ${TEMP}/dmraid/sbin
485 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
486 print_info 1 ' >> Copying to bincache...'
488 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
489 gen_die 'Could not create binary cache'
492 rm -rf "${TEMP}/device-mapper" > /dev/null
493 rm -rf "${DMRAID_DIR}" dmraid
497 compile_device_mapper() {
498 if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
500 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
501 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!"
503 rm -rf "${DEVICE_MAPPER_DIR}"
504 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
505 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
506 gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
507 cd "${DEVICE_MAPPER_DIR}"
508 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
509 --disable-selinux >> ${LOGFILE} 2>&1 ||
510 gen_die 'Configuring device-mapper failed!'
511 print_info 1 'device-mapper: >> Compiling...'
512 compile_generic '' utils
513 compile_generic 'install' utils
514 print_info 1 ' >> Copying to cache...'
516 rm -rf "${TEMP}/device-mapper/man" ||
517 gen_die 'Could not remove manual pages!'
518 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
519 gen_die 'Could not strip dmsetup binary!'
520 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
521 gen_die 'Could not tar up the device-mapper binary!'
522 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
523 gen_die 'device-mapper cache not created!'
525 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
526 rm -rf "${TEMP}/device-mapper" > /dev/null
530 compile_e2fsprogs() {
531 if [ ! -f "${BLKID_BINCACHE}" ]
533 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
534 gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
536 rm -rf "${E2FSPROGS_DIR}"
537 tar -zxpf "${E2FSPROGS_SRCTAR}"
538 [ ! -d "${E2FSPROGS_DIR}" ] &&
539 gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
540 cd "${E2FSPROGS_DIR}"
541 print_info 1 'e2fsprogs: >> Configuring...'
542 ./configure --with-ldopts=-static >> ${LOGFILE} 2>&1 ||
543 gen_die 'Configuring e2fsprogs failed!'
544 print_info 1 'e2fsprogs: >> Compiling...'
545 MAKE=${UTILS_MAKE} compile_generic "" ""
546 print_info 1 'blkid: >> Copying to cache...'
547 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
548 gen_die 'Blkid executable does not exist!'
549 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
550 gen_die 'Could not strip blkid binary!'
551 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
552 gen_die 'bzip2 compression of blkid failed!'
553 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
554 gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
557 rm -rf "${E2FSPROGS_DIR}" > /dev/null