-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·145 lines (121 loc) · 3 KB
/
configure
File metadata and controls
executable file
·145 lines (121 loc) · 3 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
#!/bin/sh
unset arch cross target cc ar strip tp lto
commanddir=/sbin
servicedir=/sbin/service
networkdir=/sbin/network
systemdir=/sbin/system
man1dir=/sman/man1
man5dir=/sman/man5
man8dir=/sman/man8
cflags=-Os
die() { echo "$@" >&2; exit 1; }
while [ $# -gt 0 ]; do
case "$1" in
*dir=*) eval "$1" ;;
cross=*) eval "$1"; cross="${cross}-" ;;
target=*) eval "$1"; cross="${cross:-$target-}" ;;
arch=*) eval "$1" ;;
cc=*) eval "$1" ;;
ar=*) eval "$1" ;;
strip=*) eval "$1" ;;
clang) clang=yes ;;
devel) cflags="-Wall -g -DDEVEL" ;;
debug) cflags="-Os -g" ;;
wextra) cflags="$cflags -Wextra" ;;
werror) cflags="$cflags -Werror" ;;
lto) lto="-flto " ;;
qemu=*) eval "$1" ;;
only) shift; only="$@"; break ;;
*) die "Unexpected argument $1" ;;
esac; shift
done
test -z "$ar" && ar="${cross}ar"
test -z "$strip" && strip="${cross}strip"
if [ -n "$clang" -a -z "$cc" ]; then
cc="clang${target:+ --target=$target}"
elif [ -z "$cc" ]; then
cc="${cross}gcc"
fi
if [ -z "$arch" ]; then
mach=`$cc -dumpmachine`
mach=${mach%%-*}
case "$mach" in
mips64el) arch=mips64 ;;
mipsn32) arch=mips32 ;;
mipsn32el) arch=mips32 ;;
mipsel) arch=mips ;;
*) 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 it's qemu=/path/to/qemu-blah than use that unchanged.
if [ -z "$qemu" ]; then
host=`uname -m`
if [ "$host" != "$mach" ]; then
qemu="$mach"
else
qemu="-"
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
networkdir = $networkdir
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
END
# 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.
if [ -n "$clang" ]; then
cat >> mini-cc <<END
exec $cc -ffreestanding \\
-fno-asynchronous-unwind-tables -fno-stack-protector -fno-vectorize \\
-static -nopie -fno-pic -fno-plt $lto \\
-nostdinc -I\$base/lib/arch/$arch -I\$base/lib -MD \\
-Wno-unused-command-line-argument -Wno-gnu \\
$cflags "\$@" \\
-nostdlib \${needslib:+\$base/lib/all.a}
END
else
cat >> mini-cc <<END
exec $cc -ffreestanding \\
-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 "\$@" \\
-nostdlib -Wl,-\\( \${needslib:+\$base/lib/all.a -lgcc} -Wl,-\\)
END
fi
chmod a+x mini-cc