summaryrefslogtreecommitdiff
path: root/tools/gen-musl-gcc.sh
blob: 89f7f4d98e4965d70fc71194679ed674894ca542 (plain)
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
#!/bin/sh

printf '#!/bin/sh\n\nlibc_prefix="%s"\n' "$1"

cat <<"EOF"
libc_lib=$libc_prefix/lib
libc_inc=$libc_prefix/include
libc_crt="$libc_lib/crt1.o"
libc_start="$libc_lib/crti.o"
libc_end="$libc_lib/crtn.o"

gcc_inc=$libc_inc
libgcc="`gcc \"$@\" -print-file-name=libgcc.a`"

gcc -wrapper sh,-c,'
x= ; y= ; z= ; s= ; for i ; do
  [ "$z" ] || set -- ; z=1
  case "$i" in
    -shared) s=1 ; set -- "$@" -shared ;;
    -Lxxxxxx) x=1 ;;
    -xxxxxx) x= ; [ "$s" ] || set -- "$@" "'"$libc_start"'" "'"$libc_crt"'" ;;
    -l*) [ "$y" ] || set -- "$@" '"$libc_end"' ; set -- "$@" "$i" ; y=1 ;;
    *) [ "$x" ] || set -- "$@" "$i" ;;
  esac
done
exec "$0" "$@"
' -std=gnu99 -nostdinc -nostdlib \
  -isystem "$libc_inc" -isystem "$gcc_inc" \
  -Wl,-xxxxxx "$@" -L"$libc_lib" -lc "$libgcc" -Lxxxxxx -Wl,-nostdlib
EOF