add new genkernel dev
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2
3 compile_generic() {
4         local RET
5         if [ "$#" -lt "1" ]
6         then
7                 gen_die "compile_generic(): improper usage"
8         fi
9
10         if [ "${DEBUGLEVEL}" -gt "1" ]
11         then
12                 # Output to stdout and debugfile
13                 ${MAKE} CC="${CC}" AS="${AS}" LD="${LD}" ${MAKEOPTS} ${1} 2>&1 | tee -a ${DEBUGFILE}
14                 RET=$?
15         else
16                 # Output to debugfile only
17                 ${MAKE} CC="${CC}" AS="${AS}" LD="${LD}" ${MAKEOPTS} ${1} >> ${DEBUGFILE} 2>&1
18                 RET=$?
19         fi
20         [ "${RET}" -ne "0" ] && gen_die "compile of failed"
21 }
22
23 compile_modules() {
24         print_info 1 "kernel: Starting compile of linux ${KV} modules"
25         cd ${KERNEL_DIR}
26         compile_generic "modules"
27         compile_generic "modules_install"
28 }
29
30 compile_kernel() {
31         [ "${KERNEL_MAKE}" = "" ] && gen_die "KERNEL_MAKE undefined. Don't know how to compile kernel for arch."
32         cd ${KERNEL_DIR}
33         print_info 1 "kernel: Starting compile of linux ${KV} ${KERNEL_MAKE}"
34         compile_generic "${KERNEL_MAKE}"
35         cp "${KERNEL_BINARY}" "/boot/kernel-${KV}" || gen_die "Could not copy kernel binary to boot"
36 }
37
38 compile_busybox() {
39         if [ ! -f "${BUSYBOX_BINCACHE}" ]
40         then
41                 [ ! -f "${BUSYBOX_SRCTAR}" ] && gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}"
42                 [ ! -f "${BUSYBOX_CONFIG}" ] && gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}"
43                 cd ${TEMP}
44                 rm -rf ${BUSYBOX_DIR} > /dev/null
45                 tar -jxpf ${BUSYBOX_SRCTAR} || gen_die "Could not extract busybox source tarball"
46                 [ ! -d "${BUSYBOX_DIR}" ] && gen_die "Busybox directory ${BUSYBOX_DIR} invalid"
47                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
48                 cd "${BUSYBOX_DIR}"
49                 if [ "${USE_DIETLIBC}" -eq "1" ]
50                 then
51                         OLD_CC="${CC}"
52                         CC="${TEMP}/diet/bin/diet ${CC}"
53                 fi
54                 print_info 1 "Busybox: make oldconfig"
55                 compile_generic "oldconfig"
56                 print_info 1 "Busybox: make all"
57                 compile_generic "all"
58                 if [ "${USE_DIETLIBC}" -eq "1" ]
59                 then
60                         CC="${OLD_CC}"
61                 fi
62                 print_info 1 "Busybox: copying to bincache"
63                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] && gen_die "busybox executable does not exist after compile, error"
64                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "bzip2 compression of busybox failed"
65                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" ] && gen_die "could not find compressed busybox binary"
66                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" || gen_die "could not copy busybox binary to arch package directory, does the directory exist?"
67         else
68                 print_info 1 "Busybox: Found bincache at ${BUSYBOX_BINCACHE}"
69         fi
70 }
71
72 compile_module_init_tools() {
73         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
74         then
75                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] && gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_BINCACHE}"
76                 cd ${TEMP}
77                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
78                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
79                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] && gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} invalid"
80                 cd "${MODULE_INIT_TOOLS_DIR}"
81                 print_info 1 "module-init-tools: configure"
82                 ./configure >> ${DEBUGFILE} 2>&1 || gen_die "Configure of module-init-tools failed"
83                 print_info 1 "module-init-tools: make all"
84                 compile_generic "all"
85                 print_info 1 "module-init-tools: copying to bincache"
86                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] && gen_die "insmod.static does not exist after compilation of module-init-tools"
87                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "compression of busybox failed"
88                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
89                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}"
90         else
91                 print_info 1 "module-init-tools: Found bincache at ${MODULE_INIT_TOOLS_BINCACHE}"
92         fi
93 }
94
95 compile_dietlibc() {
96         local BUILD_DIETLIBC
97         local ORIGTEMP
98
99         BUILD_DIETLIBC=0
100         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
101         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
102         if [ "${BUILD_DIETLIBC}" -eq "0" ]
103         then
104                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
105                 if [ "${TEMP}" != "${ORIGTEMP}" ]
106                 then
107                         print_info 1 "Dietlibc: Bincache exists, but current temp directory is different than original. Rebuilding."
108                         BUILD_DIETLIBC=1
109                 fi
110         fi
111
112         if [ "${BUILD_DIETLIBC}" -eq "1" ]
113         then
114                 [ ! -f "${DIETLIBC_SRCTAR}" ] && gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
115                 cd ${TEMP}
116                 rm -rf ${DIETLIBC_DIR} > /dev/null
117                 tar -jxpf ${DIETLIBC_SRCTAR} || gen_die "Could not extract dietlibc source tarball"
118                 [ ! -d "${DIETLIBC_DIR}" ] && gen_die "Dietlibc directory ${DIETLIBC_DIR} invalid"
119                 cd "${DIETLIBC_DIR}"
120                 print_info 1 "Dietlibc: make"
121                 compile_generic "prefix=${TEMP}/diet"
122                 print_info 1 "Dietlibc: installing"
123                 compile_generic "prefix=${TEMP}/diet install"
124                 print_info 1 "Dietlibc: copying to bincache"
125                 cd ${TEMP}
126                 tar -jcpf "${DIETLIBC_BINCACHE}" diet || gen_die "Could not tar up dietlibc bin"
127                 [ ! -f "${DIETLIBC_BINCACHE}" ] && gen_die "bincache not created"
128                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
129         else
130                 print_info 1 "Dietlibc: Found bincache at ${DIETLIBC_BINCACHE}"
131         fi
132 }
133