mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: configure script for musl (?!)
Date: Tue, 1 May 2012 19:39:26 -0400	[thread overview]
Message-ID: <20120501233926.GN14673@brightrain.aerifal.cx> (raw)
In-Reply-To: <20120501225408.GM14673@brightrain.aerifal.cx>

[-- Attachment #1: Type: text/plain, Size: 35 bytes --]

Here's the configure draft..

Rich

[-- Attachment #2: configure --]
[-- Type: text/plain, Size: 5235 bytes --]

#!/bin/sh

usage () {
cat <<EOF
Usage: $0 [OPTION]... [VAR=VALUE]... [BUILDTYPE]

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Installation directories:
  --prefix=PREFIX         main installation prefix [/usr/local/musl]
  --exec-prefix=EPREFIX   installation prefix for tools [/usr/local]

Fine tuning of the installation directories:
  --bindir=DIR            user executables [EPREFIX/bin]
  --libdir=DIR            library files for the linker [PREFIX/lib]
  --includedir=DIR        include files for the C compiler [PREFIX/include]
  --syslibdir=DIR         location for the dynamic linker [/lib]

System types:
  --target=TARGET         configure to run on target TARGET [detected]
  --build=BUILD           same as --target

Optional features:
  --enable-debug          build libraries with debugging information
  --disable-shared        inhibit building shared library
  --disable-static        inhibit building static library

Some influential environment variables:
  CC                      C compiler command [guessed]
  CFLAGS                  C compiler flags [-O2 ...]

Use these variables to override the choices made by configure.

EOF
exit 0
}

# Helper functions

fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" ; }
cmdexists () { type "$1" >/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 ="


  reply	other threads:[~2012-05-01 23:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-01 22:54 Rich Felker
2012-05-01 23:39 ` Rich Felker [this message]
2012-05-02 14:00   ` Solar Designer
2012-05-02 14:31     ` Rich Felker
2012-05-02 15:05       ` Solar Designer
2012-05-02 15:39         ` Rich Felker
2012-05-02 15:41           ` Solar Designer
2012-05-02 16:26             ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120501233926.GN14673@brightrain.aerifal.cx \
    --to=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).