-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·130 lines (108 loc) · 2.88 KB
/
configure
File metadata and controls
executable file
·130 lines (108 loc) · 2.88 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
#!/bin/sh
arch=
cross=
unset cc ar strip tp lto
commanddir=/sbin
servicedir=/sbin/service
networkdir=/sbin/network
systemdir=/sbin/system
initrddir=/boot/sbin
man1dir=/usr/share/man1
man5dir=/usr/share/man5
man8dir=/usr/share/man8
cflags=-Os
die() { echo "$@" >&2; exit 1; }
for arg in "$@"; do
case "$arg" in
*dir=*) eval "$arg" ;;
cross=*) eval "$arg" ;;
x86_64|arm|arm64|riscv) arch=$arg ;;
cc=*) eval "$arg" ;;
ar=*) eval "$arg" ;;
strip=*) eval "$arg" ;;
clang) clang=yes ;;
devel) cflags="-Wall -g -DDEVEL" ;;
debug) cflags="-Os -g" ;;
wextra) cflags="$cflags -Wextra" ;;
werror) cflags="$cflags -Werror" ;;
lto) lto="-flto " ;;
*) die "Unexpected argument $arg" ;;
esac
done
test -z "$ar" && ar="${cross:+$cross-}ar"
test -z "$strip" && strip="${cross:+$cross-}strip"
if [ -n "$clang" -a -z "$cc" ]; then
cc="clang${cross:+--target=$cross}"
elif [ -z "$cc" ]; then
cc="${cross:+$cross-}gcc"
fi
if [ -z "$arch" ]; then
mach=`$cc -dumpmachine`
arch=${mach%%-*}
case "$arch" in
aarch64) arch=arm64 ;;
riscv64) arch=riscv ;;
riscv32) die "RV32 is not supported" ;;
esac
test -n "$arch" || die "Cannot determine target arch"
test -d "lib/arch/$arch" || die "Unsupported arch $arch"
fi
cat > config.mk <<END
ARCH = $arch
CC = \$/mini-cc
AR = $ar
LD = \$(CC)
AS = \$(CC)
STRIP = $strip
commanddir = $commanddir
servicedir = $servicedir
networkdir = $networkdir
systemdir = $systemdir
initrddir = $initrddir
man1dir = $man1dir
man5dir = $man5dir
man8dir = $man8dir
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.
#
# Current gcc versions also generate GOT relocations no matter what.
# No idea how to disable them atm. It's mostly harmless, but adds one
# dirty page for executables that would not need it otherwise.
#
# clang does it right and produces nice static executables with no GOT.
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 \\
-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 -no-pie -fno-pie -fno-PIE -fno-pic -fno-PIC -fno-plt $lto \\
-nostdinc -I\$base/lib/arch/$arch -I\$base/lib \\
$cflags "\$@" \\
-nostdlib -Wl,-\\( \${needslib:+\$base/lib/all.a -lgcc} -Wl,-\\)
END
fi
chmod a+x mini-cc