build: overhaul wrapper script system for multiple wrapper support

this overhauls part of the build system in order to support multiple
toolchain wrapper scripts, as opposed to solely the musl-gcc wrapper as
before. it thereby replaces --enable-gcc-wrapper with --enable-wrapper=...,
which has the options 'auto' (the default, detect whether to use wrappers),
'all' (build and install all wrappers), 'no' (don't build any) and finally
the options named after the individual compiler scripts (currently only
'gcc' is available) to build and install only that wrapper.
the old --enable-gcc-wrapper is removed from --help, but still available.

it also modifies the wrappers to use the C compiler specified to the build
system as 'inner' compiler, when applicable. as wrapper detection works by
probing this compiler, it may not work with any other.
This commit is contained in:
Shiz 2015-06-28 23:08:19 +02:00 committed by Rich Felker
parent 2a780aa305
commit b3cd7d13fe
2 changed files with 39 additions and 21 deletions

View File

@ -51,6 +51,8 @@ TOOL_LIBS = lib/musl-gcc.specs
ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS) ALL_LIBS = $(CRT_LIBS) $(STATIC_LIBS) $(SHARED_LIBS) $(EMPTY_LIBS) $(TOOL_LIBS)
ALL_TOOLS = tools/musl-gcc ALL_TOOLS = tools/musl-gcc
WRAPCC_GCC = gcc
LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1 LDSO_PATHNAME = $(syslibdir)/ld-musl-$(ARCH)$(SUBARCH).so.1
-include config.mak -include config.mak
@ -155,7 +157,7 @@ lib/musl-gcc.specs: tools/musl-gcc.specs.sh config.mak
sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@ sh $< "$(includedir)" "$(libdir)" "$(LDSO_PATHNAME)" > $@
tools/musl-gcc: config.mak tools/musl-gcc: config.mak
printf '#!/bin/sh\nexec "$${REALGCC:-gcc}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@ printf '#!/bin/sh\nexec "$${REALGCC:-$(WRAPCC_GCC)}" "$$@" -specs "%s/musl-gcc.specs"\n' "$(libdir)" > $@
chmod +x $@ chmod +x $@
$(DESTDIR)$(bindir)/%: tools/% $(DESTDIR)$(bindir)/%: tools/%

56
configure vendored
View File

