add devfsd support
[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         elif [ "${2}" = "utils" ]
122         then
123                 export_utils_args
124         fi
125
126         if [ "${DEBUGLEVEL}" -gt "1" ]
127         then
128                 # Output to stdout and debugfile
129                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${1}" 1 0 1
130                 ${MAKE} ${MAKEOPTS} ${1} 2>&1 | tee -a ${DEBUGFILE}
131                 RET=$?
132         else
133                 # Output to debugfile only
134                 print_info 2 "COMMAND: ${MAKE} ${MAKEOPTS} ${1}" 1 0 1
135                 ${MAKE} ${MAKEOPTS} ${1} >> ${DEBUGFILE} 2>&1
136                 RET=$?
137         fi
138         [ "${RET}" -ne "0" ] && gen_die "compile of failed"
139
140         if [ "${2}" = "kernel" ]
141         then
142                 unset_kernel_args
143         elif [ "${2}" = "utils" ]
144         then
145                 unset_utils_args
146         fi
147
148 }
149
150 extract_dietlibc_bincache() {
151         print_info 1 "extracting dietlibc bincache"
152         CURR_DIR=`pwd`
153         cd "${TEMP}"
154         rm -rf "${TEMP}/diet" > /dev/null
155         tar -jxpf "${DIETLIBC_BINCACHE}" || gen_die "Could not extract dietlibc bincache"
156         [ ! -d "${TEMP}/diet" ] && gen_die "${TEMP}/diet directory not found"
157         cd "${CURR_DIR}"
158 }
159
160 clean_dietlibc_bincache() {
161         print_info 1 "cleaning up dietlibc bincache"
162         CURR_DIR=`pwd`
163         cd "${TEMP}"
164         rm -rf "${TEMP}/diet" > /dev/null
165         cd "${CURR_DIR}"
166 }
167
168
169 compile_dep() {
170         # Only make dep for 2.4 kernels
171         if [ "${PAT}" -gt "4" ]
172         then
173                 print_info 1 "kernel: skipping make dep for non 2.4 kernels"
174         else
175                 print_info 1 "kernel: Making dependancies for linux ${KV}"
176                 cd ${KERNEL_DIR}
177                 compile_generic "dep" kernel
178         fi
179 }
180
181 compile_modules() {
182         print_info 1 "kernel: Starting compile of linux ${KV} modules"
183         cd ${KERNEL_DIR}
184         compile_generic "modules" kernel
185         compile_generic "modules_install" kernel
186 }
187
188 compile_kernel() {
189         [ "${KERNEL_MAKE}" = "" ] && gen_die "KERNEL_MAKE undefined. Don't know how to compile kernel for arch."
190         cd ${KERNEL_DIR}
191         print_info 1 "kernel: Starting compile of linux ${KV} ${KERNEL_MAKE}"
192         compile_generic "${KERNEL_MAKE}" kernel
193         cp "${KERNEL_BINARY}" "/boot/kernel-${KV}" || gen_die "Could not copy kernel binary to boot"
194 }
195
196 compile_busybox() {
197         if [ ! -f "${BUSYBOX_BINCACHE}" ]
198         then
199                 [ ! -f "${BUSYBOX_SRCTAR}" ] && gen_die "Could not find busybox source tarball: ${BUSYBOX_SRCTAR}"
200                 [ ! -f "${BUSYBOX_CONFIG}" ] && gen_die "Cound not find busybox config file: ${BUSYBOX_CONFIG}"
201                 cd "${TEMP}"
202                 rm -rf ${BUSYBOX_DIR} > /dev/null
203                 tar -jxpf ${BUSYBOX_SRCTAR} || gen_die "Could not extract busybox source tarball"
204                 [ ! -d "${BUSYBOX_DIR}" ] && gen_die "Busybox directory ${BUSYBOX_DIR} invalid"
205                 cp "${BUSYBOX_CONFIG}" "${BUSYBOX_DIR}/.config"
206                 cd "${BUSYBOX_DIR}"
207 # Busybox and dietlibc don't play nice right now
208 #               if [ "${USE_DIETLIBC}" -eq "1" ]
209 #               then
210 #                       extract_dietlibc_bincache
211 #                       OLD_CC="${UTILS_CC}"
212 #                       UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
213 #               fi
214                 print_info 1 "Busybox: make oldconfig"
215                 compile_generic "oldconfig" utils
216                 print_info 1 "Busybox: make all"
217                 compile_generic "all" utils
218 # Busybox and dietlibc don't play nice right now
219 #               if [ "${USE_DIETLIBC}" -eq "1" ]
220 #               then
221 #                       clean_dietlibc_bincache
222 #                       UTILS_CC="${OLD_CC}"
223 #               fi
224                 print_info 1 "Busybox: copying to bincache"
225                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox" ] && gen_die "busybox executable does not exist after compile, error"
226                 strip "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "could not strip busybox"
227                 bzip2 "${TEMP}/${BUSYBOX_DIR}/busybox" || gen_die "bzip2 compression of busybox failed"
228                 [ ! -f "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" ] && gen_die "could not find compressed busybox binary"
229                 mv "${TEMP}/${BUSYBOX_DIR}/busybox.bz2" "${BUSYBOX_BINCACHE}" || gen_die "could not copy busybox binary to arch package directory, does the directory exist?"
230
231                 print_info 1 "Busybox: cleaning up"
232                 cd "${TEMP}"
233                 rm -rf "${BUSYBOX_DIR}" > /dev/null
234         else
235                 print_info 1 "Busybox: Found bincache at ${BUSYBOX_BINCACHE}"
236         fi
237 }
238
239 compile_modutils() {
240         local ARGS
241         if [ ! -f "${MODUTILS_BINCACHE}" ]
242         then
243                 [ ! -f "${MODUTILS_SRCTAR}" ] && gen_die "Could not find modutils source tarball: ${MODUTILS_SRCTAR}"
244                 cd "${TEMP}"
245                 rm -rf "${MODUTILS_DIR}"
246                 tar -jxpf "${MODUTILS_SRCTAR}"
247                 [ ! -d "${MODUTILS_DIR}" ] && gen_die "Modutils directory ${MODUTILS_DIR} invalid"
248                 cd "${MODUTILS_DIR}"
249                 print_info 1 "modutils: configure"
250
251                 if [ "${USE_DIETLIBC}" -eq "1" ]
252                 then
253                         extract_dietlibc_bincache
254                         OLD_CC="${UTILS_CC}"
255                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
256                 fi
257
258                 export_utils_args
259                 ./configure --disable-combined --enable-insmod-static >> ${DEBUGFILE} 2>&1 || gen_die "Configure of modutils failed"
260                 unset_utils_args
261
262                 print_info 1 "modutils: make all"
263                 compile_generic "all" utils
264
265                 if [ "${USE_DIETLIBC}" -eq "1" ]
266                 then
267                         clean_dietlibc_bincache
268                         UTILS_CC="${OLD_CC}"
269                 fi
270
271                 print_info 1 "modutils: copying to bincache"
272                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" ] && gen_die "insmod.static does not exist after compilation of modutils"
273                 strip "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "could not strip insmod.static"
274                 bzip2 "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static" || gen_die "compression of insmod.static failed"
275                 [ ! -f "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
276                 mv "${TEMP}/${MODUTILS_DIR}/insmod/insmod.static.bz2" "${MODUTILS_BINCACHE}" || gen_die "could not move compress binary to bincache"
277
278                 print_info 1 "modutils: cleaning up"
279                 cd "${TEMP}"
280                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
281         else
282                 print_info 1 "modutils: Found bincache at ${MODUTILS_BINCACHE}"
283         fi
284 }
285
286 compile_module_init_tools() {
287         local ARGS
288         if [ ! -f "${MODULE_INIT_TOOLS_BINCACHE}" ]
289         then
290                 [ ! -f "${MODULE_INIT_TOOLS_SRCTAR}" ] && gen_die "Could not find module-init-tools source tarball: ${MODULE_INIT_TOOLS_SRCTAR}"
291                 cd "${TEMP}"
292                 rm -rf "${MODULE_INIT_TOOLS_DIR}"
293                 tar -jxpf "${MODULE_INIT_TOOLS_SRCTAR}"
294                 [ ! -d "${MODULE_INIT_TOOLS_DIR}" ] && gen_die "Module-init-tools directory ${MODULE_INIT_TOOLS_DIR} invalid"
295                 cd "${MODULE_INIT_TOOLS_DIR}"
296                 print_info 1 "module-init-tools: configure"
297
298                 if [ "${USE_DIETLIBC}" -eq "1" ]
299                 then
300                         extract_dietlibc_bincache
301                         OLD_CC="${UTILS_CC}"
302                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
303                 fi
304
305                 export_utils_args
306                 ./configure >> ${DEBUGFILE} 2>&1 || gen_die "Configure of module-init-tools failed"
307                 unset_utils_args
308                 print_info 1 "module-init-tools: make all"
309                 compile_generic "all" utils
310
311                 if [ "${USE_DIETLIBC}" -eq "1" ]
312                 then
313                         clean_dietlibc_bincache
314                         UTILS_CC="${OLD_CC}"
315                 fi
316
317                 print_info 1 "module-init-tools: copying to bincache"
318                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" ] && gen_die "insmod.static does not exist after compilation of module-init-tools"
319                 strip "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "could not strip insmod.static"
320                 bzip2 "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static" || gen_die "compression of insmod.static failed"
321                 [ ! -f "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" ] && gen_die "could not find compressed insmod.static.bz2 binary"
322                 mv "${TEMP}/${MODULE_INIT_TOOLS_DIR}/insmod.static.bz2" "${MODULE_INIT_TOOLS_BINCACHE}" || gen_die "could not move compressed binary to bincache"
323
324                 print_info 1 "module-init-tools: cleaning up"
325                 cd "${TEMP}"
326                 rm -rf "${MODULE_INIT_TOOLS_DIR}" > /dev/null
327         else
328                 print_info 1 "module-init-tools: Found bincache at ${MODULE_INIT_TOOLS_BINCACHE}"
329         fi
330 }
331
332 compile_devfsd() {
333         local ARGS
334         if [ ! -f "${DEVFSD_BINCACHE}" -o ! -f "${DEVFSD_CONF_BINCACHE}" ]
335         then
336                 [ ! -f "${DEVFSD_SRCTAR}" ] && gen_die "Could not find devfsd source tarball: ${DEVFSD_SRCTAR}"
337                 cd "${TEMP}"
338                 rm -rf "${DEVFSD_DIR}"
339                 tar -jxpf "${DEVFSD_SRCTAR}"
340                 [ ! -d "${DEVFSD_DIR}" ] && gen_die "Devfsd directory ${DEVFSD_DIR} invalid"
341                 cd "${DEVFSD_DIR}"
342
343                 if [ "${USE_DIETLIBC}" -eq "1" ]
344                 then
345                         extract_dietlibc_bincache
346                         OLD_CC="${UTILS_CC}"
347                         UTILS_CC="${TEMP}/diet/bin/diet ${UTILS_CC}"
348                 fi
349
350                 print_info 1 "devfsd: make all"
351
352                 if [ "${USE_DIETLIBC}" -eq "1" ]
353                 then
354                         compile_generic "has_dlopen=0 has_rpcsvc=0" utils
355                 else
356                         compile_generic "LDFLAGS=-static" utils
357                 fi
358
359                 if [ "${USE_DIETLIBC}" -eq "1" ]
360                 then
361                         clean_dietlibc_bincache
362                         UTILS_CC="${OLD_CC}"
363                 fi
364
365                 print_info 1 "devfsd: copying to bincache"
366                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd" ] && gen_die "devfsd executable does not exist after compilation of devfsd"
367                 strip "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die "could not strip devfsd"
368                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd" || gen_die "compression of devfsd failed"
369                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" ] && gen_die "could not find compressed devfsd.bz2 binary"
370                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.bz2" "${DEVFSD_BINCACHE}" || gen_die "could not move compressed binary to bincache"
371
372                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf" ] && gen_die "devfsd.conf does not exist after compilation of devfsd"
373                 bzip2 "${TEMP}/${DEVFSD_DIR}/devfsd.conf" || gen_die "compression of devfsd.conf failed"
374                 [ ! -f "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" ] && gen_die "could not find compressed devfsd.conf.bz2 binary"
375                 mv "${TEMP}/${DEVFSD_DIR}/devfsd.conf.bz2" "${DEVFSD_CONF_BINCACHE}" || gen_die "could not move compressed binary to bincache"
376
377                 print_info 1 "devfsd: cleaning up"
378                 cd "${TEMP}"
379                 rm -rf "${DEVFSD_DIR}" > /dev/null
380         else
381                 print_info 1 "devfsd: Found bincache at ${DEVFSD_BINCACHE} and ${DEVFSD_CONF_BINCACHE}"
382         fi
383 }
384
385 compile_dietlibc() {
386         local BUILD_DIETLIBC
387         local ORIGTEMP
388
389         BUILD_DIETLIBC=0
390         [ ! -f "${DIETLIBC_BINCACHE}" ] && BUILD_DIETLIBC=1
391         [ ! -f "${DIETLIBC_BINCACHE_TEMP}" ] && BUILD_DIETLIBC=1
392         if [ "${BUILD_DIETLIBC}" -eq "0" ]
393         then
394                 ORIGTEMP=`cat "${DIETLIBC_BINCACHE_TEMP}"`
395                 if [ "${TEMP}" != "${ORIGTEMP}" ]
396                 then
397                         print_info 1 "Dietlibc: Bincache exists, but current temp directory is different than original. Rebuilding."
398                         BUILD_DIETLIBC=1
399                 fi
400         fi
401
402         if [ "${BUILD_DIETLIBC}" -eq "1" ]
403         then
404                 [ ! -f "${DIETLIBC_SRCTAR}" ] && gen_die "Could not find dietlibc source tarball: ${DIETLIBC_SRCTAR}"
405                 cd "${TEMP}"
406                 rm -rf "${DIETLIBC_DIR}" > /dev/null
407                 tar -jxpf ${DIETLIBC_SRCTAR} || gen_die "Could not extract dietlibc source tarball"
408                 [ ! -d "${DIETLIBC_DIR}" ] && gen_die "Dietlibc directory ${DIETLIBC_DIR} invalid"
409                 cd "${DIETLIBC_DIR}"
410                 print_info 1 "Dietlibc: make"
411                 compile_generic "prefix=${TEMP}/diet" utils
412                 print_info 1 "Dietlibc: installing"
413                 compile_generic "prefix=${TEMP}/diet install" utils
414                 print_info 1 "Dietlibc: copying to bincache"
415                 cd ${TEMP}
416                 tar -jcpf "${DIETLIBC_BINCACHE}" diet || gen_die "Could not tar up dietlibc bin"
417                 [ ! -f "${DIETLIBC_BINCACHE}" ] && gen_die "bincache not created"
418                 echo "${TEMP}" > "${DIETLIBC_BINCACHE_TEMP}"
419
420                 print_info 1 "dietlibc: cleaning up"
421                 cd "${TEMP}"
422                 rm -rf "${DIETLIBC_DIR}" > /dev/null
423                 rm -rf "${TEMP}/diet" > /dev/null
424         else
425                 print_info 1 "Dietlibc: Found bincache at ${DIETLIBC_BINCACHE}"
426         fi
427 }
428