fixes for sparc, cant set LD or AS for sparc64
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2
3 compile_args()
4 {
5         local ARGS
6
7         ARGS=""
8         if [ "${CC}" != "" ]
9         then
10                 ARGS="CC=\"${CC}\""
11         fi
12         if [ "${LD}" != "" ]
13         then
14                 ARGS="${ARGS} LD=\"${LD}\""
15         fi
16
17         if [ "${AS}" != "" ]
18         then
19                 ARGS="${ARGS} AS=\"${AS}\""
20         fi
21         
22         echo -n "${ARGS}"
23 }
24
25 compile_generic() {
26         local RET
27         if [ "$#" -lt "1" ]
28         then
29                 gen_die "compile_generic(): improper usage"
30         fi
31
32         ARGS=`compile_args`
33
34         if [ "${DEBUGLEVEL}" -gt "1" ]
35         then
36                 # Output to stdout and debugfile
37                 print_info 2 "COMMAND: ${MAKE} ${ARGS} ${MAKEOPTS} ${1}" 1 0
38                 ${MAKE} ${ARGS} ${MAKEOPTS} ${1} 2>&1 | tee -a ${DEBUGFILE}
39                 RET=$?
40         else
41                 # Output to debugfile only
42                 print_info 2 "COMMAND: ${MAKE} ${ARGS} ${MAKEOPTS} ${1}" 1 0
43                 ${MAKE} ${ARGS} ${MAKEOPTS} ${1} >> ${DEBUGFILE} 2>&1
44                 RET=$?
45         fi
46         [ "${RET}" -ne "0" ] && gen_die "compile of failed"
47 }
48
49 compile_dep() {
50         # Only make dep for 2.4 kernels
51         if [ "${PAT}" -gt "4" ]
52         then
53                 print_info 1 "kernel: skipping make dep for non 2.4 kernels"
54         else
55                 print_info 1 "kernel: Making dependancies for linux ${KV}"
56                 cd ${KERNEL_DIR}
57                 compile_generic "dep"
58         fi
59 }
60
61 compile_modules() {
62         print_info 1 "kernel: Starting compile of linux ${KV} modules"
63         cd ${KERNEL_DIR}
64         compile_generic "modules"
65         compile_generic "modules_install"
66 }
67
68 compile_kernel() {
69         [ "${KERNEL_MAKE}" = "" ] && gen_die "KERNEL_MAKE undefined. Don't know how to compile kernel for arch."
70         cd ${KERNEL_DIR}
71         print_info 1 "kernel: Starting compile of linux ${KV} ${KERNEL_MAKE}"
72         compile_generic "${KERNEL_MAKE}"
73         cp "${KERNEL_BINARY}" "/boot/kernel-${KV}" || gen_die "Could not copy kernel binary to boot"
74 }
75
76 compile_busybox() {
77         if [ ! -f "${BUSYBOX_BINCACHE}" ]
78         then
79                 [ ! -f "${BUSYBOX_SRCTAR}" ] && gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}"
80                 [ ! -f "${BUSYBOX_CONFIG}" ] && gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}"
81                 cd ${TEMP}
82                 rm -rf ${BUSYBOX_DIR} > /dev/null
83                 tar -jxpf ${BUSYBOX_SRCTAR} || gen_die "Could not extract busybox source tarball"
84                 [ ! -d "${BUSYBOX_DIR}" ] && gen_die "Busybox directory ${BUSYBOX_DIR} invalid"
85                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
86                 cd "${BUSYBOX_DIR}"
87                 if [ "${USE_DIETLIBC}" -eq "1" ]
88                 then
89                         OLD_CC="${CC}"
90                         CC="${TEMP}/diet/bin/diet ${CC}"
91                 fi
92                 print_info 1 "Busybox: make oldconfig"
93                 compile_generic "oldconfig"
94                 print_info 1 "Busybox: make all"
95                 compile_generic "all"
96                 if [ "${USE_DIETLIBC}" -eq "1" ]
97                 then
98                         CC="${OLD_CC}"
99                 fi
100                 print_info 1 "Busybox: copying to bincache"
101                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] && gen_die "busybox executable does not exist after compile, error"
102                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "could not strip busybox"
103                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "bzip2 compression of busybox failed"
104                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" ] && gen_die "could not find compressed busybox binary"
105                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" || gen_die "could not copy busybox binary to arch package directory, does the directory exist?"
106         else
107                 print_info 1 "Busybox: Found bincache at ${BUSYBOX_BINCACHE}"
108         fi
109 }
110
111 compile_modutils() {
112         if [ ! -f "${MODUTILS_BINCACHE}" ]
113         then
114                 [ ! -f "${MODUTILS_SRCTAR}" ] && gen_die "Could not find modutils source tarball: ${MODUTILS_BINCACHE}"
115                 cd ${TEMP}
116                 rm -rf "${MODUTILS_DIR}"
117                 tar -jxpf "${MODUTILS_SRCTAR}"
118                 [ ! -d "${MODUTILS_DIR}" ] && gen_die "Modutils directory ${MODUTILS_DIR} invalid"
119                 cd "${MODUTILS_DIR}"
120                 print_info 1 "modutils: configure"
121                 ${ARGS} ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 || gen_die "Configure of modutils failed"
122                 print_info 1 "modutils: make all"
123                 compile_generic "all"
124                 print_info 1 "modutils: copying to bincache"
125                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] && gen_die "insmod.static does not exist after compilation of modutils"
126                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "could not strip insmod.static"
127                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "compression of insmod.static failed"
128                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
129                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODUTILS_BINCACHE}"
130         else
131                 print_info 1 "modutils: Found bincache at ${MODUTILS_BINCACHE}"
132         fi
133 }
134
135 compile_module_init_tools() {
136         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
137         then
138                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] && gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_BINCACHE}"
139                 cd ${TEMP}
140                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
141                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
142                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] && gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} invalid"
143                 cd "${MODULE_INIT_TOOLS_DIR}"
144                 print_info 1 "module-init-tools: configure"
145                 ${ARGS} ./configure >> ${DEBUGFILE} 2>&1 || gen_die "Configure of module-init-tools failed"
146                 print_info 1 "module-init-tools: make all"
147                 compile_generic "all"
148                 print_info 1 "module-init-tools: copying to bincache"
149                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] && gen_die "insmod.static does not exist after compilation of module-init-tools"
150                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "could not strip insmod.static"
151                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "compression of insmod.static failed"
152                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
153                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}"
154         else
155                 print_info 1 "module-init-tools: Found bincache at ${MODULE_INIT_TOOLS_BINCACHE}"
156         fi
157 }
158
159 compile_dietlibc() {
160         local BUILD_DIETLIBC
161         local ORIGTEMP
162
163         BUILD_DIETLIBC=0
164         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
165         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
166         if [ "${BUILD_DIETLIBC}" -eq "0" ]
167         then
168                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
169                 if [ "${TEMP}" != "${ORIGTEMP}" ]
170                 then
171                         print_info 1 "Dietlibc: Bincache exists, but current temp directory is different than original. Rebuilding."
172                         BUILD_DIETLIBC=1
173                 fi
174         fi
175
176         if [ "${BUILD_DIETLIBC}" -eq "1" ]
177         then
178                 [ ! -f "${DIETLIBC_SRCTAR}" ] && gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
179                 cd ${TEMP}
180                 rm -rf ${DIETLIBC_DIR} > /dev/null
181                 tar -jxpf ${DIETLIBC_SRCTAR} || gen_die "Could not extract dietlibc source tarball"
182                 [ ! -d "${DIETLIBC_DIR}" ] && gen_die "Dietlibc directory ${DIETLIBC_DIR} invalid"
183                 cd "${DIETLIBC_DIR}"
184                 print_info 1 "Dietlibc: make"
185                 compile_generic "prefix=${TEMP}/diet"
186                 print_info 1 "Dietlibc: installing"
187                 compile_generic "prefix=${TEMP}/diet install"
188                 print_info 1 "Dietlibc: copying to bincache"
189                 cd ${TEMP}
190                 tar -jcpf "${DIETLIBC_BINCACHE}" diet || gen_die "Could not tar up dietlibc bin"
191                 [ ! -f "${DIETLIBC_BINCACHE}" ] && gen_die "bincache not created"
192                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
193         else
194                 print_info 1 "Dietlibc: Found bincache at ${DIETLIBC_BINCACHE}"
195         fi
196 }
197