@ -28,7 +28,7 @@ Optional features:
--enable-debug build with debugging information [disabled] --enable-debug build with debugging information [disabled]
--enable-warnings build with recommended warnings flags [disabled] --enable-warnings build with recommended warnings flags [disabled]
--enable-visibility use global visibility options to optimize PIC [auto] --enable-visibility use global visibility options to optimize PIC [auto]
--enable-gcc-wrapper build musl-gcc toolchain wrapper [auto] --enable-wrapper=... build given musl toolchain wrapper [auto]
--disable-shared inhibit building shared library [enabled] --disable-shared inhibit building shared library [enabled]
--disable-static inhibit building static library [enabled] --disable-static inhibit building static library [enabled]
@ -123,6 +123,8 @@ bindir='$(exec_prefix)/bin'
libdir='$(prefix)/lib' libdir='$(prefix)/lib'
includedir='$(prefix)/include' includedir='$(prefix)/include'
syslibdir='/lib' syslibdir='/lib'
tools=
tool_libs=
target= target=
optimize=auto optimize=auto
debug=no debug=no
@ -131,6 +133,7 @@ visibility=auto
shared=auto shared=auto
static=yes static=yes
wrapper=auto wrapper=auto
gcc_wrapper=no
for arg ; do for arg ; do
case "$arg" in case "$arg" in
@ -154,7 +157,11 @@ case "$arg" in
--disable-warnings|--enable-warnings=no) warnings=no ;; --disable-warnings|--enable-warnings=no) warnings=no ;;
--enable-visibility|--enable-visibility=yes) visibility=yes ;; --enable-visibility|--enable-visibility=yes) visibility=yes ;;
--disable-visibility|--enable-visibility=no) visibility=no ;; --disable-visibility|--enable-visibility=no) visibility=no ;;
--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ;; --enable-wrapper|--enable-wrapper=yes) wrapper=detect ;;
--enable-wrapper=all) wrapper=yes ; gcc_wrapper=yes ;;
--enable-wrapper=gcc) wrapper=yes ; gcc_wrapper=yes ;;
--disable-wrapper|--enable-wrapper=no) wrapper=no ;;
--enable-gcc-wrapper|--enable-gcc-wrapper=yes) wrapper=yes ; gcc_wrapper=yes ;;
--disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;; --disable-gcc-wrapper|--enable-gcc-wrapper=no) wrapper=no ;;
--enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;; --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--build=*) ;;
--host=*|--target=*) target=${arg#*=} ;; --host=*|--target=*) target=${arg#*=} ;;
@ -215,36 +222,44 @@ tryldflag LDFLAGS_TRY -Werror=unknown-warning-option
tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument tryldflag LDFLAGS_TRY -Werror=unused-command-line-argument
# #
# Need to know if the compiler is gcc to decide whether to build the # Need to know if the compiler is gcc or clang to decide which toolchain
# musl-gcc wrapper, and for critical bug detection in some gcc versions. # wrappers to build.
# #
printf "checking whether compiler is gcc... " printf "checking for C compiler family... "
if fnmatch '*gcc\ version*' "$(LC_ALL=C $CC -v 2>&1)" ; then cc_ver="$(LC_ALL=C $CC -v 2>&1)"
cc_is_gcc=yes cc_family=unknown
else if fnmatch '*gcc\ version*' "$cc_ver" ; then
cc_is_gcc=no cc_family=gcc
fi fi
echo "$cc_is_gcc" echo "$cc_family"
# #
# Only build musl-gcc wrapper if toolchain does not already target musl # Figure out toolchain wrapper to build
# #
if test "$wrapper" = auto -o "$wrapper" = detect ; then
printf "checking for toolchain wrapper to build... "
if test "$cc_family" = gcc ; then
gcc_wrapper=yes
if test "$wrapper" = auto ; then if test "$wrapper" = auto ; then
printf "checking whether to build musl-gcc wrapper... "
if test "$cc_is_gcc" = yes ; then
wrapper=yes
while read line ; do while read line ; do
case "$line" in */ld-musl-*) wrapper=no ;; esac case "$line" in */ld-musl-*) gcc_wrapper=no ;; esac
done <<EOF done <<EOF
$($CC -dumpspecs) $($CC -dumpspecs)
EOF EOF
fi
test "$gcc_wrapper" = yes && echo "gcc"
else else
wrapper=no echo "none"
if test "$wrapper" = detect ; then
fail "$0: could not find an appropriate toolchain wrapper"
fi
fi fi
echo "$wrapper"
fi fi
if test "$gcc_wrapper" = yes ; then
tools="$tools tools/musl-gcc"
tool_libs="$tool_libs lib/musl-gcc.specs"
fi
# #
# Find the target architecture # Find the target architecture
@ -580,11 +595,12 @@ LDFLAGS = $LDFLAGS_AUTO $LDFLAGS
CROSS_COMPILE = $CROSS_COMPILE CROSS_COMPILE = $CROSS_COMPILE
LIBCC = $LIBCC LIBCC = $LIBCC
OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS OPTIMIZE_GLOBS = $OPTIMIZE_GLOBS
ALL_TOOLS = $tools
TOOL_LIBS = $tool_libs
EOF EOF
test "x$static" = xno && echo "STATIC_LIBS =" test "x$static" = xno && echo "STATIC_LIBS ="
test "x$shared" = xno && echo "SHARED_LIBS =" test "x$shared" = xno && echo "SHARED_LIBS ="
test "x$wrapper" = xno && echo "ALL_TOOLS =" test "x$cc_family" = xgcc && echo 'WRAPCC_GCC = $(CC)'
test "x$wrapper" = xno && echo "TOOL_LIBS ="
exec 1>&3 3>&- exec 1>&3 3>&-
printf "done\n" printf "done\n"