gen-musl-gcc.sh 1.3 KB

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