Handle missing kernel Makefile better
[genkernel.git] / gen_determineargs.sh
1 #!/bin/bash
2 # $Id$
3
4 get_KV() {
5         if [ "${NO_KERNEL_SOURCES}" = '1' -a -e "${KERNCACHE}" ]
6         then
7                 /bin/tar -xj -C ${TEMP} -f ${KERNCACHE} kerncache.config 
8                 if [ -e ${TEMP}/kerncache.config ]
9                 then
10                         VER=`grep ^VERSION\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'`
11                         PAT=`grep ^PATCHLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'`
12                         SUB=`grep ^SUBLEVEL\ \= ${TEMP}/kerncache.config | awk '{ print $3 };'`
13                         EXV=`grep ^EXTRAVERSION\ \= ${TEMP}/kerncache.config | sed -e "s/EXTRAVERSION =//" -e "s/ //g"`
14                         LOV=`grep ^CONFIG_LOCALVERSION\= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION=\"\(.*\)\"/\1/"`
15                         KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
16                 else
17                         gen_die "Could not find kerncache.config in the kernel cache! Exiting."
18                 fi
19         else
20                 # Configure the kernel
21                 # If BUILD_KERNEL=0 then assume --no-clean, menuconfig is cleared
22
23                 if [ ! -f "${KERNEL_DIR}"/Makefile ]
24                 then
25                         gen_die "Kernel Makefile (${KERNEL_DIR}/Makefile) missing.  Maybe re-install the kernel sources."
26                 fi
27
28                 VER=`grep ^VERSION\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
29                 PAT=`grep ^PATCHLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
30                 SUB=`grep ^SUBLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
31                 EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'`
32
33                 if [ -z "${SUB}" ]; 
34                 then
35                         # Handle O= build directories
36                         KERNEL_SOURCE_DIR=`grep ^MAKEARGS\ \:\=  ${KERNEL_DIR}/Makefile | awk '{ print $4 };'`
37                         [ -z "${KERNEL_SOURCE_DIR}" ] && gen_die "Deriving \${KERNEL_SOURCE_DIR} failed"
38                         SUB=`grep ^SUBLEVEL\ \= ${KERNEL_SOURCE_DIR}/Makefile | awk '{ print $3 };'`
39                         EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_SOURCE_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'`
40                 fi
41
42                 cd ${KERNEL_DIR}
43                 #compile_generic prepare kernel > /dev/null 2>&1
44                 cd - > /dev/null 2>&1
45                 [ -f "${KERNEL_DIR}/include/linux/version.h" ] && \
46                         VERSION_SOURCE="${KERNEL_DIR}/include/linux/version.h"
47                 [ -f "${KERNEL_DIR}/include/linux/utsrelease.h" ] && \
48                         VERSION_SOURCE="${KERNEL_DIR}/include/linux/utsrelease.h"
49                 # Handle new-style releases where version.h doesn't have UTS_RELEASE
50                 if [ -f ${KERNEL_DIR}/include/config/kernel.release ]
51                 then
52                         UTS_RELEASE=`cat ${KERNEL_DIR}/include/config/kernel.release`
53                         LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"`
54                         KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
55                 elif [ -n "${VERSION_SOURCE}" ]
56                 then
57                         UTS_RELEASE=`grep UTS_RELEASE ${VERSION_SOURCE} | sed -e 's/#define UTS_RELEASE "\(.*\)"/\1/'`
58                         LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"`
59                         KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
60                 else
61                         LCV=`grep ^CONFIG_LOCALVERSION= ${KERNEL_DIR}/.config | sed -r -e "s/.*=\"(.*)\"/\1/"`
62                         KV=${VER}.${PAT}.${SUB}${EXV}${LCV}
63                 fi
64         fi
65 }
66
67 determine_real_args() {
68         print_info 4 "Resolving config file, command line, and arch default settings."
69
70         #                          Config File          Command Line             Arch Default
71         #                          -----------          ------------             ------------
72         set_config_with_override 2 DEBUGFILE            CMD_DEBUGFILE
73         set_config_with_override 2 KERNEL_DIR           CMD_KERNEL_DIR           "${DEFAULT_KERNEL_SOURCE}"
74         set_config_with_override 1 NO_KERNEL_SOURCES    CMD_NO_KERNEL_SOURCES
75         set_config_with_override 2 KNAME                CMD_KERNNAME             "genkernel"
76
77         set_config_with_override 2 MAKEOPTS             CMD_MAKEOPTS             "$DEFAULT_MAKEOPTS"
78         set_config_with_override 2 KERNEL_MAKE          CMD_KERNEL_MAKE          "$DEFAULT_KERNEL_MAKE"
79         set_config_with_override 2 UTILS_MAKE           CMD_UTILS_MAKE           "$DEFAULT_UTILS_MAKE"
80         set_config_with_override 2 KERNEL_CC            CMD_KERNEL_CC            "$DEFAULT_KERNEL_CC"
81         set_config_with_override 2 KERNEL_LD            CMD_KERNEL_LD            "$DEFAULT_KERNEL_LD"
82         set_config_with_override 2 KERNEL_AS            CMD_KERNEL_AS            "$DEFAULT_KERNEL_AS"
83         set_config_with_override 2 UTILS_CC             CMD_UTILS_CC             "$DEFAULT_UTILS_CC"
84         set_config_with_override 2 UTILS_LD             CMD_UTILS_LD             "$DEFAULT_UTILS_LD"
85         set_config_with_override 2 UTILS_AS             CMD_UTILS_AS             "$DEFAULT_UTILS_AS"
86
87         set_config_with_override 2 KERNEL_CROSS_COMPILE CMD_KERNEL_CROSS_COMPILE
88         set_config_with_override 2 UTILS_CROSS_COMPILE  CMD_UTILS_CROSS_COMPILE
89         set_config_with_override 2 BOOTDIR              CMD_BOOTDIR              "/boot"
90
91         set_config_with_override 1 SPLASH               CMD_SPLASH
92         set_config_with_override 1 POSTCLEAR            CMD_POSTCLEAR
93         set_config_with_override 1 MRPROPER             CMD_MRPROPER
94         set_config_with_override 1 MENUCONFIG           CMD_MENUCONFIG
95         set_config_with_override 1 CLEAN                CMD_CLEAN
96
97         set_config_with_override 2 MINKERNPACKAGE       CMD_MINKERNPACKAGE
98         set_config_with_override 2 MODULESPACKAGE       CMD_MODULESPACKAGE
99         set_config_with_override 2 KERNCACHE            CMD_KERNCACHE
100         set_config_with_override 1 NORAMDISKMODULES     CMD_NORAMDISKMODULES
101         set_config_with_override 1 ALLRAMDISKMODULES    CMD_ALLRAMDISKMODULES
102         set_config_with_override 2 INITRAMFS_OVERLAY    CMD_INITRAMFS_OVERLAY
103         set_config_with_override 1 MOUNTBOOT            CMD_MOUNTBOOT
104         set_config_with_override 1 BUILD_STATIC         CMD_STATIC
105         set_config_with_override 1 SAVE_CONFIG          CMD_SAVE_CONFIG
106         set_config_with_override 1 SYMLINK              CMD_SYMLINK
107         set_config_with_override 2 INSTALL_MOD_PATH     CMD_INSTALL_MOD_PATH
108         set_config_with_override 1 OLDCONFIG            CMD_OLDCONFIG
109         set_config_with_override 1 LVM                  CMD_LVM
110         set_config_with_override 1 EVMS                 CMD_EVMS
111         set_config_with_override 1 DMRAID               CMD_DMRAID
112         set_config_with_override 1 ISCSI                CMD_ISCSI
113         set_config_with_override 1 BUSYBOX              CMD_BUSYBOX              "yes"
114         set_config_with_override 1 UNIONFS                              CMD_UNIONFS
115         set_config_with_override 1 NETBOOT                              CMD_NETBOOT
116         set_config_with_override 2 REAL_ROOT                    CMD_REAL_ROOT
117         set_config_with_override 1 DISKLABEL            CMD_DISKLABEL
118         set_config_with_override 1 LUKS                 CMD_LUKS
119         set_config_with_override 1 GPG                  CMD_GPG
120         set_config_with_override 1 MDADM                CMD_MDADM
121         set_config_with_override 1 MULTIPATH            CMD_MULTIPATH
122         set_config_with_override 1 FIRMWARE             CMD_FIRMWARE
123         set_config_with_override 2 FIRMWARE_DIR         CMD_FIRMWARE_DIR         "/lib/firmware"
124         set_config_with_override 2 FIRMWARE_FILES       CMD_FIRMWARE_FILES
125         set_config_with_override 1 INTEGRATED_INITRAMFS CMD_INTEGRATED_INITRAMFS
126         set_config_with_override 1 GENZIMAGE            CMD_GENZIMAGE
127         set_config_with_override 1 KEYMAP               CMD_KEYMAP               "yes"
128         set_config_with_override 1 DOKEYMAPAUTO         CMD_DOKEYMAPAUTO
129         set_config_with_override 2 BUSYBOX_CONFIG       CMD_BUSYBOX_CONFIG
130
131         BOOTDIR=`arch_replace "${BOOTDIR}"`
132         BOOTDIR=${BOOTDIR%/}    # Remove any trailing slash
133
134         CACHE_DIR=`arch_replace "${CACHE_DIR}"`
135         BUSYBOX_BINCACHE=`cache_replace "${BUSYBOX_BINCACHE}"`
136         DEVICE_MAPPER_BINCACHE=`cache_replace "${DEVICE_MAPPER_BINCACHE}"`
137         LVM_BINCACHE=`cache_replace "${LVM_BINCACHE}"`
138         DMRAID_BINCACHE=`cache_replace "${DMRAID_BINCACHE}"`
139         ISCSI_BINCACHE=`cache_replace "${ISCSI_BINCACHE}"`
140         BLKID_BINCACHE=`cache_replace "${BLKID_BINCACHE}"`
141         FUSE_BINCACHE=`cache_replace "${FUSE_BINCACHE}"`
142         UNIONFS_FUSE_BINCACHE=`cache_replace "${UNIONFS_FUSE_BINCACHE}"`
143         GPG_BINCACHE=`cache_replace "${GPG_BINCACHE}"`
144   
145         DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"`
146         BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"`
147         BUSYBOX_BINCACHE=`arch_replace "${BUSYBOX_BINCACHE}"`
148         DEVICE_MAPPER_BINCACHE=`arch_replace "${DEVICE_MAPPER_BINCACHE}"`
149         LVM_BINCACHE=`arch_replace "${LVM_BINCACHE}"`
150         DMRAID_BINCACHE=`arch_replace "${DMRAID_BINCACHE}"`
151         ISCSI_BINCACHE=`arch_replace "${ISCSI_BINCACHE}"`
152         BLKID_BINCACHE=`arch_replace "${BLKID_BINCACHE}"`
153         FUSE_BINCACHE=`arch_replace "${FUSE_BINCACHE}"`
154         UNIONFS_FUSE_BINCACHE=`arch_replace "${UNIONFS_FUSE_BINCACHE}"`
155         GPG_BINCACHE=`arch_replace "${GPG_BINCACHE}"`
156
157         if [ -n "${CMD_BOOTLOADER}" ]
158         then
159                 BOOTLOADER="${CMD_BOOTLOADER}"
160                 if [ "${CMD_BOOTLOADER}" != "${CMD_BOOTLOADER/:/}" ]
161                 then
162                         BOOTFS=`echo "${CMD_BOOTLOADER}" | cut -f2- -d:`
163                         BOOTLOADER=`echo "${CMD_BOOTLOADER}" | cut -f1 -d:`
164                 fi
165         fi
166         
167         if [ "${NO_KERNEL_SOURCES}" != "1" ]
168         then
169                 if [ ! -d ${KERNEL_DIR} ]
170                 then
171                         gen_die "kernel source directory \"${KERNEL_DIR}\" was not found!"
172                 fi
173         fi
174
175         if [ -z "${KERNCACHE}" ]
176         then
177                 if [ "${KERNEL_DIR}" = '' -a "${NO_KERNEL_SOURCES}" != "1" ]
178                 then
179                         gen_die 'No kernel source directory!'
180                 fi
181                 if [ ! -e "${KERNEL_DIR}" -a "${NO_KERNEL_SOURCES}" != "1" ]
182                 then
183                         gen_die 'No kernel source directory!'
184                 fi
185         else
186                 if [ "${KERNEL_DIR}" = '' ]
187                 then
188                         gen_die 'Kernel Cache specified but no kernel tree to verify against!'
189                 fi
190         fi
191
192         # Special case:  If --no-clean is specified on the command line, 
193         # imply --no-mrproper.
194         if [ "${CMD_CLEAN}" != '' ]
195         then
196                 if ! isTrue ${CLEAN}
197                 then
198                         MRPROPER=0
199                 fi
200         fi
201         
202         if [ -n "${MINKERNPACKAGE}" ]
203         then
204                 mkdir -p `dirname ${MINKERNPACKAGE}`
205         fi
206         
207         if [ -n "${MODULESPACKAGE}" ]
208         then
209                 mkdir -p `dirname ${MODULESPACKAGE}`
210         fi
211
212         if [ -n "${KERNCACHE}" ]
213         then
214                 mkdir -p `dirname ${KERNCACHE}`
215         fi
216
217         if ! isTrue "${BUILD_RAMDISK}"
218         then
219                 INTEGRATED_INITRAMFS=0
220         fi
221         
222         get_KV
223 }