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}/*{diff,patch}
201 patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null
208 if [ ${patch_success} != 1 ]
210 gen_die "could not apply patch ${i} for ${util}-${version}"
219 gen_die 'compile_generic(): improper usage!'
223 if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
227 elif [ "${2}" = 'utils' ]
232 case "${argstype}" in
233 kernel) ARGS="`compile_kernel_args`" ;;
234 utils) ARGS="`compile_utils_args`" ;;
235 *) ARGS="" ;; # includes runtask
239 # the eval usage is needed in the next set of code
240 # as ARGS can contain spaces and quotes, eg:
241 # ARGS='CC="ccache gcc"'
242 if [ "${argstype}" == 'runtask' ]
244 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
245 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
247 elif [ "${LOGLEVEL}" -gt "1" ]
249 # Output to stdout and logfile
250 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
251 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
254 # Output to logfile only
255 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
256 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
259 [ "${RET}" -ne '0' ] &&
260 gen_die "Failed to compile the \"${target}\" target..."
264 if [ "${argstype}" = 'kernel' ]
267 elif [ "${argstype}" = 'utils' ]
274 print_info 1 " >> Compiling ${KV} modules..."
276 compile_generic modules kernel
277 export UNAME_MACHINE="${ARCH}"
278 [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
279 compile_generic "modules_install" kernel
284 [ "${KERNEL_MAKE}" = '' ] &&
285 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
287 print_info 1 " >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
288 compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
289 if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
291 print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
292 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
294 if ! isTrue "${CMD_NOINSTALL}"
296 copy_image_with_preserve "kernel" \
298 "kernel-${KNAME}-${ARCH}-${KV}"
300 copy_image_with_preserve "System.map" \
302 "System.map-${KNAME}-${ARCH}-${KV}"
304 if isTrue "${GENZIMAGE}"
306 copy_image_with_preserve "kernelz" \
307 "${KERNEL_BINARY_2}" \
311 cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
312 gen_die "Could not copy the kernel binary to ${TMPDIR}!"
313 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
314 gen_die "Could not copy System.map to ${TMPDIR}!"
315 if isTrue "${GENZIMAGE}"
317 cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
318 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
324 [ -f "${BUSYBOX_SRCTAR}" ] ||
325 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
327 if [ -n "${BUSYBOX_CONFIG}" ]
329 [ -f "${BUSYBOX_CONFIG}" ] ||
330 gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}"
331 elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ]
333 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")"
334 elif [ -f "${GK_SHARE}/defaults/busy-config" ]
336 BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config"
338 gendie "Could not find a busybox config file"
341 # Delete cache if stored config's MD5 does not match one to be used
342 if [ -f "${BUSYBOX_BINCACHE}" ]
344 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum)
345 newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}")
346 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
348 print_info 1 "busybox: >> Removing stale cache..."
349 rm -rf "${BUSYBOX_BINCACHE}"
351 print_info 1 "busybox: >> Using cache"
355 if [ ! -f "${BUSYBOX_BINCACHE}" ]
358 rm -rf "${BUSYBOX_DIR}" > /dev/null
359 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
360 gen_die 'Could not extract busybox source tarball!'
361 [ -d "${BUSYBOX_DIR}" ] ||
362 gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
363 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
364 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig"
366 apply_patches busybox ${BUSYBOX_VER}
367 print_info 1 'busybox: >> Configuring...'
368 yes '' 2>/dev/null | compile_generic oldconfig utils
370 print_info 1 'busybox: >> Compiling...'
371 compile_generic all utils
372 print_info 1 'busybox: >> Copying to cache...'
373 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
374 gen_die 'Busybox executable does not exist!'
375 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
376 gen_die 'Could not strip busybox binary!'
377 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig ||
378 gen_die 'Could not create the busybox bincache!'
381 rm -rf "${BUSYBOX_DIR}" > /dev/null
386 compile_device_mapper
387 if [ ! -f "${LVM_BINCACHE}" ]
389 [ -f "${LVM_SRCTAR}" ] ||
390 gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
392 rm -rf ${LVM_DIR} > /dev/null
393 /bin/tar -zxpf ${LVM_SRCTAR} ||
394 gen_die 'Could not extract LVM source tarball!'
395 [ -d "${LVM_DIR}" ] ||
396 gen_die 'LVM directory ${LVM_DIR} is invalid!'
397 rm -rf "${TEMP}/device-mapper" > /dev/null
398 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
399 gen_die "Could not extract device-mapper binary cache!";
402 print_info 1 'lvm: >> Configuring...'
403 LDFLAGS="-L${TEMP}/device-mapper/lib" \
404 CFLAGS="-I${TEMP}/device-mapper/include" \
405 CPPFLAGS="-I${TEMP}/device-mapper/include" \
406 ./configure --enable-static_link --prefix=${TEMP}/lvm >> ${LOGFILE} 2>&1 ||
407 gen_die 'Configure of lvm failed!'
408 print_info 1 'lvm: >> Compiling...'
409 compile_generic '' utils
410 compile_generic 'install' utils
413 print_info 1 ' >> Copying to bincache...'
414 strip "sbin/lvm.static" ||
415 gen_die 'Could not strip lvm.static!'
416 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
417 gen_die 'Could not create binary cache'
420 rm -rf "${TEMP}/device-mapper" > /dev/null
421 rm -rf "${LVM_DIR}" lvm
426 compile_device_mapper
427 if [ ! -f "${DMRAID_BINCACHE}" ]
429 [ -f "${DMRAID_SRCTAR}" ] ||
430 gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
432 rm -rf ${DMRAID_DIR} > /dev/null
433 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
434 gen_die 'Could not extract DMRAID source tarball!'
435 [ -d "${DMRAID_DIR}" ] ||
436 gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
437 rm -rf "${TEMP}/device-mapper" > /dev/null
438 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
439 gen_die "Could not extract device-mapper binary cache!";
442 print_info 1 'dmraid: >> Configuring...'
444 LDFLAGS="-L${TEMP}/device-mapper/lib" \
445 CFLAGS="-I${TEMP}/device-mapper/include" \
446 CPPFLAGS="-I${TEMP}/device-mapper/include" \
447 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
448 gen_die 'Configure of dmraid failed!'
450 # We dont necessarily have selinux installed yet... look into
451 # selinux global support in the future.
452 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
453 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
454 mkdir -p "${TEMP}/dmraid"
455 print_info 1 'dmraid: >> Compiling...'
456 # Force dmraid to be built with -j1 for bug #188273
457 MAKEOPTS=-j1 compile_generic '' utils
458 #compile_generic 'install' utils
459 mkdir ${TEMP}/dmraid/sbin
460 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
461 print_info 1 ' >> Copying to bincache...'
463 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
464 gen_die 'Could not create binary cache'
467 rm -rf "${TEMP}/device-mapper" > /dev/null
468 rm -rf "${DMRAID_DIR}" dmraid
472 compile_device_mapper() {
473 if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
475 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
476 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!"
478 rm -rf "${DEVICE_MAPPER_DIR}"
479 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
480 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
481 gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
482 cd "${DEVICE_MAPPER_DIR}"
483 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
484 --disable-selinux >> ${LOGFILE} 2>&1 ||
485 gen_die 'Configuring device-mapper failed!'
486 print_info 1 'device-mapper: >> Compiling...'
487 compile_generic '' utils
488 compile_generic 'install' utils
489 print_info 1 ' >> Copying to cache...'
491 rm -rf "${TEMP}/device-mapper/man" ||
492 gen_die 'Could not remove manual pages!'
493 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
494 gen_die 'Could not strip dmsetup binary!'
495 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
496 gen_die 'Could not tar up the device-mapper binary!'
497 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
498 gen_die 'device-mapper cache not created!'
500 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
501 rm -rf "${TEMP}/device-mapper" > /dev/null
505 compile_e2fsprogs() {
506 if [ ! -f "${BLKID_BINCACHE}" ]
508 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
509 gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
511 rm -rf "${E2FSPROGS_DIR}"
512 tar -zxpf "${E2FSPROGS_SRCTAR}"
513 [ ! -d "${E2FSPROGS_DIR}" ] &&
514 gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
515 cd "${E2FSPROGS_DIR}"
516 print_info 1 'e2fsprogs: >> Configuring...'
517 ./configure --with-ldopts=-static >> ${LOGFILE} 2>&1 ||
518 gen_die 'Configuring e2fsprogs failed!'
519 print_info 1 'e2fsprogs: >> Compiling...'
520 MAKE=${UTILS_MAKE} compile_generic "" ""
521 print_info 1 'blkid: >> Copying to cache...'
522 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
523 gen_die 'Blkid executable does not exist!'
524 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
525 gen_die 'Could not strip blkid binary!'
526 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
527 gen_die 'bzip2 compression of blkid failed!'
528 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
529 gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
532 rm -rf "${E2FSPROGS_DIR}" > /dev/null
537 if [ ! -f "${FUSE_BINCACHE}" ]
539 [ ! -f "${FUSE_SRCTAR}" ] &&
540 gen_die "Could not find fuse source tarball: ${FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
543 tar -zxpf "${FUSE_SRCTAR}"
544 [ ! -d "${FUSE_DIR}" ] &&
545 gen_die "fuse directory ${FUSE_DIR} invalid"
547 print_info 1 'fuse: >> Configuring...'
548 ./configure --disable-kernel-module --disable-example >> ${LOGFILE} 2>&1 ||
549 gen_die 'Configuring fuse failed!'
550 print_info 1 'fuse: >> Compiling...'
551 MAKE=${UTILS_MAKE} compile_generic "" ""
553 # Since we're linking statically against libfuse, we don't need to cache the .so
554 # print_info 1 'libfuse: >> Copying to cache...'
555 # [ -f "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ] ||
556 # gen_die 'libfuse.so does not exist!'
557 # strip "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ||
558 # gen_die 'Could not strip libfuse.so!'
559 # cd "${TEMP}/${FUSE_DIR}/lib/.libs"
560 # tar -cjf "${FUSE_BINCACHE}" libfuse*so* ||
561 # gen_die 'Could not create fuse bincache!'
564 # rm -rf "${FUSE_DIR}" > /dev/null
568 compile_unionfs_fuse() {
569 if [ ! -f "${UNIONFS_FUSE_BINCACHE}" ]
572 # We'll call compile_fuse() from here, since it's not needed directly by anything else
575 [ ! -f "${UNIONFS_FUSE_SRCTAR}" ] &&
576 gen_die "Could not find unionfs-fuse source tarball: ${UNIONFS_FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
578 rm -rf "${UNIONFS_FUSE_DIR}"
579 tar -jxpf "${UNIONFS_FUSE_SRCTAR}"
580 [ ! -d "${UNIONFS_FUSE_DIR}" ] &&
581 gen_die "unionfs-fuse directory ${UNIONFS_FUSE_DIR} invalid"
582 cd "${UNIONFS_FUSE_DIR}"
583 print_info 1 'unionfs-fuse: >> Compiling...'
584 sed -i "/^\(CFLAGS\|CPPFLAGS\)/s:^\\(.*\\)$:\\1 -static -I${TEMP}/${FUSE_DIR}/include -L${TEMP}/${FUSE_DIR}/lib/.libs:" Makefile src/Makefile
585 sed -i "/^LIB = /s:^LIB = \(.*\)$:LIB = -static -L${TEMP}/${FUSE_DIR}/lib/.libs \1 -ldl -lrt:" Makefile src/Makefile
586 MAKE=${UTILS_MAKE} compile_generic "" ""
587 print_info 1 'unionfs-fuse: >> Copying to cache...'
588 [ -f "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ] ||
589 gen_die 'unionfs binary does not exist!'
590 strip "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
591 gen_die 'Could not strip unionfs binary!'
592 bzip2 "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
593 gen_die 'bzip2 compression of unionfs binary failed!'
594 mv "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs.bz2" "${UNIONFS_FUSE_BINCACHE}" ||
595 gen_die 'Could not copy the unionfs binary to the package directory, does the directory exist?'
598 rm -rf "${UNIONFS_FUSE_DIR}" > /dev/null