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 [ -n "${UTILS_CROSS_COMPILE}" ]
38 UTILS_CC="${UTILS_CROSS_COMPILE}gcc"
39 UTILS_LD="${UTILS_CROSS_COMPILE}ld"
40 UTILS_AS="${UTILS_CROSS_COMPILE}as"
43 if [ "${UTILS_ARCH}" != '' ]
45 ARGS="ARCH=\"${UTILS_ARCH}\""
47 if [ "${UTILS_CC}" != '' ]
49 ARGS="CC=\"${UTILS_CC}\""
51 if [ "${UTILS_LD}" != '' ]
53 ARGS="${ARGS} LD=\"${UTILS_LD}\""
55 if [ "${UTILS_AS}" != '' ]
57 ARGS="${ARGS} AS=\"${UTILS_AS}\""
66 if [ "${UTILS_ARCH}" != '' ]
68 export ARCH="${UTILS_ARCH}"
70 if [ "${UTILS_CC}" != '' ]
72 export CC="${UTILS_CC}"
74 if [ "${UTILS_LD}" != '' ]
76 export LD="${UTILS_LD}"
78 if [ "${UTILS_AS}" != '' ]
80 export AS="${UTILS_AS}"
86 if [ "${UTILS_ARCH}" != '' ]
90 if [ "${UTILS_CC}" != '' ]
94 if [ "${UTILS_LD}" != '' ]
98 if [ "${UTILS_AS}" != '' ]
107 if [ "${KERNEL_CC}" != '' ]
109 export CC="${KERNEL_CC}"
111 if [ "${KERNEL_LD}" != '' ]
113 export LD="${KERNEL_LD}"
115 if [ "${KERNEL_AS}" != '' ]
117 export AS="${KERNEL_AS}"
119 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
121 export CROSS_COMPILE="${KERNEL_CROSS_COMPILE}"
127 if [ "${KERNEL_CC}" != '' ]
131 if [ "${KERNEL_LD}" != '' ]
135 if [ "${KERNEL_AS}" != '' ]
139 if [ "${KERNEL_CROSS_COMPILE}" != '' ]
146 if [ "${ARCH}" != '' ]
148 export ORIG_ARCH="${ARCH}"
152 export ORIG_CC="${CC}"
156 export ORIG_LD="${LD}"
160 export ORIG_AS="${AS}"
162 if [ "${CROSS_COMPILE}" != '' ]
164 export ORIG_CROSS_COMPILE="${CROSS_COMPILE}"
169 if [ "${ORIG_ARCH}" != '' ]
171 export ARCH="${ORIG_ARCH}"
174 if [ "${ORIG_CC}" != '' ]
176 export CC="${ORIG_CC}"
179 if [ "${ORIG_LD}" != '' ]
181 export LD="${ORIG_LD}"
184 if [ "${ORIG_AS}" != '' ]
186 export AS="${ORIG_AS}"
189 if [ "${ORIG_CROSS_COMPILE}" != '' ]
191 export CROSS_COMPILE="${ORIG_CROSS_COMPILE}"
192 unset ORIG_CROSS_COMPILE
200 if [ -d "${GK_SHARE}/patches/${util}/${version}" ]
202 print_info 1 "${util}: >> Applying patches..."
203 for i in ${GK_SHARE}/patches/${util}/${version}/*{diff,patch}
208 patch -p${j} --backup-if-mismatch -f < "${i}" >/dev/null
215 if [ ${patch_success} != 1 ]
217 gen_die "could not apply patch ${i} for ${util}-${version}"
226 gen_die 'compile_generic(): improper usage!'
230 if [ "${argstype}" = 'kernel' ] || [ "${argstype}" = 'runtask' ]
234 elif [ "${2}" = 'utils' ]
239 case "${argstype}" in
240 kernel) ARGS="`compile_kernel_args`" ;;
241 utils) ARGS="`compile_utils_args`" ;;
242 *) ARGS="" ;; # includes runtask
246 # the eval usage is needed in the next set of code
247 # as ARGS can contain spaces and quotes, eg:
248 # ARGS='CC="ccache gcc"'
249 if [ "${argstype}" == 'runtask' ]
251 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS/-j?/j1} ${ARGS} ${target} $*" 1 0 1
252 eval ${MAKE} -s ${MAKEOPTS/-j?/-j1} "${ARGS}" ${target} $*
254 elif [ "${LOGLEVEL}" -gt "1" ]
256 # Output to stdout and logfile
257 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $*" 1 0 1
258 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* 2>&1 | tee -a ${LOGFILE}
261 # Output to logfile only
262 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${ARGS} ${1} $*" 1 0 1
263 eval ${MAKE} ${MAKEOPTS} ${ARGS} ${target} $* >> ${LOGFILE} 2>&1
266 [ "${RET}" -ne '0' ] &&
267 gen_die "Failed to compile the \"${target}\" target..."
271 if [ "${argstype}" = 'kernel' ]
274 elif [ "${argstype}" = 'utils' ]
281 print_info 1 " >> Compiling ${KV} modules..."
283 compile_generic modules kernel
284 export UNAME_MACHINE="${ARCH}"
285 [ "${INSTALL_MOD_PATH}" != '' ] && export INSTALL_MOD_PATH
286 compile_generic "modules_install" kernel
291 [ "${KERNEL_MAKE}" = '' ] &&
292 gen_die "KERNEL_MAKE undefined - I don't know how to compile a kernel for this arch!"
294 print_info 1 " >> Compiling ${KV} ${KERNEL_MAKE_DIRECTIVE/_install/ [ install ]/}..."
295 compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
296 if [ "${KERNEL_MAKE_DIRECTIVE_2}" != '' ]
298 print_info 1 " >> Starting supplimental compile of ${KV}: ${KERNEL_MAKE_DIRECTIVE_2}..."
299 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
301 if ! isTrue "${CMD_NOINSTALL}"
303 copy_image_with_preserve "kernel" \
305 "kernel-${KNAME}-${ARCH}-${KV}"
307 copy_image_with_preserve "System.map" \
309 "System.map-${KNAME}-${ARCH}-${KV}"
311 if isTrue "${GENZIMAGE}"
313 copy_image_with_preserve "kernelz" \
314 "${KERNEL_BINARY_2}" \
318 cp "${KERNEL_BINARY}" "${TMPDIR}/kernel-${KNAME}-${ARCH}-${KV}" ||
319 gen_die "Could not copy the kernel binary to ${TMPDIR}!"
320 cp "System.map" "${TMPDIR}/System.map-${KNAME}-${ARCH}-${KV}" ||
321 gen_die "Could not copy System.map to ${TMPDIR}!"
322 if isTrue "${GENZIMAGE}"
324 cp "${KERNEL_BINARY_2}" "${TMPDIR}/kernelz-${KV}" ||
325 gen_die "Could not copy the kernelz binary to ${TMPDIR}!"
331 [ -f "${BUSYBOX_SRCTAR}" ] ||
332 gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}!"
334 if [ -n "${BUSYBOX_CONFIG}" ]
336 [ -f "${BUSYBOX_CONFIG}" ] ||
337 gen_die "Could not find busybox config file: ${BUSYBOX_CONFIG}"
338 elif isTrue "${NETBOOT}" && [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")" ]
340 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/netboot-busy-config")"
341 elif isTrue "${NETBOOT}" && [ -f "${GK_SHARE}/netboot/busy-config" ]
343 BUSYBOX_CONFIG="${GK_SHARE}/netboot/busy-config"
344 elif [ -f "$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")" ]
346 BUSYBOX_CONFIG="$(arch_replace "${GK_SHARE}/arch/%%ARCH%%/busy-config")"
347 elif [ -f "${GK_SHARE}/defaults/busy-config" ]
349 BUSYBOX_CONFIG="${GK_SHARE}/defaults/busy-config"
351 gen_die "Could not find a busybox config file"
354 # Delete cache if stored config's MD5 does not match one to be used
355 if [ -f "${BUSYBOX_BINCACHE}" ]
357 oldconfig_md5=$(tar -xjf "${BUSYBOX_BINCACHE}" -O .config.gk_orig 2>/dev/null | md5sum)
358 newconfig_md5=$(md5sum < "${BUSYBOX_CONFIG}")
359 if [ "${oldconfig_md5}" != "${newconfig_md5}" ]
361 print_info 1 "busybox: >> Removing stale cache..."
362 rm -rf "${BUSYBOX_BINCACHE}"
364 print_info 1 "busybox: >> Using cache"
368 if [ ! -f "${BUSYBOX_BINCACHE}" ]
371 rm -rf "${BUSYBOX_DIR}" > /dev/null
372 /bin/tar -jxpf ${BUSYBOX_SRCTAR} ||
373 gen_die 'Could not extract busybox source tarball!'
374 [ -d "${BUSYBOX_DIR}" ] ||
375 gen_die 'Busybox directory ${BUSYBOX_DIR} is invalid!'
376 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
377 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config.gk_orig"
379 apply_patches busybox ${BUSYBOX_VER}
380 print_info 1 'busybox: >> Configuring...'
381 yes '' 2>/dev/null | compile_generic oldconfig utils
383 print_info 1 'busybox: >> Compiling...'
384 compile_generic all utils
385 print_info 1 'busybox: >> Copying to cache...'
386 [ -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] ||
387 gen_die 'Busybox executable does not exist!'
388 strip "${TEMP}/${BUSYBOX_DIR}/busybox" ||
389 gen_die 'Could not strip busybox binary!'
390 tar -cj -C "${TEMP}/${BUSYBOX_DIR}" -f "${BUSYBOX_BINCACHE}" busybox .config .config.gk_orig ||
391 gen_die 'Could not create the busybox bincache!'
394 rm -rf "${BUSYBOX_DIR}" > /dev/null
399 compile_device_mapper
400 if [ ! -f "${LVM_BINCACHE}" ]
402 [ -f "${LVM_SRCTAR}" ] ||
403 gen_die "Could not find LVM source tarball: ${LVM_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
405 rm -rf ${LVM_DIR} > /dev/null
406 /bin/tar -zxpf ${LVM_SRCTAR} ||
407 gen_die 'Could not extract LVM source tarball!'
408 [ -d "${LVM_DIR}" ] ||
409 gen_die 'LVM directory ${LVM_DIR} is invalid!'
410 rm -rf "${TEMP}/device-mapper" > /dev/null
411 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
412 gen_die "Could not extract device-mapper binary cache!";
415 print_info 1 'lvm: >> Configuring...'
416 LDFLAGS="-L${TEMP}/device-mapper/lib" \
417 CFLAGS="-I${TEMP}/device-mapper/include" \
418 CPPFLAGS="-I${TEMP}/device-mapper/include" \
419 ./configure --enable-static_link --prefix=${TEMP}/lvm >> ${LOGFILE} 2>&1 ||
420 gen_die 'Configure of lvm failed!'
421 print_info 1 'lvm: >> Compiling...'
422 compile_generic '' utils
423 compile_generic 'install' utils
426 print_info 1 ' >> Copying to bincache...'
427 strip "sbin/lvm.static" ||
428 gen_die 'Could not strip lvm.static!'
429 /bin/tar -cjf "${LVM_BINCACHE}" sbin/lvm.static ||
430 gen_die 'Could not create binary cache'
433 rm -rf "${TEMP}/device-mapper" > /dev/null
434 rm -rf "${LVM_DIR}" lvm
439 compile_device_mapper
440 if [ ! -f "${DMRAID_BINCACHE}" ]
442 [ -f "${DMRAID_SRCTAR}" ] ||
443 gen_die "Could not find DMRAID source tarball: ${DMRAID_SRCTAR}! Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
445 rm -rf ${DMRAID_DIR} > /dev/null
446 /bin/tar -jxpf ${DMRAID_SRCTAR} ||
447 gen_die 'Could not extract DMRAID source tarball!'
448 [ -d "${DMRAID_DIR}" ] ||
449 gen_die 'DMRAID directory ${DMRAID_DIR} is invalid!'
450 rm -rf "${TEMP}/device-mapper" > /dev/null
451 /bin/tar -jxpf "${DEVICE_MAPPER_BINCACHE}" -C "${TEMP}" ||
452 gen_die "Could not extract device-mapper binary cache!";
455 print_info 1 'dmraid: >> Configuring...'
457 LDFLAGS="-L${TEMP}/device-mapper/lib" \
458 CFLAGS="-I${TEMP}/device-mapper/include" \
459 CPPFLAGS="-I${TEMP}/device-mapper/include" \
460 ./configure --enable-static_link --prefix=${TEMP}/dmraid >> ${LOGFILE} 2>&1 ||
461 gen_die 'Configure of dmraid failed!'
463 # We dont necessarily have selinux installed yet... look into
464 # selinux global support in the future.
465 sed -i tools/Makefile -e "s|DMRAIDLIBS += -lselinux||g"
466 ###echo "DMRAIDLIBS += -lselinux -lsepol" >> tools/Makefile
467 mkdir -p "${TEMP}/dmraid"
468 print_info 1 'dmraid: >> Compiling...'
469 # Force dmraid to be built with -j1 for bug #188273
470 MAKEOPTS=-j1 compile_generic '' utils
471 #compile_generic 'install' utils
472 mkdir ${TEMP}/dmraid/sbin
473 install -m 0755 -s tools/dmraid "${TEMP}/dmraid/sbin/dmraid"
474 print_info 1 ' >> Copying to bincache...'
476 /bin/tar -cjf "${DMRAID_BINCACHE}" sbin/dmraid ||
477 gen_die 'Could not create binary cache'
480 rm -rf "${TEMP}/device-mapper" > /dev/null
481 rm -rf "${DMRAID_DIR}" dmraid
485 compile_device_mapper() {
486 if [ ! -f "${DEVICE_MAPPER_BINCACHE}" ]
488 [ ! -f "${DEVICE_MAPPER_SRCTAR}" ] &&
489 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!"
491 rm -rf "${DEVICE_MAPPER_DIR}"
492 /bin/tar -zxpf "${DEVICE_MAPPER_SRCTAR}"
493 [ ! -d "${DEVICE_MAPPER_DIR}" ] &&
494 gen_die "device-mapper directory ${DEVICE_MAPPER_DIR} invalid"
495 cd "${DEVICE_MAPPER_DIR}"
496 ./configure --prefix=${TEMP}/device-mapper --enable-static_link \
497 --disable-selinux >> ${LOGFILE} 2>&1 ||
498 gen_die 'Configuring device-mapper failed!'
499 print_info 1 'device-mapper: >> Compiling...'
500 compile_generic '' utils
501 compile_generic 'install' utils
502 print_info 1 ' >> Copying to cache...'
504 rm -rf "${TEMP}/device-mapper/man" ||
505 gen_die 'Could not remove manual pages!'
506 strip "${TEMP}/device-mapper/sbin/dmsetup" ||
507 gen_die 'Could not strip dmsetup binary!'
508 /bin/tar -jcpf "${DEVICE_MAPPER_BINCACHE}" device-mapper ||
509 gen_die 'Could not tar up the device-mapper binary!'
510 [ -f "${DEVICE_MAPPER_BINCACHE}" ] ||
511 gen_die 'device-mapper cache not created!'
513 rm -rf "${DEVICE_MAPPER_DIR}" > /dev/null
514 rm -rf "${TEMP}/device-mapper" > /dev/null
518 compile_e2fsprogs() {
519 if [ ! -f "${BLKID_BINCACHE}" ]
521 [ ! -f "${E2FSPROGS_SRCTAR}" ] &&
522 gen_die "Could not find e2fsprogs source tarball: ${E2FSPROGS_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
524 rm -rf "${E2FSPROGS_DIR}"
525 tar -zxpf "${E2FSPROGS_SRCTAR}"
526 [ ! -d "${E2FSPROGS_DIR}" ] &&
527 gen_die "e2fsprogs directory ${E2FSPROGS_DIR} invalid"
528 cd "${E2FSPROGS_DIR}"
529 print_info 1 'e2fsprogs: >> Configuring...'
530 ./configure --with-ldopts=-static >> ${LOGFILE} 2>&1 ||
531 gen_die 'Configuring e2fsprogs failed!'
532 print_info 1 'e2fsprogs: >> Compiling...'
533 MAKE=${UTILS_MAKE} compile_generic "" ""
534 print_info 1 'blkid: >> Copying to cache...'
535 [ -f "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ] ||
536 gen_die 'Blkid executable does not exist!'
537 strip "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
538 gen_die 'Could not strip blkid binary!'
539 bzip2 "${TEMP}/${E2FSPROGS_DIR}/misc/blkid" ||
540 gen_die 'bzip2 compression of blkid failed!'
541 mv "${TEMP}/${E2FSPROGS_DIR}/misc/blkid.bz2" "${BLKID_BINCACHE}" ||
542 gen_die 'Could not copy the blkid binary to the package directory, does the directory exist?'
545 rm -rf "${E2FSPROGS_DIR}" > /dev/null
550 if [ ! -f "${FUSE_BINCACHE}" ]
552 [ ! -f "${FUSE_SRCTAR}" ] &&
553 gen_die "Could not find fuse source tarball: ${FUSE_SRCTAR}. Please place it there, or place another version, changing /etc/genkernel.conf as necessary!"
556 tar -zxpf "${FUSE_SRCTAR}"
557 [ ! -d "${FUSE_DIR}" ] &&
558 gen_die "fuse directory ${FUSE_DIR} invalid"
560 print_info 1 'fuse: >> Configuring...'
561 ./configure --disable-kernel-module --disable-example >> ${LOGFILE} 2>&1 ||
562 gen_die 'Configuring fuse failed!'
563 print_info 1 'fuse: >> Compiling...'
564 MAKE=${UTILS_MAKE} compile_generic "" ""
566 # Since we're linking statically against libfuse, we don't need to cache the .so
567 # print_info 1 'libfuse: >> Copying to cache...'
568 # [ -f "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ] ||
569 # gen_die 'libfuse.so does not exist!'
570 # strip "${TEMP}/${FUSE_DIR}/lib/.libs/libfuse.so" ||
571 # gen_die 'Could not strip libfuse.so!'
572 # cd "${TEMP}/${FUSE_DIR}/lib/.libs"
573 # tar -cjf "${FUSE_BINCACHE}" libfuse*so* ||
574 # gen_die 'Could not create fuse bincache!'
577 # rm -rf "${FUSE_DIR}" > /dev/null
581 compile_unionfs_fuse() {
582 if [ ! -f "${UNIONFS_FUSE_BINCACHE}" ]
585 # We'll call compile_fuse() from here, since it's not needed directly by anything else
588 [ ! -f "${UNIONFS_FUSE_SRCTAR}" ] &&
589 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!"
591 rm -rf "${UNIONFS_FUSE_DIR}"
592 tar -jxpf "${UNIONFS_FUSE_SRCTAR}"
593 [ ! -d "${UNIONFS_FUSE_DIR}" ] &&
594 gen_die "unionfs-fuse directory ${UNIONFS_FUSE_DIR} invalid"
595 cd "${UNIONFS_FUSE_DIR}"
596 print_info 1 'unionfs-fuse: >> Compiling...'
597 sed -i "/^\(CFLAGS\|CPPFLAGS\)/s:^\\(.*\\)$:\\1 -static -I${TEMP}/${FUSE_DIR}/include -L${TEMP}/${FUSE_DIR}/lib/.libs:" Makefile src/Makefile
598 sed -i "/^LIB = /s:^LIB = \(.*\)$:LIB = -static -L${TEMP}/${FUSE_DIR}/lib/.libs \1 -ldl -lrt:" Makefile src/Makefile
599 MAKE=${UTILS_MAKE} compile_generic "" ""
600 print_info 1 'unionfs-fuse: >> Copying to cache...'
601 [ -f "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ] ||
602 gen_die 'unionfs binary does not exist!'
603 strip "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
604 gen_die 'Could not strip unionfs binary!'
605 bzip2 "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs" ||
606 gen_die 'bzip2 compression of unionfs binary failed!'
607 mv "${TEMP}/${UNIONFS_FUSE_DIR}/src/unionfs.bz2" "${UNIONFS_FUSE_BINCACHE}" ||
608 gen_die 'Could not copy the unionfs binary to the package directory, does the directory exist?'
611 rm -rf "${UNIONFS_FUSE_DIR}" > /dev/null