-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·194 lines (160 loc) · 4.06 KB
/
configure
File metadata and controls
executable file
·194 lines (160 loc) · 4.06 KB
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
#!/bin/sh
unset arch cross target cc ar strip tp lto cflags uselds
commanddir=/sbin
servicedir=/sbin/service
systemdir=/sbin/system
man1dir=/sman/man1
man5dir=/sman/man5
man8dir=/sman/man8
uselds=yes
die() { echo "$@" >&2; exit 1; }
accept() { eval "$key=\$val"; unset val; }
setkey() { eval "$1=\$val"; unset val; }
append() { eval "$1=\"\${$1:+\$$1 }\$2\""; }
appval() { append "$1" "$val"; unset val; }
optim=-Os
while [ $# -gt 0 ]; do
key=${1%%=*}
val=${1#*=}
test "$key" = "$1" && unset val
case "$key" in
commanddir) accept ;;
servicedir) accept ;;
systemdir) accept ;;
cross) accept; cross="${cross}-" ;;
target) accept; cross="${cross:-$target-}" ;;
arch) accept ;;
cc|CC) setkey cc ;;
ar|AR) setkey ar ;;
strip) setkey strip ;;
STRIP) setkey strip ;;
cflags) appval cflags; unset optim ;;
CFLAGS) appval cflags; unset optim ;;
devel) append cflags "-Wall -g -DDEVEL"; unset optim ;;
debug) append cflags "-Wall -g" ;;
wextra) append cflags "-Wextra" ;;
werror) append cflags "-Werror" ;;
lto) lto="-flto " ;;
qemu) accept ;;
only) shift; only="$@"; break ;;
nolds) unset uselds ;;
*) die "Unexpected argument $key" ;;
esac; shift
test -n "$val" && die "Unexpected argument for $key"
done
append cflags "$optim"
append cflags "$lto"
test -z "$ar" && ar="${cross}ar"
test -z "$strip" && strip="${cross}strip"
case "$cc" in
*clang*) die "clang is not supported" ;;
esac
test -z "$cc" && cc="${cross}gcc"
if [ -z "$arch" ]; then
mach=`$cc -dumpmachine`
mach=${mach%%-*}
case "$mach" in
i[3456]86) arch=i386 ;;
mips64el) arch=mips64 ;;
mipsn32) arch=mips32 ;;
mipsn32el) arch=mips32 ;;
mipsel) arch=mips ;;
armv*) arch=arm ;;
*) arch="$mach"
esac
test -n "$arch" || die "Cannot determine target arch"
test -d "lib/arch/$arch" || die "Unsupported arch $arch"
fi
# Default meaning of qemu=something is to use qemu-something,
# however if it's qemu=/path/to/qemu-blah then use that unchanged.
if [ -z "$qemu" ]; then
host=`uname -m`
if [ "$host" = "$mach" ]; then
qemu="-"
elif [ "$arch" = "i386" ]; then
qemu="$arch"
else
qemu="$mach"
fi
fi
case "$qemu" in
-) qemu='' ;;
*-*) ;;
*/*) ;;
*) qemu="qemu-$qemu" ;;
esac
cat > config.mk <<END
ARCH = $arch
CC = \$/mini-cc
AR = $ar
LD = \$(CC)
AS = \$(CC)
STRIP = $strip
QEMU = $qemu
commanddir = $commanddir
servicedir = $servicedir
systemdir = $systemdir
man1dir = $man1dir
man5dir = $man5dir
man8dir = $man8dir
only = $only
END
cat > mini-cc <<END
#!/bin/sh
case "\$0" in
*/*) base=\${0%/*} ;;
*) echo "\$0 may not be called from PATH" >&2; exit 1 ;;
esac
needslib=yes
for _ in "\$@"; do
case "\$_" in
-c|-E|-S) unset needslib ;;
esac
done
set $cc -ffreestanding -fomit-frame-pointer \\
-fno-asynchronous-unwind-tables -fno-stack-protector \\
-static -fno-pie -fno-PIE -fno-pic -fno-PIC $lto \\
-nostdinc -I\$base/lib/arch/$arch -I\$base/lib -MD \\
$cflags "\$@"
END
# ^above: GCC may be configured to produce PIEs without explicit -pie options,
# and it would do so even if given -ffreestanding -static. This is not
# acceptable for minibase, so the code below tries to force non-PIE mode.
# Below: use custom linker script if available, otherwise link with lib/all.a
# and libgcc.a; note it must be a linker group because reasons.
ldscript="lib/arch/$arch/static.ld"
if [ -n "$uselds" -a -f "$ldscript" ]; then
cat >> mini-cc <<END
test -n "\$needslib" && \
set "\$@" -nostdlib \\
-Wl,-\\( \$base/lib/all.a -lgcc -Wl,-\\) \\
-T \$base/$ldscript
exec "\$@"
END
else
cat >> mini-cc <<END
test -n "\$needslib" && \
set "\$@" -nostdlib \\
-Wl,-\\( \$base/lib/all.a -lgcc -Wl,-\\)
exec "\$@"
END
fi
chmod a+x mini-cc
echo "Configured for $arch"
echo
echo " CC = $cc"
echo " AR = $ar"
echo " STRIP = $strip"
echo " CFLAGS = $cflags"
test -n "$qemu" && echo " QEMU = $qemu"
echo
echo " commanddir = $commanddir"
echo " servicedir = $servicedir"
echo " systemdir = $systemdir"
echo
echo " man1dir = $man1dir"
echo " man5dir = $man5dir"
echo " man8dir = $man8dir"
echo
test -n "$only" && echo "Tools to build: $only"
echo "Proceed to run 'make'"