apply patch from John R. Graham <john_r_graham@mindspring.com> for bug 201482
[genkernel.git] / gen_determineargs.sh
1 #!/bin/bash
2
3 get_KV() {
4         if [ "${CMD_NO_KERNEL_SOURCES}" = '1' -a -e "${CMD_KERNCACHE}" ]
5         then
6                 /bin/tar -xj -C ${TEMP} -f ${CMD_KERNCACHE} kerncache.config 
7                 if [ -e ${TEMP}/kerncache.config ]
8                 then
9                         KERN_24=0
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                         if [ "${PAT}" -gt '4' -a "${VER}" -ge '2' ]
15                         then
16                                 LOV=`grep ^CONFIG_LOCALVERSION\= ${TEMP}/kerncache.config | sed -e "s/CONFIG_LOCALVERSION=\"\(.*\)\"/\1/"`
17                                 KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
18                         else
19                                 KERN_24=1
20                                 KV=${VER}.${PAT}.${SUB}${EXV}
21                         fi
22
23                 else
24                         gen_die "Could not find kerncache.config in the kernel cache! Exiting."
25                 fi
26
27         else
28                 # Configure the kernel
29                 # If BUILD_KERNEL=0 then assume --no-clean, menuconfig is cleared
30
31                 VER=`grep ^VERSION\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
32                 PAT=`grep ^PATCHLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
33                 SUB=`grep ^SUBLEVEL\ \= ${KERNEL_DIR}/Makefile | awk '{ print $3 };'`
34                 EXV=`grep ^EXTRAVERSION\ \= ${KERNEL_DIR}/Makefile | sed -e "s/EXTRAVERSION =//" -e "s/ //g" -e 's/\$([a-z]*)//gi'`
35                 if [ "${PAT}" -gt '4' -a "${VER}" -ge '2' -a -e ${KERNEL_DIR}/.config ]
36                 then
37                         KERN_24=0
38                         cd ${KERNEL_DIR}
39                         #compile_generic prepare kernel > /dev/null 2>&1
40                         cd - > /dev/null 2>&1
41                         [ -f "${KERNEL_DIR}/include/linux/version.h" ] && \
42                                 VERSION_SOURCE="${KERNEL_DIR}/include/linux/version.h"
43                         [ -f "${KERNEL_DIR}/include/linux/utsrelease.h" ] && \
44                                 VERSION_SOURCE="${KERNEL_DIR}/include/linux/utsrelease.h"
45                         # Handle new-style releases where version.h doesn't have UTS_RELEASE
46                         if [ -f ${KERNEL_DIR}/include/config/kernel.release ]
47                         then
48                                 UTS_RELEASE=`cat ${KERNEL_DIR}/include/config/kernel.release`
49                                 LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"`
50                                 KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
51                         elif [ -n "${VERSION_SOURCE}" ]
52                         then
53                                 UTS_RELEASE=`grep UTS_RELEASE ${VERSION_SOURCE} | sed -e 's/#define UTS_RELEASE "\(.*\)"/\1/'`
54                                 LOV=`echo ${UTS_RELEASE}|sed -e "s/${VER}.${PAT}.${SUB}${EXV}//"`
55                                 KV=${VER}.${PAT}.${SUB}${EXV}${LOV}
56                         else
57                                 LCV=`grep ^CONFIG_LOCALVERSION= ${KERNEL_DIR}/.config | sed -r -e "s/.*=\"(.*)\"/\1/"`
58                                 KV=${VER}.${PAT}.${SUB}${EXV}${LCV}
59                         fi
60                 else
61                         KERN_24=1
62                         KV=${VER}.${PAT}.${SUB}${EXV}
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 KERNCACHE            CMD_KERNCACHE
76         set_config_with_override 2 KNAME                CMD_KERNNAME             "genkernel"
77
78         set_config_with_override 2 MAKEOPTS             CMD_MAKEOPTS             "$DEFAULT_MAKEOPTS"
79         set_config_with_override 2 KERNEL_MAKE          CMD_KERNEL_MAKE          "$DEFAULT_KERNEL_MAKE"
80         set_config_with_override 2 UTILS_MAKE           CMD_UTILS_MAKE           "$DEFAULT_UTILS_MAKE"
81         set_config_with_override 2 KERNEL_CC            CMD_KERNEL_CC            "$DEFAULT_KERNEL_CC"
82         set_config_with_override 2 KERNEL_LD            CMD_KERNEL_LD            "$DEFAULT_KERNEL_LD"
83         set_config_with_override 2 KERNEL_AS            CMD_KERNEL_AS            "$DEFAULT_KERNEL_AS"
84         set_config_with_override 2 UTILS_CC             CMD_UTILS_CC             "$DEFAULT_UTILS_CC"
85         set_config_with_override 2 UTILS_LD             CMD_UTILS_LD             "$DEFAULT_UTILS_LD"
86         set_config_with_override 2 UTILS_AS             CMD_UTILS_AS             "$DEFAULT_UTILS_AS"
87
88         set_config_with_override 2 KERNEL_CROSS_COMPILE CMD_KERNEL_CROSS_COMPILE
89         set_config_with_override 2 UTILS_CROSS_COMPILE  CMD_UTILS_CROSS_COMPILE
90         set_config_with_override 2 BOOTDIR              CMD_BOOTDIR              "/boot"
91
92         set_config_with_override 1 SPLASH               CMD_SPLASH
93         set_config_with_override 1 POSTCLEAR            CMD_POSTCLEAR
94         set_config_with_override 1 MRPROPER             CMD_MRPROPER
95         set_config_with_override 1 MENUCONFIG           CMD_MENUCONFIG
96         set_config_with_override 1 CLEAN                CMD_CLEAN
97
98         set_config_with_override 2 MINKERNPACKAGE       CMD_MINKERNPACKAGE
99         set_config_with_override 2 MODULESPACKAGE       CMD_MODULESPACKAGE
100         set_config_with_override 2 KERNCACHE            CMD_KERNCACHE
101         set_config_with_override 1 NOINITRDMODULES      CMD_NOINITRDMODULES
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 BUILD_INITRAMFS      CMD_INITRAMFS
106         set_config_with_override 1 SAVE_CONFIG          CMD_SAVE_CONFIG
107         set_config_with_override 1 SYMLINK              CMD_SYMLINK
108         set_config_with_override 2 INSTALL_MOD_PATH     CMD_INSTALL_MOD_PATH
109         set_config_with_override 1 OLDCONFIG            CMD_OLDCONFIG
110         set_config_with_override 1 LVM                  CMD_LVM
111         set_config_with_override 1 EVMS                 CMD_EVMS
112         set_config_with_override 1 UNIONFS              CMD_UNIONFS
113         set_config_with_override 1 DMRAID               CMD_DMRAID
114         set_config_with_override 1 BUSYBOX              CMD_BUSYBOX              "yes"
115         set_config_with_override 1 DEVFS                CMD_UNDEFINED_CMD        "no"
116         
117         set_config_with_override 1 DISKLABEL            CMD_DISKLABEL
118         set_config_with_override 1 LUKS                 CMD_LUKS
119         set_config_with_override 1 MDADM                CMD_MDADM
120
121                 BOOTDIR=`arch_replace "${BOOTDIR}"`
122                 BOOTDIR=${BOOTDIR%/}    # Remove any trailing slash
123
124         CACHE_DIR=`arch_replace "${CACHE_DIR}"`
125         BUSYBOX_BINCACHE=`cache_replace "${BUSYBOX_BINCACHE}"`
126         DEVFSD_BINCACHE=`cache_replace "${DEVFSD_BINCACHE}"`
127         DEVFSD_CONF_BINCACHE=`cache_replace "${DEVFSD_CONF_BINCACHE}"`
128         DEVICE_MAPPER_BINCACHE=`cache_replace "${DEVICE_MAPPER_BINCACHE}"`
129         LVM_BINCACHE=`cache_replace "${LVM_BINCACHE}"`
130         DMRAID_BINCACHE=`cache_replace "${DMRAID_BINCACHE}"`
131         UNIONFS_BINCACHE=`cache_replace "${UNIONFS_BINCACHE}"`
132         UNIONFS_MODULES_BINCACHE=`cache_replace "${UNIONFS_MODULES_BINCACHE}"`
133         BLKID_BINCACHE=`cache_replace "${BLKID_BINCACHE}"`
134   
135         DEFAULT_KERNEL_CONFIG=`arch_replace "${DEFAULT_KERNEL_CONFIG}"`
136         BUSYBOX_CONFIG=`arch_replace "${BUSYBOX_CONFIG}"`
137         BUSYBOX_BINCACHE=`arch_replace "${BUSYBOX_BINCACHE}"`
138         DEVICE_MAPPER_BINCACHE=`arch_replace "${DEVICE_MAPPER_BINCACHE}"`
139         LVM_BINCACHE=`arch_replace "${LVM_BINCACHE}"`
140         DMRAID_BINCACHE=`arch_replace "${DMRAID_BINCACHE}"`
141         UNIONFS_BINCACHE=`arch_replace "${UNIONFS_BINCACHE}"`
142         UNIONFS_MODULES_BINCACHE=`arch_replace "${UNIONFS_MODULES_BINCACHE}"`
143         BLKID_BINCACHE=`arch_replace "${BLKID_BINCACHE}"`
144         
145
146         if [ "${CMD_BOOTLOADER}" != '' ]
147         then
148                 BOOTLOADER="${CMD_BOOTLOADER}"
149
150                 if [ "${CMD_BOOTLOADER}" != "${CMD_BOOTLOADER/:/}" ]
151         then
152                         BOOTFS=`echo "${CMD_BOOTLOADER}" | cut -f2- -d:`
153                         BOOTLOADER=`echo "${CMD_BOOTLOADER}" | cut -f1 -d:`
154         fi
155         fi
156
157         if [ "${NO_KERNEL_SOURCES}" != "1" ]
158         then
159                 if [ ! -d ${KERNEL_DIR} ]
160         then
161                         gen_die "kernel source directory \"${KERNEL_DIR}\" was not found!"
162         fi
163         fi
164
165         if [ -z "${KERNCACHE}" ]
166         then
167                 if [ "${KERNEL_DIR}" = '' -a "${NO_KERNEL_SOURCES}" != "1" ]
168         then
169                         gen_die 'No kernel source directory!'
170         fi
171                 if [ ! -e "${KERNEL_DIR}" -a "${NO_KERNEL_SOURCES}" != "1" ]
172         then
173                         gen_die 'No kernel source directory!'
174         fi
175         else
176                 if [ "${KERNEL_DIR}" = '' ]
177                 then
178                         gen_die 'Kernel Cache specified but no kernel tree to verify against!'
179         fi
180         fi
181
182         # Special case:  If --no-clean is specified on the command line, 
183         # imply --no-mrproper.
184         if [ "${CMD_CLEAN}" != '' ]
185         then
186                 if ! isTrue ${CLEAN}
187         then
188                         MRPROPER=0
189         fi
190         fi
191         
192         if [ -n "${MINKERNPACKAGE}" ]
193         then
194                 mkdir -p `dirname ${MINKERNPACKAGE}`
195         fi
196         
197         if [ -n "${MODULESPACKAGE}" ]
198         then
199                 mkdir -p `dirname ${MODULESPACKAGE}`
200         fi
201
202         if [ -n "${KERNCACHE}" ]
203         then
204                 mkdir -p `dirname ${KERNCACHE}`
205         fi
206         
207         get_KV
208         UNIONFS_MODULES_BINCACHE=`kv_replace "${UNIONFS_MODULES_BINCACHE}"`
209 }