forked from alexfru/dflat20
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cosmocc
executable file
·74 lines (68 loc) · 1.86 KB
/
cosmocc
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
#!/bin/sh
# replacement for cc command
#
# we assume you run the following beforehand
#
# sudo chmod 1777 /opt
# cd /opt
# git clone https://github.com/jart/cosmopolitan cosmo
# cd cosmo
# make -j
#
# you can then use it to build open source projects, e.g.
#
# export CC=cosmocc
# export CXX=cosmoc++
# export LD=cosmoc++
# ./configure --prefix=/opt/cosmos
# make -j
# make install
#
if [ "$1" = "--version" ]; then
cat <<'EOF'
x86_64-unknown-cosmo-gcc (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
exit 0
fi
# change the following two lines if required
COSMO="/Users/greg/net/cosmopolitan"
CC="x86_64-linux-musl-gcc"
#COSMO="/opt/cosmo"
#CC="/opt/cosmo/o/third_party/gcc/bin/x86_64-linux-musl-gcc"
CFLAGS="-O2 -fno-omit-frame-pointer -fdata-sections -ffunction-sections -fno-pie -pg -mnop-mcount -mno-tls-direct-seg-refs"
CPPFLAGS="-DNDEBUG -nostdinc -iquote $COSMO -isystem $COSMO/include -isystem $COSMO/libc/isystem -include libc/integral/normalize.inc"
LDFLAGS="-static -no-pie -nostdlib -fuse-ld=bfd -Wl,--gc-sections -L$COSMO/lib -Wl,-T,$COSMO/o/ape/public/ape.lds $COSMO/o/ape/ape-no-modify-self.o $COSMO/o/libc/crt/crt.o"
LDLIBS="$COSMO/o/cosmopolitan.a"
HAS_C=0
HAS_O=0
HAS_E=0
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ "$x" = "-c" ]; then
HAS_C=1
fi
if [ "$x" = "-E" ]; then
HAS_E=1
fi
if [ "$x" = "-o" ] || [ "${x#-o}" != "$x" ]; then
HAS_O=1
fi
set -- "$@" "$x"
done
if [ "$HAS_E" = "1" ]; then
set -- $CPPFLAGS "$@"
elif [ "$HAS_C" = "1" ]; then
set -- $CFLAGS $CPPFLAGS "$@"
else
set -- $LDFLAGS $CPPFLAGS "$@" $LDLIBS
fi
set -- "$CC" "$@"
printf '(cd %s; %s)\n' "$PWD" "$*" >>/tmp/build.log
exec "$@"