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