-
Notifications
You must be signed in to change notification settings - Fork 6
/
configure
387 lines (308 loc) · 10.2 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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/bin/sh
#
# Configure script for OS/161 tree.
# This generates the file "defs.mk" at the top level of the tree.
#
# Usage: ./configure [options]
# where you can get a list of the options by doing ./configure --help.
#
# Must be run with the top of the OS/161 tree as its current directory.
#
# Note: while this superficially acts like a GNU Autoconf configure
# script, it was not generated by autoconf. Scripts generated by
# autoconf are much harder to read. :-)
#
# gcc warnings to use.
# (If you change this, rerun the script to propagate it to defs.mk.)
# -Werror will be added if the --werror argument is given.
WARNINGS='-Wall -W -Wwrite-strings'
# Target hardware platform.
PLATFORM='mips'
# Default optimize/debug flag: optimize.
OPTFLAGS='-O2'
# Default location of the root of the installed system.
# Note that we quote it such that the reference to the home directory
# is a make variable, not a shell variable. This means it gets expanded
# when make runs rather than when this script runs.
OSTREE='$(HOME)/cs161/root'
# Default toolchain name.
TOOLPREFIX="cs161-"
##################################################
#
# Check to make sure we're in the right place.
if [ ! -d kern/userprog ]; then
echo 'Please run configure from the top of the OS/161 tree.'
exit 1
fi
#
# Process the command-line options.
while [ "x$1" != x ]; do
case "$1" in
--debug) OPTFLAGS='-g';;
--werror|--Werror) WARNINGS="$WARNINGS -Werror";;
--ostree=*) OSTREE=`echo $1 | sed 's,^[^=]*=,,'`;;
--toolprefix=*) TOOLPREFIX=`echo $1 | sed 's,^[^=]*=,,'`;;
--help|*)
more <<EOF
Usage: ./configure [options]
where the options are:
--help Print this message.
--debug Compile the user-level programs with debug info.
This is disabled by default because there's no
support for userlevel source debugging in OS/161.
(Note: debug info in the kernel is controlled by
the kernel config file.)
--werror Compile with -Werror, so that compiler warnings
are turned into errors and cause the build to
stop. Recommended, because on long builds you
don't always notice warnings as they go by, but
disabled by default.
--ostree=PATH Install the compiled system in a directory tree
rooted at PATH. Default is \$HOME/cs161/root.
--toolprefix=NAME Set up to use compiler and tools named with a
prefix of NAME. The default is "cs161-", so the
tools used are called cs161-gcc, cs161-ld, etc.
The directory with these tools should be on your
shell's search path.
EOF
exit
;;
esac
shift
done
####################
# Assume gcc on the host. It would be nice to probe this, but for now
# it doesn't seem worthwhile.
HOST_CC=gcc
####################
# Figure out if the host system needs us to use ranlib or not. Assume
# that if it exists, we should use it. This is a bad assumption on
# BSD/OS 2.1, but hopefully that won't come up, as BSD/OS 2.1 is quite
# out of date now.
echo -n 'Checking for ranlib... '
STUFF=`(ranlib) 2>&1`
if echo $STUFF | grep 'not found' >/dev/null 2>&1; then
echo 'no'
HOST_RANLIB=true
else
echo 'yes'
HOST_RANLIB=ranlib
fi
####################
# Check if the host system supports 4.4BSD <err.h>.
echo -n "Checking for <err.h>... "
cat > __conftest.c <<EOF
#include <err.h>
int
main()
{
err(0, "works");
return 1;
}
EOF
OK=0
if $HOST_CC __conftest.c -o __conftest >/dev/null 2>&1; then
if ./__conftest >/dev/null 2>&1; then
OK=1
fi
fi
rm -f __conf*
if [ $OK = 1 ]; then
echo 'yes'
else
echo 'no'
COMPAT_CFLAGS="${COMPATCFLAGS} -DNEED_ERR"
COMPAT_TARGETS="${HOSTTARGETS} install-errh"
fi
####################
# Now generate defs.mk.
echo 'Generating defs.mk.'
(
# First, put an explanatory comment at the top.
cat <<EOF
# This file was generated by configure. Edits will disappear if you rerun
# configure. If you find that you need to edit this file to make things
# work, let the course staff know and we'll try to fix the configure script.
#
#
# The purpose of this file is to hold all the makefile definitions
# needed to adjust the OS/161 build process to any particular
# environment. If I've done it right, all you need to do is rerun the
# configure script and make clean if you decide to work from Linux or
# BSD instead of Digital Unix. If I've done it mostly right, you may
# need to edit this file but you still hopefully won't need to edit
# any of the makefiles.
#
EOF
# Initialize various variables.
cat <<EOF
#
# Initialize various variables that we set only with += in case some make
# has a default value we weren't expecting.
#
CFLAGS=
KCFLAGS=
HOST_CFLAGS=
LDFLAGS=
KLDFLAGS=
HOST_LDFLAGS=
LIBS=
HOST_LIBS=
EOF
# Define OSTREE.
cat <<EOF
#
# Location of installed runnable system tree.
#
# This must be an absolute path, because it is used from different
# levels of the source tree.
#
OSTREE=${OSTREE}
EOF
# Define PLATFORM.
cat <<EOF
#
# Name of the platform we're building OS/161 to run on.
#
PLATFORM=${PLATFORM}
EOF
if [ "x$PLATFORM" = xmips ]; then
cat <<EOF
#
# As of cs161-toolchain-1.2 the MIPS toolchain is a mips-linux one
# that generates more or less SVR4 ELF ABI compliant code. This means
# that by default all code is PIC (position-independent code), which
# is all very well but not what we want. So we use -fno-pic to turn
# this behavior off. It turns out you need -mno-abicalls too to turn
# it off completely.
#
CFLAGS+=-mno-abicalls -fno-pic
KCFLAGS+=-mno-abicalls -fno-pic
# If using an older cs161-toolchain for MIPS, you'll need this instead:
#LDFLAGS+=-Ttext 0x1000
EOF
fi
# Long explanatory comment about the two sets of compiler tools.
cat <<EOF
#
# Because OS/161 runs on one architecture (probably MIPS or ANT32) and
# is compiled on another (probably Alpha or i386) it is important to
# make sure the right compiler (and assembler, linker, etc.) is used
# at every point.
#
# A compiler compiles *running on* one platform, and *generates code*
# that may run on a different platform. Thus, supposing that you are
# building MIPS OS/161 on i386 Linux, there are four possible compilers.
# (If you are building some other OS/161 or building on some other
# platform, make the appropriate substitutions.) These four are:
#
# (1) runs on i386 Linux, generates code for i386 Linux
# (2) runs on i386 Linux, generates code for MIPS OS/161
# (3) runs on MIPS OS/161, generates code for i386 Linux
# (4) runs on MIPS OS/161, generates code for MIPS OS/161
#
# Note that when building on i386 Linux, there is no use for a
# compiler that runs on MIPS OS/161; you can't run it. Thus cases
# (3) and (4) do not interest us.
#
# However, in the course of the build, there are places where it is
# necessary to compile and run programs on the machine the build is
# happening on. Thus, the makefiles need to be able to access *both*
# compiler (1) and compiler (2).
#
# We do this by defining the make variable CC to be the common case,
# compiler (2), and the make variable HOST_CC to be compiler (1).
# Similar variables are defined for the other bits of the toolchain,
# like AS (assembler), LD (linker), and SIZE (size program).
#
# Then, programs to be run during the build can be compiled with
# HOST_CC, and components of the system can be built with CC.
#
EOF
# define CC, LDCC, AS, LD, AR, RANLIB, SIZE, STRIP,
# the tools for building OS/161.
cat <<EOF
# CC: compiler, when compiling to object files
CC=${TOOLPREFIX}gcc
# LDCC: compiler, when linking
LDCC=${TOOLPREFIX}gcc
# AS: assembler.
AS=${TOOLPREFIX}as
# LD: linker
LD=${TOOLPREFIX}ld
# AR: archiver (librarian)
AR=${TOOLPREFIX}ar
# RANLIB: library postprocessor
RANLIB=${TOOLPREFIX}ranlib
# NM: prints symbol tables
NM=${TOOLPREFIX}nm
# SIZE: prints size of binaries
SIZE=${TOOLPREFIX}size
# STRIP: strips debug info
STRIP=${TOOLPREFIX}strip
EOF
# define HOST_CC, HOST_LDCC, HOST_AS, HOST_LD, HOST_AR, HOST_RANLIB,
# HOST_NM, HOST_SIZE, HOST_STRIP, the tools for building programs
# that run on the host system.
cat <<EOF
# compiler for host system
HOST_CC=${HOST_CC}
# compiler for host system, when linking
HOST_LDCC=${HOST_CC}
# assembler for host system
HOST_AS=as
# linker for host system
HOST_LD=ld
# archiver (librarian) for host system
HOST_AR=ar
# ranlib (library postprocessor) for host system... or "true" to skip it
HOST_RANLIB=${HOST_RANLIB}
# nm for host system
HOST_NM=nm
# size for host system
HOST_SIZE=size
# strip for host system
HOST_STRIP=strip
EOF
# Define compiler and linker flags we're going to use based on the
# requests above.
# This keeps the shell from interpreting the $() inside the here-document.
HINC='-I$(OSTREE)/hostinclude'
cat <<EOF
# The HOST_... versions are for compiling/linking for the host system.
# The K... versions are for the kernel build.
# Compile flags.
# The kernel has its own debug/optimize setting in the kernel config, so
# we don't include ours.
CFLAGS+=${WARNINGS} ${OPTFLAGS}
KCFLAGS+=${WARNINGS}
HOST_CFLAGS+=${WARNINGS} ${OPTFLAGS} ${HINC}
# Linker flags
LDFLAGS+=
KLDFLAGS+=
HOST_LDFLAGS+=
# Libraries
#
LIBS+=
HOST_LIBS+=
EOF
# Config information for the hostcompat library
cat <<EOF
# These are cflags used to conditionally compile src/lib/hostcompat.
COMPAT_CFLAGS=${COMPAT_CFLAGS}
# These are make targets that we conditionally enable when installing
# in src/lib/hostcompat.
COMPAT_TARGETS=${COMPAT_TARGETS}
EOF
# Define additional flags for making the toolchain do what we want.
cat <<EOF
# When we compile OS/161 programs, we want to use the OS/161 header files
# and libraries. By default, gcc will look in some include directory and
# some lib directory that it was told to use when it was compiled. We
# assume that directory isn't ours. (If it is, all these variables can
# be set to empty, but everything will still work if you don't.)
EOF
echo 'TREE_CFLAGS=-nostdinc -I$(OSTREE)/include'
echo 'TREE_LDFLAGS=-nostdlib -L$(OSTREE)/lib $(OSTREE)/lib/crt0.o'
echo 'TREE_LIBS=-lc'
) > defs.mk