remove useless "extern" keywords in headers
[musl] / tools / gen-musl-gcc.sh
1 #!/bin/sh
2
3 printf '#!/bin/sh\n\nlibc_prefix="%s"\nldso_pathname="%s"\n' "$1" "$2"
4
5 cat <<"EOF"
6 gcc=gcc
7 libc_lib=$libc_prefix/lib
8 libc_inc=$libc_prefix/include
9 libc_crt="$libc_lib/crt1.o"
10 libc_start="$libc_lib/crti.o"
11 libc_end="$libc_lib/crtn.o"
12
13 gcc_inc=$libc_inc
14 libgcc="$("$gcc" -print-file-name=libgcc.a)"
15 libgcc=${libgcc%/libgcc.a}
16
17 gccver=${libgcc##*/}
18 gcctarget=${libgcc%/*}
19 gcctarget=${gcctarget##*/}
20
21 case "$gccver" in
22 [0123].*|4.[01]*) ;;
23 *) nosp=-fno-stack-protector ;;
24 esac
25
26 [ "x$1" = "x-V" ] && { printf "%s: -V not supported\n" "$0" ; exit 1 ; }
27
28 for i ; do
29 case "$skip$i" in
30 -I|-L) skip=--- ; continue ;;
31 -[cSE]|-M*) nolink=1 ;;
32 -shared) nocrt=1 ;;
33 -*) ;;
34 *) havefile=1 ;;
35 esac
36 skip=
37 done
38
39 [ "$havefile" ] || nolink=1
40
41 [ "$nolink" ] && nocrt=1
42
43 [ "$nocrt" ] || set -- "$libc_start" "$libc_crt" "$@" "$libc_end" \
44
45 [ "$nolink" ] || {
46 tmp_specs=$HOME/.specs.tmp.$$
47 printf '*link_libgcc:\n\n\n' > "$tmp_specs" || exit 1
48 exec 3<"$tmp_specs"
49 rm -f "$tmp_specs"
50 set -- -specs=/proc/self/fd/3 "$@" \
51   -Wl,--as-needed -Wl,--start-group -lc -lgcc -lgcc_eh -Wl,--end-group \
52   -Wl,-dynamic-linker,"$ldso_pathname" -Wl,-nostdlib
53 }
54
55 set -- -std=gnu99 -nostdinc -nostdlib $nosp \
56   -isystem "$libc_inc" -isystem "$gcc_inc" "$@" \
57   -L"$libc_lib" -L"$libgcc"
58
59 exec "$gcc" "$@"
60 EOF