forked from latentPrion/zambesii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·261 lines (225 loc) · 8.1 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
#!/usr/bin/env bash
hllToolchain=''
hllCc=''
hllCxx=''
hllCxxAbi=''
hllCpp=''
assembler=''
linker=''
arTest=''
isoTest=''
isoProg=''
arch=''
chipset=''
firmware=''
toolchainTarget=''
toolchainTest=''
builddir="$(pwd)"
srcdir="$builddir/${0%'/configure'}"
echo "Builddir is \"$builddir\"; srcdir is \"$srcdir\"."
echo 'Zambesii kernel interactive build configuration script.';
echo 'Only in-tree builds are supported until autotools support is added.'; echo
echo 'What compiler toolchain will you be using for C/C++ source?
Currently supported options: gnu, llvm'
read hllToolchain
echo
if [ -z $hllToolchain ]; then echo 'Null string is invalid input.'; exit 1; fi;
if [ "$hllToolchain" != 'gnu' -a "$hllToolchain" != 'llvm' ]; then
echo "Invalid toolchain '$hllToolchain'."
exit 1
fi
echo 'Which toolchain provides the assembler you will be using?
Currently supported options: gnu.'
read assembler
echo
if [ -z $assembler ]; then echo 'Null string is invalid input.'; exit 2; fi;
if [ $assembler != 'gnu' -a "$assembler" != 'llvm' ]; then
echo "Invalid assembler toolchain '$assembler'."
exit 2
fi
echo 'Which toolchain provides the linker you will be using?
Currently supported options: gnu.'
read linker
echo
if [ -z $linker ]; then echo 'Null string is invalid input.'; exit 3; fi;
if [ $linker != 'gnu' -a "$linker" != 'llvm' ]; then
echo "Invalid toolchain '$linker'."
exit 3
fi
echo 'Which processor architecture are you building the kernel for?
Currently supported targets: x8632.'
read arch
echo
if [ -z $arch ]; then echo 'Null string is invalid input.'; exit 4; fi;
if [ $arch != 'x8632' ]; then
echo "Unsupported target arch '$arch'."
exit 4
fi
echo 'Which chipset are you building the kernel for?
Currently supported targets: ibmPc.'
read chipset
echo
if [ -z $chipset ]; then echo 'Null string is invalid input.'; exit 5; fi;
if [ $chipset != 'ibmPc' ]; then
echo "Unsupported chipset '$chipset'."
exit 5
fi
if [ $chipset == 'ibmPc' ]; then
echo 'The IBM-PC target may support either IBM-PC BIOS or (U)EFI'
echo 'firmware. What firmware does your target board have?'
echo ' Currently supported PC firmwares: ibmPcBios.'
read firmware
echo
if [ -z $firmware ]; then echo 'Null string is invalid input.'; exit 6; fi;
if [ $firmware != 'ibmPcBios' ]; then
echo "Unsupported firmware '$firmware'."
exit 6
fi
fi
echo 'Please give the target for your toolchain;
E.g.: i586-elf, x86_64-elf, armel32-eabi-elf.'
echo 'You may enter nothing for this value, though it implies the use of a '
echo 'non-cross-compiler to do the kernel build; this is not a recommended '
echo 'build setup.'
read toolchainTarget
echo
if [ -z $toolchainTarget ]; then
echo "Warning: Null input string implies use of your distribution's "
echo "native toolchain. Using a cross compiler is highly recommended."
echo
fi
if [ $hllToolchain == 'gnu' ]; then
hllCxxAbi='icxxabi'
if [ -z $toolchainTarget ]; then
hllCc='gcc'
hllCxx='g++'
hllCpp='gcc -E'
else
hllCc="$toolchainTarget-gcc"
hllCxx="$toolchainTarget-g++"
hllCpp="$toolchainTarget-gcc -E"
fi
fi
if [ $hllToolchain == 'llvm' ]; then
hllCxxAbi='icxxabi'
if [ -z $toolchainTarget ]; then
hllCc='clang -###'
hllCxx='clang++ -###'
hllCpp='clang -E -###'
else
# hllCc="clang -ccc-host-triple $toolchainTarget"
# hllCxx="clang++ -ccc-host-triple $toolchainTarget"
# hllCpp="clang -ccc-host-triple $toolchainTarget -E"
hllCc="clang -target $toolchainTarget"
hllCxx="clang++ -target $toolchainTarget"
hllCpp="clang -target $toolchainTarget -E"
fi
if [ "$arch" == "x8632" ]; then
hllCc="$hllCc -m32"
hllCxx="$hllCxx -m32"
fi
fi
if [ $assembler == 'gnu' ]; then
if [ -z $toolchainTarget ]; then assembler='as'; else assembler="$toolchainTarget-as"; fi
fi
if [ $assembler == 'llvm' ]; then
if [ -z $toolchainTarget ]; then
assembler='llvm-as-3.0'; else assembler="llvm-as-3.0 -ccc-host-triple $toolchainTarget";
fi
fi
if [ $linker == 'gnu' ]; then
if [ -z $toolchainTarget ]; then linker='ld'; else linker="$toolchainTarget-ld"; fi
fi
if [ $linker == 'llvm' ]; then
if [ -z $toolchainTarget ]; then
linker='llvm-ld-3.0'; else linker="llvm-ld-3.0 -ccc-host-triple $toolchainTarget";
fi
fi
# We pass a non-existent file as an argument to ensure that tools that read from
# stdin when no file arguments are passed will error and exit instead of
# hanging waiting on stdin, and hanging our script along with themselves.
rm -f garbagephile
# Check to make sure that the input toolchain exists.
echo 'Checking to ensure that tools are installed.'
$hllCc garbagephile >/dev/null 2>&1
if [ $? == 127 ]; then echo "Build toolchain C compiler $hllCc does not exist."; exit 7; fi
$hllCxx garbagephile >/dev/null 2>&1
if [ $? == 127 ]; then echo "Build toolchain C++ compiler $hllCxx does not exist."; exit 7; fi
$hllCpp garbagephile >/dev/null 2>&1
if [ $? == 127 ]; then echo "Build toolchain C preprocessor $hllCpp does not exist."; exit 7; fi
$assembler garbagephile >/dev/null 2>&1
if [ $? == 127 ]; then echo "Build toolchain assembler $assembler does not exist."; exit 7; fi
$linker garbagephile >/dev/null 2>&1
if [ $? == 127 ]; then echo "Build toolchain linker $linker does not exist."; exit 7; fi
# Check to see if a GNU compatible AR is available.
ar V >/dev/null 2>&1
arTest=$?
if [ $arTest != 0 ]; then
echo "System \'ar\' is not GNU AR compatible.";
exit 4
fi
#Check for mkisofs or genisoimage
genisoimage >/dev/null 2>&1
isoTest=$?
if [ $isoTest == 127 ]; then
mkisofs >/dev/null 2>&1
isoTest=$?
if [ $isoTest == 127 ]; then
echo -n "Package genisoimage or mkisofs is required to "
echo "successfully build the kernel."
exit 5
fi
isoProg='mkisofs'
else
isoProg='genisoimage'
fi
# TODO: Do a check for a 'make' utility.
# Now generate the Makefile.vars file.
# This is really nothing more than a file written in Makefile syntax that
# defines a series of variables for use in make. The variables encode the
# input the user gave above.
echo "Generating 'Make' environment."
echo "export CPP=$hllCpp" >Makefile.vars
echo "export CC=$hllCc" >>Makefile.vars
echo "export CXX=$hllCxx" >>Makefile.vars
echo "export ZCXXABI=$hllCxxAbi" >>Makefile.vars
echo "export AS=$assembler" >>Makefile.vars
echo "export LD=$linker" >>Makefile.vars
echo "export ISOPROG=$isoProg" >>Makefile.vars
echo "export CPPFLAGS=-I\"$srcdir/include\" -I\"$srcdir/core/include\" -ffreestanding" >>Makefile.vars
echo "export CFLAGS=-O3 -Wstrict-overflow=5 -Wall -Wextra -pedantic -std=c99 -fno-omit-frame-pointer" >>Makefile.vars
echo "export CXXFLAGS=-O3 -Wstrict-overflow=5 -Wall -Wextra -pedantic -std=c++98 -fno-omit-frame-pointer -fno-exceptions -fno-rtti" >>Makefile.vars
echo "export ASFLAGS=" >>Makefile.vars
# echo "export LDFLAGS=-L\"$builddir/core/__kthreads/$arch\" -nodefaultlibs" >>Makefile.vars
echo "export LDFLAGS=-nodefaultlibs" >>Makefile.vars
echo "export ARFLAGS=" >>Makefile.vars
echo "" >>Makefile.vars
echo "export ZARCH=$arch" >>Makefile.vars
echo "export ZCHIPSET=$chipset" >>Makefile.vars
echo "export ZFIRMWARE=$firmware" >>Makefile.vars
echo "" >>Makefile.vars
echo "export BUILDDIR=$builddir" >>Makefile.vars
echo "export SRCDIR=$srcdir" >>Makefile.vars
echo "" >>Makefile.vars
# Generate the config.h C header.
echo "Generating config.h."
echo "#ifndef _CONFIG_H" >include/config.h
echo " #define _CONFIG_H" >>include/config.h;
echo "" >>include/config.h
echo "#define __ZAMBESII_KERNEL_SOURCE__" >>include/config.h
if [ $arch == 'x8632' ]; then echo "#define CONFIG_ARCH_x86_32" >>include/config.h; fi
if [ $chipset == 'ibmPc' ]; then echo "#define CONFIG_CHIPSET_IBM_PC" >>include/config.h; fi
if [ $firmware == 'ibmPcBios' ]; then echo "#define CONFIG_FIRMWARE_IBM_PC_BIOS" >>include/config.h; fi
echo "#define CONFIG_DTRIB_CISTERNN" >>include/config.h
echo "#define CONFIG_DEBUG_LOCKS" >>include/config.h
echo "" >>include/config.h
echo "#endif" >>include/config.h
echo "" >>include/config.h
echo "Copying Makefiles."
cp -f "$srcdir/Makefile.in" "$builddir/Makefile"
cp -f "$srcdir/core/Makefile.in" "$builddir/core/Makefile"
echo "Generating LD search dir include."
echo "SEARCH_DIR(\"$builddir/core/__kthreads/$arch\")" >ldSearchDirs.ld
echo "Extracting GRUB ISO structure."
tar -xzf scripts/iso.tar.gz
mkdir -p iso/zambesii