uname machine for parisc, etc
[genkernel.git] / gen_compile.sh
1 #!/bin/bash
2
3 compile_kernel_args()
4 {
5         local ARGS
6
7         ARGS=""
8         if [ "${KERNEL_CC}" != "" ]
9         then
10                 ARGS="CC=\"${KERNEL_CC}\""
11         fi
12         if [ "${KERNEL_LD}" != "" ]
13         then
14                 ARGS="${ARGS} LD=\"${KERNEL_LD}\""
15         fi
16
17         if [ "${KERNEL_AS}" != "" ]
18         then
19                 ARGS="${ARGS} AS=\"${KERNEL_AS}\""
20         fi
21
22         echo -n "${ARGS}"
23 }
24
25 compile_utils_args()
26 {
27         local ARGS
28
29         ARGS=""
30         if [ "${UTILS_CC}" != "" ]
31         then
32                 ARGS="CC=\"${UTILS_CC}\""
33         fi
34         if [ "${UTILS_LD}" != "" ]
35         then
36                 ARGS="${ARGS} LD=\"${UTILS_LD}\""
37         fi
38
39         if [ "${UTILS_AS}" != "" ]
40         then
41                 ARGS="${ARGS} AS=\"${UTILS_AS}\""
42         fi
43
44         echo -n "${ARGS}"
45 }
46
47 export_utils_args()
48 {
49         if [ "${UTILS_CC}" != "" ]
50         then
51                 export CC="${UTILS_CC}"
52         fi
53         if [ "${UTILS_LD}" != "" ]
54         then
55                 export LD="${UTILS_LD}"
56         fi
57         if [ "${UTILS_AS}" != "" ]
58         then
59                 export AS="${UTILS_AS}"
60         fi
61 }
62
63 unset_utils_args()
64 {
65         if [ "${UTILS_CC}" != "" ]
66         then
67                 unset CC
68         fi
69         if [ "${UTILS_LD}" != "" ]
70         then
71                 unset LD
72         fi
73         if [ "${UTILS_AS}" != "" ]
74         then
75                 unset AS
76         fi
77 }
78
79 export_kernel_args()
80 {
81         if [ "${KERNEL_CC}" != "" ]
82         then
83                 export CC="${KERNEL_CC}"
84         fi
85         if [ "${KERNEL_LD}" != "" ]
86         then
87                 export LD="${KERNEL_LD}"
88         fi
89         if [ "${KERNEL_AS}" != "" ]
90         then
91                 export AS="${KERNEL_AS}"
92         fi
93 }
94
95 unset_kernel_args()
96 {
97         if [ "${KERNEL_CC}" != "" ]
98         then
99                 unset CC
100         fi
101         if [ "${KERNEL_LD}" != "" ]
102         then
103                 unset LD
104         fi
105         if [ "${KERNEL_AS}" != "" ]
106         then
107                 unset AS
108         fi
109 }
110
111 compile_generic() {
112         local RET
113         if [ "$#" -lt "2" ]
114         then
115                 gen_die "compile_generic(): improper usage"
116         fi
117
118         if [ "${2}" = "kernel" ]
119         then
120                 export_kernel_args
121                 MAKE=${KERNEL_MAKE}
122         elif [ "${2}" = "utils" ]
123         then
124                 export_utils_args
125                 MAKE=${UTILS_MAKE}
126         fi
127
128         if [ "${DEBUGLEVEL}" -gt "1" ]
129         then
130                 # Output to stdout and debugfile
131                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${1}" 1 0 1
132                 ${MAKE} ${MAKEOPTS} ${1} 2>&1 | tee -a ${DEBUGFILE}
133                 RET=$?
134         else
135                 # Output to debugfile only
136                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${1}" 1 0 1
137                 ${MAKE} ${MAKEOPTS} ${1} >> ${DEBUGFILE} 2>&1
138                 RET=$?
139         fi
140         [ "${RET}" -ne "0" ] && gen_die "compile of ${1} failed"
141
142         unset MAKE
143         if [ "${2}" = "kernel" ]
144         then
145                 unset_kernel_args
146         elif [ "${2}" = "utils" ]
147         then
148                 unset_utils_args
149         fi
150
151 }
152
153 extract_dietlibc_bincache() {
154         print_info 1 "extracting dietlibc bincache"
155         CURR_DIR=`pwd`
156         cd "${TEMP}"
157         rm -rf "${TEMP}/diet" > /dev/null
158         tar -jxpf "${DIETLIBC_BINCACHE}" || gen_die "Could not extract dietlibc bincache"
159         [ ! -d "${TEMP}/diet" ] && gen_die "${TEMP}/diet directory not found"
160         cd "${CURR_DIR}"
161 }
162
163 clean_dietlibc_bincache() {
164         print_info 1 "cleaning up dietlibc bincache"
165         CURR_DIR=`pwd`
166         cd "${TEMP}"
167         rm -rf "${TEMP}/diet" > /dev/null
168         cd "${CURR_DIR}"
169 }
170
171
172 compile_dep() {
173         # Only make dep for 2.4 kernels
174         if [ "${PAT}" -gt "4" ]
175         then
176                 print_info 1 "kernel: skipping make dep for non 2.4 kernels"
177         else
178                 print_info 1 "kernel: Making dependencies for linux ${KV}"
179                 cd ${KERNEL_DIR}
180                 compile_generic "dep" kernel
181         fi
182 }
183
184 compile_modules() {
185         print_info 1 "kernel: Starting compile of linux ${KV} modules"
186         cd ${KERNEL_DIR}
187         compile_generic "modules" kernel
188         export UNAME_MACHINE="${ARCH}"
189         compile_generic "modules_install" kernel
190         unset UNAME_MACHINE
191 }
192
193 compile_kernel() {
194         [ "${KERNEL_MAKE}" = "" ] && gen_die "KERNEL_MAKE undefined. Don't know how to compile kernel for arch."
195         cd ${KERNEL_DIR}
196         print_info 1 "kernel: Starting compile of linux ${KV} ${KERNEL_MAKE_DIRECTIVE}"
197         compile_generic "${KERNEL_MAKE_DIRECTIVE}" kernel
198         if [ "${KERNEL_MAKE_DIRECTIVE_2}" != "" ]
199         then
200                 print_info 1 "kernel: Starting suppliment compile of linux ${KV} ${KERNEL_MAKE_DIRECTIVE_2}"
201                 compile_generic "${KERNEL_MAKE_DIRECTIVE_2}" kernel
202         fi
203         cp "${KERNEL_BINARY}" "/boot/kernel-${KV}" || gen_die "Could not copy kernel binary to boot"
204 }
205
206 compile_busybox() {
207         if [ ! -f "${BUSYBOX_BINCACHE}" ]
208         then
209                 [ ! -f "${BUSYBOX_SRCTAR}" ] && gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}"
210                 [ ! -f "${BUSYBOX_CONFIG}" ] && gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}"
211                 cd "${TEMP}"
212                 rm -rf ${BUSYBOX_DIR} > /dev/null
213                 tar -jxpf ${BUSYBOX_SRCTAR} || gen_die "Could not extract busybox source tarball"
214                 [ ! -d "${BUSYBOX_DIR}" ] && gen_die "Busybox directory ${BUSYBOX_DIR} invalid"
215                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
216                 cd "${BUSYBOX_DIR}"
217 # Busybox and dietlibc don't play nice right now
218 #               if [ "${USE_DIETLIBC}" -eq "1" ]
219 #               then
220 #                       extract_dietlibc_bincache
221 #                       OLD_CC="${UTILS_CC}"
222 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
223 #               fi
224                 print_info 1 "Busybox: make oldconfig"
225                 yes "" | compile_generic "oldconfig" utils
226                 print_info 1 "Busybox: make all"
227                 compile_generic "all" utils
228 # Busybox and dietlibc don't play nice right now
229 #               if [ "${USE_DIETLIBC}" -eq "1" ]
230 #               then
231 #                       clean_dietlibc_bincache
232 #                       UTILS_CC="${OLD_CC}"
233 #               fi
234                 print_info 1 "Busybox: copying to bincache"
235                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] && gen_die "busybox executable does not exist after compile, error"
236                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "could not strip busybox"
237                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "bzip2 compression of busybox failed"
238                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" ] && gen_die "could not find compressed busybox binary"
239                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" || gen_die "could not copy busybox binary to arch package directory, does the directory exist?"
240
241                 print_info 1 "Busybox: cleaning up"
242                 cd "${TEMP}"
243                 rm -rf "${BUSYBOX_DIR}" > /dev/null
244         else
245                 print_info 1 "Busybox: Found bincache at ${BUSYBOX_BINCACHE}"
246         fi
247 }
248
249 compile_modutils() {
250         local ARGS
251         if [ ! -f "${MODUTILS_BINCACHE}" ]
252         then
253                 [ ! -f "${MODUTILS_SRCTAR}" ] && gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}"
254                 cd "${TEMP}"
255                 rm -rf "${MODUTILS_DIR}"
256                 tar -jxpf "${MODUTILS_SRCTAR}"
257                 [ ! -d "${MODUTILS_DIR}" ] && gen_die "Modutils directory ${MODUTILS_DIR} invalid"
258                 cd "${MODUTILS_DIR}"
259                 print_info 1 "modutils: configure"
260
261                 if [ "${USE_DIETLIBC}" -eq "1" ]
262                 then
263                         extract_dietlibc_bincache
264                         OLD_CC="${UTILS_CC}"
265                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
266                 fi
267
268                 export_utils_args
269                 ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 || gen_die "Configure of modutils failed"
270                 unset_utils_args
271
272                 print_info 1 "modutils: make all"
273                 compile_generic "all" utils
274
275                 if [ "${USE_DIETLIBC}" -eq "1" ]
276                 then
277                         clean_dietlibc_bincache
278                         UTILS_CC="${OLD_CC}"
279                 fi
280
281                 print_info 1 "modutils: copying to bincache"
282                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] && gen_die "insmod.static does not exist after compilation of modutils"
283                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "could not strip insmod.static"
284                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "compression of insmod.static failed"
285                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
286                 mv "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" "${MODUTILS_BINCACHE}" || gen_die "could not move compress binary to bincache"
287
288                 print_info 1 "modutils: cleaning up"
289                 cd "${TEMP}"
290                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
291         else
292                 print_info 1 "modutils: Found bincache at ${MODUTILS_BINCACHE}"
293         fi
294 }
295
296 compile_module_init_tools() {
297         local ARGS
298         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
299         then
300                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] && gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
301                 cd "${TEMP}"
302                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
303                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
304                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] && gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} invalid"
305                 cd "${MODULE_INIT_TOOLS_DIR}"
306                 print_info 1 "module-init-tools: configure"
307
308                 if [ "${USE_DIETLIBC}" -eq "1" ]
309                 then
310                         extract_dietlibc_bincache
311                         OLD_CC="${UTILS_CC}"
312                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
313                 fi
314
315                 export_utils_args
316                 ./configure >> ${DEBUGFILE} 2>&1 || gen_die "Configure of module-init-tools failed"
317                 unset_utils_args
318                 print_info 1 "module-init-tools: make all"
319                 compile_generic "all" utils
320
321                 if [ "${USE_DIETLIBC}" -eq "1" ]
322                 then
323                         clean_dietlibc_bincache
324                         UTILS_CC="${OLD_CC}"
325                 fi
326
327                 print_info 1 "module-init-tools: copying to bincache"
328                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] && gen_die "insmod.static does not exist after compilation of module-init-tools"
329                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "could not strip insmod.static"
330                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "compression of insmod.static failed"
331                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
332                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}" || gen_die "could not move compressed binary to bincache"
333
334                 print_info 1 "module-init-tools: cleaning up"
335                 cd "${TEMP}"
336                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
337         else
338                 print_info 1 "module-init-tools: Found bincache at ${MODULE_INIT_TOOLS_BINCACHE}"
339         fi
340 }
341
342 compile_devfsd() {
343         local ARGS
344         if [ ! -f "${DEVFSD_BINCACHE}" -o ! -f "${DEVFSD_CONF_BINCACHE}" ]
345         then
346                 [ ! -f "${DEVFSD_SRCTAR}" ] && gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
347                 cd "${TEMP}"
348                 rm -rf "${DEVFSD_DIR}"
349                 tar -jxpf "${DEVFSD_SRCTAR}"
350                 [ ! -d "${DEVFSD_DIR}" ] && gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
351                 cd "${DEVFSD_DIR}"
352
353                 if [ "${USE_DIETLIBC}" -eq "1" ]
354                 then
355                         extract_dietlibc_bincache
356                         OLD_CC="${UTILS_CC}"
357                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
358                 fi
359
360                 print_info 1 "devfsd: make all"
361
362                 if [ "${USE_DIETLIBC}" -eq "1" ]
363                 then
364                         compile_generic "has_dlopen=0 has_rpcsvc=0" utils
365                 else
366                         compile_generic "LDFLAGS=-static" utils
367                 fi
368
369                 if [ "${USE_DIETLIBC}" -eq "1" ]
370                 then
371                         clean_dietlibc_bincache
372                         UTILS_CC="${OLD_CC}"
373                 fi
374
375                 print_info 1 "devfsd: copying to bincache"
376                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] && gen_die "devfsd executable does not exist after compilation of devfsd"
377                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die "could not strip devfsd"
378                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die "compression of devfsd failed"
379                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] && gen_die "could not find compressed devfsd.bz2 binary"
380                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die "could not move compressed binary to bincache"
381
382                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf" ] && gen_die "devfsd.conf does not exist after compilation of devfsd"
383                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd.conf" || gen_die "compression of devfsd.conf failed"
384                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" ] && gen_die "could not find compressed devfsd.conf.bz2 binary"
385                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" "${DEVFSD_CONF_BINCACHE}" || gen_die "could not move compressed binary to bincache"
386
387                 print_info 1 "devfsd: cleaning up"
388                 cd "${TEMP}"
389                 rm -rf "${DEVFSD_DIR}" > /dev/null
390         else
391                 print_info 1 "devfsd: Found bincache at ${DEVFSD_BINCACHE} and ${DEVFSD_CONF_BINCACHE}"
392         fi
393 }
394
395 compile_dietlibc() {
396         local BUILD_DIETLIBC
397         local ORIGTEMP
398
399         BUILD_DIETLIBC=0
400         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
401         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
402         if [ "${BUILD_DIETLIBC}" -eq "0" ]
403         then
404                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
405                 if [ "${TEMP}" != "${ORIGTEMP}" ]
406                 then
407                         print_info 1 "Dietlibc: Bincache exists, but current temp directory is different than original. Rebuilding."
408                         BUILD_DIETLIBC=1
409                 fi
410         fi
411
412         if [ "${BUILD_DIETLIBC}" -eq "1" ]
413         then
414                 [ ! -f "${DIETLIBC_SRCTAR}" ] && gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
415                 cd "${TEMP}"
416                 rm -rf "${DIETLIBC_DIR}" > /dev/null
417                 tar -jxpf ${DIETLIBC_SRCTAR} || gen_die "Could not extract dietlibc source tarball"
418                 [ ! -d "${DIETLIBC_DIR}" ] && gen_die "Dietlibc directory ${DIETLIBC_DIR} invalid"
419                 cd "${DIETLIBC_DIR}"
420                 print_info 1 "Dietlibc: make"
421                 compile_generic "prefix=${TEMP}/diet" utils
422                 print_info 1 "Dietlibc: installing"
423                 compile_generic "prefix=${TEMP}/diet install" utils
424                 print_info 1 "Dietlibc: copying to bincache"
425                 cd ${TEMP}
426                 tar -jcpf "${DIETLIBC_BINCACHE}" diet || gen_die "Could not tar up dietlibc bin"
427                 [ ! -f "${DIETLIBC_BINCACHE}" ] && gen_die "bincache not created"
428                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
429
430                 print_info 1 "Dietlibc: cleaning up"
431                 cd "${TEMP}"
432                 rm -rf "${DIETLIBC_DIR}" > /dev/null
433                 rm -rf "${TEMP}/diet" > /dev/null
434         else
435                 print_info 1 "Dietlibc: Found bincache at ${DIETLIBC_BINCACHE}"
436         fi
437 }
438