#!/bin/sh usage () { cat </dev/null 2>&1 ; } trycc () { test -z "$CC" && cmdexists "$1" && CC=$1 ; } setdir () { if eval "test -z \"\${$1}\"" ; then eval "$1=\$2" else eval "fnmatch '*/' \"\${$1}\"" && eval "$1=\${$1%/}" ; fi } tryflag () { printf "checking whether %s %s works... " "$CC" "$2" echo "typedef int x;" > "$tmpc" if "$CC" "$2" -c -o /dev/null "$tmpc" 2>/dev/null ; then printf "yes\n" eval "$1=\"\${$1} \$2\"" eval "$1=\${$1# }" else printf "no\n" fi } # Beginning of actual script prefix= exec_prefix= bindir= libdir= includedir= syslibdir= build= debug= shared= static= for arg ; do case "$arg" in --help) usage ;; --prefix=*) prefix=${arg#*=} ;; --exec-prefix=*) exec_prefix=${arg#*=} ;; --bindir=*) bindir=${arg#*=} ;; --libdir=*) libdir=${arg#*=} ;; --includedir=*) includedir=${arg#*=} ;; --syslibdir=*) syslibdir=${arg#*=} ;; --enable-shared|--enable-shared=yes) shared=yes ;; --disable-shared|--enable-shared=no) shared=no ;; --enable-static|--enable-static=yes) static=yes ;; --disable-static|--enable-static=no) static=no ;; --enable-debug|--enable-debug=yes) debug=yes ;; --disable-debug|--enable-debug=no) debug=no ;; --enable-*|--disable-*|--with-*|--without-*|--*dir=*|--host=*) ;; --build=*|--target=*) build=${arg#*=} ;; -* ) echo "$0: unknown option $arg" ;; CC=*) CC=${arg#*=} ;; CFLAGS=*) CFLAGS=${arg#*=} ;; CPPFLAGS=*) CPPFLAGS=${arg#*=} ;; LDFLAGS=*) LDFLAGS=${arg#*=} ;; *) build=$arg ;; esac done setdir prefix /usr/local/musl setdir exec_prefix '/usr/local' setdir bindir '$(exec_prefix)/bin' setdir libdir '$(prefix)/lib' setdir includedir '$(prefix)/include' setdir syslibdir '/lib' # Get a temp filename we can use test -n "$TMPDIR" && tmpc="$TMPDIR/conf$$.c" || tmpc="/tmp/conf$$.c" set -C > "$tmpc" || { echo "$0: cannot create temporary file $tmpc" exit 1 } set +C trap 'rm "$tmpc"' EXIT # Find a C compiler to use printf "checking for C compiler... " trycc gcc trycc c99 trycc cc printf "%s\n" "$CC" test -n "$CC" || { echo "$0: cannot find a C compiler" ; exit 1 ; } # Find the build architecture printf "checking build system type... " test -n "$build" || build=$("$CC" -dumpmachine 2>/dev/null) || build=unknown printf "%s\n" "$build" # Convert to just ARCH case "$build" in arm*) ARCH=arm ;; i?86*) ARCH=i386 ;; x86_64*) ARCH=x86_64 ;; unknown) echo "$0: unable to detect built target; try $0 --build=..." ; exit 1 ;; *) echo "$0: unknown or unsupported build target \"$build\"" ; exit 1 ;; esac # Try to get a conforming C99 freestanding environment tryflag CFLAGS_C99FSE -std=c99 tryflag CFLAGS_C99FSE -nostdinc tryflag CFLAGS_C99FSE -ffreestanding \ || tryflag CFLAGS_C99FSE -fno-builtin tryflag CFLAGS_C99FSE -fexcess-precision=standard \ || tryflag CFLAGS_C99FSE -ffloat-store # Default CFLAGS test -z "$CFLAGS" && CFLAGS=-O2 test "x$debug" = xyes && CFLAGS="$CFLAGS -g" tryflag CFLAGS -pipe # If debugging is disabled, omit bloated DWARF2 unwind tables & frame ptr if fnmatch '-g*|*\ -g*' "$CFLAGS" ; then : else tryflag CFLAGS -fno-asynchronous-unwind-tables tryflag CFLAGS -fomit-frame-pointer fi # Some optimization levels add bloated alignment that hurt performance tryflag CFLAGS -falign-functions=1 tryflag CFLAGS -falign-labels=1 tryflag CFLAGS -falign-loops=1 tryflag CFLAGS -falign-jumps=1 if test "$ARCH" = "i386" ; then fnmatch '-march=*|*\ -march=*' "$CFLAGS" || tryflag CFLAGS -march=i486 fnmatch '-mtune=*|*\ -mtune=*' "$CFLAGS" || tryflag CFLAGS -mtune=generic fi exec 1>config.mak cat << EOF ARCH = $ARCH prefix = $prefix exec_prefix = $exec_prefix bindir = $bindir libdir = $libdir includedir = $includedir syslibdir = $syslibdir CC = $CC CFLAGS = $CFLAGS CFLAGS_C99FSE = $CFLAGS_C99FSE CPPFLAGS = $CPPFLAGS LDFLAGS = $LDFLAGS EOF test "x$static" = xno && echo "STATIC_LIBS =" test "x$shared" = xno && echo "SHARED_LIBS ="