-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·319 lines (236 loc) · 7.21 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
#
# Configure script for CCP
#
function check_if_module_included {
for mod in $module_names; do
if [ "$mod" == "$1" ]; then
return 1
fi
done
return 0
}
list_of_arches=`ls kernel/hwdep`
module_names=""
BUILDROOT=`pwd` # get build root
echo
echo Interactive configure script
echo
#
# select the architecture
#
echo "Choose which platform you want to compile for."
while [ ${#response} == 0 ]; do # no input, use default
myp="Enter platform to compile for ["$list_of_arches"]:"
echo -n $myp
read response
if [ -z "$response" ]; then
echo "Enter platform to compile for"
fi
for f in $list_of_arches; do # check if valid input
if [ "$f" == "$response" ]; then
compile_arch=$response
break
fi
done
if [ ${#compile_arch} == 0 ]; then # not valid arch
echo configure: Unknown platform must be one of $list_of_arches
response=""
fi
done
if [ ! -e config/config-$compile_arch ]; then # check if config file exists
echo configure: Missing file config/config-$compile_arch
exit 1
fi
for f in bin/$compile_arch obj/$compile_arch mapfiles; do
if [ ! -e $f ]; then
mkdir -p $f
fi
done
echo Compiling for $compile_arch
CC_OPT_COUNT=0
optcount=0
#
# read options from config file
#
while IFS= read -r var
do
IFS='=' read -r varname varval <<< "$var" #read line from file and split at = into varname and varval
case $varname in # process
CC) # c compiler
CC=$varval
;;
ASM) # assembler
ASM=$varval
;;
LD) # linker
LD=$varval
;;
LD_OPTS) # linker options
LDOPTS=$varval
;;
CC_OPTS) # compiler options
CC_OPTS=$varval
;;
ASM_OPTS) # assembler options
ASM_OPTS=$varval
;;
SEARCH) # search path
SEARCH=$varval
;;
CC_BASE_FILES) # base files for c compiler
CC_BASE_FILES=$varval
;;
ASM_BASE_FILES) # base files for assembler
ASM_BASE_FILES=$varval
;;
CC_OPT_FILE) # optional files for c compiler
OPT_FILES[optcount]=$varval
let "optcount++"
;;
esac
done < config/config-$compile_arch
#
# Select optional features
#
count=0;
while [ "$optcount" != 0 ]; do # until all optional features done
IFS=':' read -r cc_desc cc_yes cc_no <<< "${OPT_FILES[count]}" # read line and split into cc_desc,cc_yes and cc_no variables
read -p "$cc_desc (Y/n)?" yesno # prompt user to include feature
if [ ${#yesno} == 0 ] || [ $yesno == "y" ]; then # include feature
CC_OPT_FILES="$CC_OPT_FILES $BUILDROOT/$cc_yes"
CC_OPT_OBJ_FILES="$CC_OPT_OBJ_FILES $BUILDROOT/obj/$compile_arch/`echo $(basename $cc_yes) | sed s:.c:-hwdep.o:`" # get path of object file
else
CC_OPT_FILES="$CC_OPT_FILES $BUILDROOT/$cc_no"
CC_OPT_OBJ_FILES="$CC_OPT_OBJ_FILES $BUILDROOT/obj/$compile_arch/`echo $(basename $cc_no) | sed s:.c:-hwdep.o:`"
fi
let "optcount--"
let "count++"
done
#
# choose which modules to compile
#
echo
echo "Select the modules you want to compile, enter y to compile the module into the kernel,"
echo "m to compile to external initrd module or enter n to not compile the module."
echo
#
# go through each driver
#
for f in $SEARCH;do
m=`echo $f | cut -d/ -f 1`
name=`echo $f | cut -d/ -f 2`
a=`echo $f | cut -d/ -f 3`
let CC_OPT_COUNT=0
if [ $name == "drivers" ] || [ $name == "filesystems" ] || [ $name == "binfmt" ]; then
#read driver config information
DRIVERNAME=""
DESCRIPTION=""
COMPILE_DEFAULT_OPT=""
REQUIRED=""
while IFS= read -r var # read lines from file
do
IFS='=' read -r varname varval <<< "$var" # split line to varname and varval variables
case $varname in
name) # driver name
DRIVERNAME=$varval
;;
description) # driver description
DESCRIPTION=$varval
;;
compile_opt) # Is optional feature
COMPILE_OPT=$varval
;;
requires) # Required modules
REQUIRED=$varval
;;
esac
done < $f/config
#
# prompt user
#
check_if_module_included "$DRIVERNAME"
rv=$? # need to save it so it can be compared
if [ $rv == 0 ]; then
echo $DESCRIPTION # display description
echo
printf "Include module $DRIVERNAME" # prompt user
if [ "$COMPILE_OPT" == "y" ] || [ "$COMPILE_OPT" == "Y" ]; then # prompt if module is built-in
echo -n " (Y/n)?"
elif [ "$COMPILE_OPT" == "m" ] || [ "$COMPILE_OPT" == "M" ]; then # initrd module
echo -n " (y/n/M)?"
elif [ "$COMPILE_OPT" == "n" ] || [ "$COMPILE_OPT" == "N" ]; then # not used by default
echo -n " (y/N/m)?"
fi
read response
if [ ${#response} == 0 ]; then # use default response
if [ "$COMPILE_OPT" == "y" ] || [ "$COMPILE_OPT" == "Y" ]; then # prompt if module is built-in
module_list="$module_list $BUILDROOT/$f" # add to list
module_names="$module_names $DRIVERNAME" # add to list
response="y"
elif [ "$COMPILE_OPT" == "m" ] || [ "$COMPILE_OPT" == "M" ]; then # initrd module
initrd_module_list="$initrd_module_list $BUILDROOT/$f" # add to list
initrd_obj_list="$initrd_obj_list $BUILDROOT/$f.o"
module_names="$module_names $DRIVERNAME" # add to list
response="m"
fi
else
if [ "$response" == "y" ] || [ "$response" == "Y" ] || [ "$response" == "m" ] || [ "$response" == "M" ]; then # do response
if [ "$response" == "y" ] || [ "$response" == "Y" ]; then # built-in module
module_list="$module_list $BUILDROOT/$f" # add to list
module_names="$module_names $DRIVERNAME" # add to list
fi
if [ "$response" == "m" ] || [ "$response" == "M" ]; then # initrd module
initrd_module_list="$initrd_module_list $BUILDROOT/$f" # add to list
initrd_obj_list="$initrd_obj_list $BUILDROOT/$f.o"
module_names="$module_names $DRIVERNAME" # add to list
fi
#
# add dependencies
#
if ! [ "$REQUIRED" = "" ]; then # there is a required check
check_if_module_included "$REQUIRED" # check if already included
rv=$? # need to save it so it can be compared
if [ "$rv" == "0" ]; then # not already included
echo
echo Including required dependency $REQUIRED
echo
module_list="$module_list $BUILDROOT/modules/drivers/$REQUIRED" # add to list
module_names="$module_names $REQUIRED" # add to list
fi
fi
fi
fi
fi
fi
done
#
# Generate makefiles from templates
#
echo Generating Makefiles
for f in $SEARCH;do # for each directory in search path
# check if makefile exists
if [ ! -e $f/Makefile.in ]; then
echo configure: Missing file $f/Makefile.in
exit 1
fi
echo Creating $f/Makefile
# Generate makefiles from templates
cat $f/Makefile.in | sed s:\@buildroot\@:"$BUILDROOT":g \
| sed s:\@asm\@:"$ASM":g \
| sed s:\@cc\@:"$CC":g \
| sed s:\@arch\@:$compile_arch:g \
| sed s:\@ld\@:"$LD":g \
| sed s:\@ldopts\@:"$LDOPTS":g \
| sed s:\@driver_list\@:"$module_list":g \
| sed s:\@asm_opts\@:"$ASM_OPTS":g \
| sed s:\@initrd_driver_list\@:"$initrd_module_list":g \
| sed s:\@cc_opts\@:"$CC_OPTS":g \
| sed s:\@cc_base_files\@:"$CC_BASE_FILES":g \
| sed s:\@cc_opt_obj_files\@:"$CC_OPT_OBJ_FILES":g \
| sed s:\@cc_opt_files\@:"$CC_OPT_FILES":g > $f/Makefile
if [ $? != 0 ]; then
echo configure: Error creating output file $f/Makefile
exit 1
fi
done