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}\""
32 if [ "${UTILS_ARCH}" != '' ]
34 ARGS="ARCH=\"${UTILS_ARCH}\""
36 if [ "${UTILS_CC}" != '' ]
38 ARGS="CC=\"${UTILS_CC}\""
40 if [ "${UTILS_LD}" != '' ]
42 ARGS="${ARGS} LD=\"${UTILS_LD}\""
44 if [ "${UTILS_AS}" != '' ]
46 ARGS="${ARGS} AS=\"${UTILS_AS}\""
55 if [ "${UTILS_ARCH}" != '' ]
57 export ARCH="${UTILS_ARCH}"
59 if [ "${UTILS_CC}" != '' ]
61 export CC="${UTILS_CC}"
63 if [ "${UTILS_LD}" != '' ]
65 export LD="${UTILS_LD}"
67 if [ "${UTILS_AS}" != '' ]
69 export AS="${UTILS_AS}"
75 if [ "${UTILS_ARCH}" != '' ]
79 if [ "${UTILS_CC}" != '' ]
83 if [ "${UTILS_LD}" != '' ]
87 if [ "${UTILS_AS}" != '' ]
96 if [ "${KERNEL_CC}" != '' ]
98 export CC="${KERNEL_CC}"
100 if [ "${KERNEL_LD}" != '' ]
102 export LD="${KERNEL_LD}"
104 if [ "${KERNEL_AS}" != '' ]
106 export AS="${KERNEL_AS}"
108 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
110 export CROSS_COMPILE="${KERNEL_CROSS_COMPILE}"
116 if [ "${KERNEL_CC}" != '' ]
120 if [ "${KERNEL_LD}" != '' ]
124 if [ "${KERNEL_AS}" != '' ]
128 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
135 if [ "${ARCH}" != '' ]
137 export ORIG_ARCH="${ARCH}"
141 export ORIG_CC="${CC}"
145 export ORIG_LD="${LD}"
149 export ORIG_AS="${AS}"
151 if [ "${CROSS_COMPILE}" != '' ]
153 export ORIG_CROSS_COMPILE="${CROSS_COMPILE}"
158 if [ "${ORIG_ARCH}" != '' ]
160 export ARCH="${ORIG_ARCH}"
163 if [ "${ORIG_CC}" != '' ]
165 export CC="${ORIG_CC}"
168 if [ "${ORIG_LD}" != '' ]
170 export LD="${ORIG_LD}"
173 if [ "${ORIG_AS}" != '' ]
175 export AS="${ORIG_AS}"
178 if [ "${ORIG_CROSS_COMPILE}" != '' ]
180 export CROSS_COMPILE="${ORIG_CROSS_COMPILE}"
181 unset ORIG_CROSS_COMPILE
189 if [ -d "${GK_SHARE}/patches/${util}/${version}" ]
191 print_info 1 "${util}: >> Applying patches..."
192 for i in ${GK_SHARE}/patches/${util}/${version}/*
197 patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null
204 if [ ${patch_success} != 1 ]
207 gen_die "could not apply patch ${i} for ${util}-${version}"
216 gen_die 'compile_generic(): improper usage!'
220 if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
224 elif [ "${2}" = 'utils' ]
229 case "${argstype}" in
230 kernel) ARGS="`compile_kernel_args`" ;;
231 utils) ARGS="`compile_utils_args`" ;;
232 *) ARGS="" ;; # includes runtask
236 # the eval usage is needed in the next set of code
237 # as ARGS can contain spaces and quotes, eg:
238 # ARGS='CC="ccache gcc"'
239 if [ "${argstype}" == 'runtask' ]
241 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
242 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
244 elif [ "${LOGLEVEL}" -gt "1" ]
246 # Output to stdout and logfile
247 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
248 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
251 # Output to logfile only
252 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
253 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
256 [ "${RET}" -ne '0' ] &&
257 gen_die "Failed to compile the \"${target}\" target..."
261 if [ "${argstype}" = 'kernel' ]
264 elif [ "${argstype}" = 'utils' ]
270 extract_dietlibc_bincache() {
272 rm -rf "${TEMP}/diet" > /dev/null
273 /bin/tar -jxpf "${DIETLIBC_BINCACHE}" ||
274 gen_die 'Could not extract dietlibc bincache!'
275 [ ! -d "${TEMP}/diet" ] &&
276 gen_die "${TEMP}/diet directory not found!"
280 clean_dietlibc_bincache() {
282 rm -rf "${TEMP}/diet" > /dev/null
287 # Only run ``make dep'' for 2.4 kernels
288 if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
290 print_info 1 "kernel: >> Making dependencies..."
292 compile_generic dep kernel
297 print_info 1 " >> Compiling ${KV} modules..."
299 compile_generic modules kernel
300 export UNAME_MACHINE="${ARCH}"
301 # On 2.4 kernels, if MAKEOPTS > -j1 it can cause failures
302 if [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ]
304 MAKEOPTS_SAVE="${MAKEOPTS}"
305 MAKEOPTS="${MAKEOPTS_SAVE/-j?/-j1}"
307 [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
308 compile_generic "modules_install" kernel
309 [ "${VER}" -eq '2' -a "${KERN_24}" -eq '1' ] && MAKEOPTS="${MAKEOPTS_SAVE}"
315 [ "${KERNEL_MAKE}" = '' ] &&
316 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
318 print_info 1 " >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
319 compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
320 if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
322 print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
323 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
325 if ! isTrue "${CMD_NOINSTALL}"
327 copy_image_with_preserve "kernel" \
329 "kernel-${KNAME}-${ARCH}-${KV}"
331 copy_image_with_preserve "System.map" \
333 "System.map-${KNAME}-${ARCH}-${KV}"
335 if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
337 copy_image_with_preserve "kernelz" \
338 "${KERNEL_BINARY_2}" \
342 cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
343 gen_die "Could not copy the kernel binary to ${TMPDIR}!"
344 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
345 gen_die "Could not copy System.map to ${TMPDIR}!"
346 if [ "${ENABLE_PEGASOS_HACKS}" = 'yes' ]
348 cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
349 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
355 [ -f "${BUSYBOX_SRCTAR}" ] ||
356 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
357 [ -f "${BUSYBOX_CONFIG}" ] ||
358 gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}!"
360 rm -rf "${BUSYBOX_DIR}" > /dev/null
361 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
362 gen_die 'Could not extract busybox source tarball!'
363 [ -d "${BUSYBOX_DIR}" ] ||
364 gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
365 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
366 # sed -i ${BUSYBOX_DIR}/.config -e 's/#\? \?CONFIG_FEATURE_INSTALLER[ =].*/CONFIG_FEATURE_INSTALLER=y/g'
368 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm.patch"
369 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm2.patch"
370 # patch -p1 < "${GK_SHARE}/pkg/busybox-1.1.3+gentoo-mdadm3.patch"
371 apply_patches busybox ${BUSYBOX_VER}
372 print_info 1 'busybox: >> Configuring...'
373 yes '' 2>/dev/null | compile_generic oldconfig utils
375 # Delete cache if stored config's MD5 does not match one to be used
376 if [ -f "${BUSYBOX_BINCACHE}" -a -f "${BUSYBOX_CONFIG}" ]
378 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config | md5sum)
379 newconfig_md5=$(md5sum < .config)
380 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
382 print_info 1 "busybox: >> Removing stale cache..."
383 rm -rf "${BUSYBOX_BINCACHE}"
385 print_info 1 "busybox: >> Using cache"
389 if [ ! -f "${BUSYBOX_BINCACHE}" ]
391 print_info 1 'busybox: >> Compiling...'
392 compile_generic all utils
393 print_info 1 'busybox: >> Copying to cache...'
394 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
395 gen_die 'Busybox executable does not exist!'
396 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
397 gen_die 'Could not strip busybox binary!'
398 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config ||
399 gen_die 'Could not create the busybox bincache!'
403 rm -rf "${BUSYBOX_DIR}" > /dev/null
407 compile_device_mapper
408 if [ ! -f "${LVM_BINCACHE}" ]
410 [ -f "${LVM_SRCTAR}" ] ||
411 gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
413 rm -rf ${LVM_DIR} > /dev/null
414 /bin/tar -zxpf ${LVM_SRCTAR} ||
415 gen_die 'Could not extract LVM source tarball!'
416 [ -d "${LVM_DIR}" ] ||
417 gen_die 'LVM directory ${LVM_DIR} is invalid!'
418 rm -rf "${TEMP}/device-mapper" > /dev/null
419 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
420 gen_die "Could not extract device-mapper binary cache!";
423 print_info 1 'lvm: >> Configuring...'
424 LDFLAGS="-L${TEMP}/device-mapper/lib" \
425 CFLAGS="-I${TEMP}/device-mapper/include" \
426 CPPFLAGS="-I${TEMP}/device-mapper/include" \
427 ./configure --enable-static_link --prefix=${TEMP}/lvm >> ${LOGFILE} 2>&1 ||
428 gen_die 'Configure of lvm failed!'
429 print_info 1 'lvm: >> Compiling...'
430 compile_generic '' utils
431 compile_generic 'install' utils
434 print_info 1 ' >> Copying to bincache...'
435 strip "sbin/lvm.static" ||
436 gen_die 'Could not strip lvm.static!'
437 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
438 gen_die 'Could not create binary cache'
441 rm -rf "${TEMP}/device-mapper" > /dev/null
442 rm -rf "${LVM_DIR}" lvm
447 compile_device_mapper
448 if [ ! -f "${DMRAID_BINCACHE}" ]
450 [ -f "${DMRAID_SRCTAR}" ] ||
451 gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
453 rm -rf ${DMRAID_DIR} > /dev/null
454 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
455 gen_die 'Could not extract DMRAID source tarball!'
456 [ -d "${DMRAID_DIR}" ] ||
457 gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
458 rm -rf "${TEMP}/device-mapper" > /dev/null
459 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
460 gen_die "Could not extract device-mapper binary cache!";
463 print_info 1 'dmraid: >> Configuring...'
465 LDFLAGS="-L${TEMP}/device-mapper/lib" \
466 CFLAGS="-I${TEMP}/device-mapper/include" \
467 CPPFLAGS="-I${TEMP}/device-mapper/include" \
468 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
469 gen_die 'Configure of dmraid failed!'
471 # We dont necessarily have selinux installed yet... look into
472 # selinux global support in the future.
473 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
474 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
475 mkdir -p "${TEMP}/dmraid"
476 print_info 1 'dmraid: >> Compiling...'
477 # Force dmraid to be built with -j1 for bug #188273
478 MAKEOPTS=-j1 compile_generic '' utils
479 #compile_generic 'install' utils
480 mkdir ${TEMP}/dmraid/sbin
481 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
482 print_info 1 ' >> Copying to bincache...'
484 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
485 gen_die 'Could not create binary cache'
488 rm -rf "${TEMP}/device-mapper" > /dev/null
489 rm -rf "${DMRAID_DIR}" dmraid
493 compile_device_mapper() {
494 if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
496 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
497 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!"
499 rm -rf "${DEVICE_MAPPER_DIR}"
500 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
501 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
502 gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
503 cd "${DEVICE_MAPPER_DIR}"
504 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
505 --disable-selinux >> ${LOGFILE} 2>&1 ||
506 gen_die 'Configuring device-mapper failed!'
507 print_info 1 'device-mapper: >> Compiling...'
508 compile_generic '' utils
509 compile_generic 'install' utils
510 print_info 1 ' >> Copying to cache...'
512 rm -rf "${TEMP}/device-mapper/man" ||
513 gen_die 'Could not remove manual pages!'
514 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
515 gen_die 'Could not strip dmsetup binary!'
516 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
517 gen_die 'Could not tar up the device-mapper binary!'
518 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
519 gen_die 'device-mapper cache not created!'
521 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
522 rm -rf "${TEMP}/device-mapper" > /dev/null
526 compile_e2fsprogs() {
527 if [ ! -f "${BLKID_BINCACHE}" ]
529 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
530 gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
532 rm -rf "${E2FSPROGS_DIR}"
533 tar -zxpf "${E2FSPROGS_SRCTAR}"
534 [ ! -d "${E2FSPROGS_DIR}" ] &&
535 gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
536 cd "${E2FSPROGS_DIR}"
537 print_info 1 'e2fsprogs: >> Configuring...'
538 ./configure --with-ldopts=-static >> ${LOGFILE} 2>&1 ||
539 gen_die 'Configuring e2fsprogs failed!'
540 print_info 1 'e2fsprogs: >> Compiling...'
541 MAKE=${UTILS_MAKE} compile_generic "" ""
542 print_info 1 'blkid: >> Copying to cache...'
543 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
544 gen_die 'Blkid executable does not exist!'
545 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
546 gen_die 'Could not strip blkid binary!'
547 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
548 gen_die 'bzip2 compression of blkid failed!'
549 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
550 gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
553 rm -rf "${E2FSPROGS_DIR}" > /dev/null