#!/bin/sh # This is a flexible yet simple configure script that can be used instead of # GNU autoconf for simple projects written in C. It depends on the file # config.config for application-specific globals and the files in config.d/ for # tests to perform. # Copyright (C) 2004 Jonas Jensen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # # Default options # app="the application" prefix=/usr/local env_vars="CC CFLAGS CPPFLAGS LDFLAGS" def_CC=cc def_CFLAGS="-O3 -Wall" MAKE_VARS= if [ -f config.config ]; then . ./config.config fi # # Helper functions # echo1() { echo $ECHO_N "$* $ECHO_C"; } echo2() { echo "$ECHO_T$*"; } conftest() { conftest_compile && conftest_link } conftest_compile() { cat >&5 << EOF Compiling: --------------------------- EOF cat conftest.c >&5 echo "---------------------------" >&5 echo "$CC -c $CPPFLAGS $CFLAGS -o conftest.o conftest.c" >&5 rm -f conftest.o $CC -c $CPPFLAGS $CFLAGS -o conftest.o conftest.c >&5 2>&5 \ && [ -f conftest.o ] } conftest_link() { echo "$CC -o conftest $LDFLAGS conftest.o" >&5 echo >&5 $CC -o conftest $LDFLAGS conftest.o >&5 2>&5 \ && [ -x conftest ] && ./conftest 2>&5 } conftest_define() { echo1 "$2" if conftest; then echo "#define $1 1" >> config.h echo2 "yes" return 0 else echo2 "no" return 1 fi } # # Initialize # exec 5>config.log date >&5 [ -d config.d ] || { echo "Directory config.d not found. Run configure from the source root." exit 1 } if mv -f config.h config.h.bak 2>/dev/null; then trap "mv config.h.bak config.h" 0 fi cat > config.h << EOF /* XXX This file was automatically generated by configure. */ EOF # # Environment # for var in $env_vars; do eval "$var=\${$var:-\$def_$var}" done # # Parse arguments # for option do case "$option" in --help) cat << EOF This will configure $app for your system. Options: --prefix=DIR Path to install under [$prefix] CC=COMMAND C compiler to use [$CC] CFLAGS=OPTIONS C compiler flags [$CFLAGS] EOF exit ;; --strict) CFLAGS="$CFLAGS -std=c9x -W -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls" echo "#define _POSIX_C_SOURCE 200112L" >> config.h echo "#define _XOPEN_SOURCE 600" >> config.h ;; --*=*) arg=`echo "$option"|cut -d= -f 2-` case "$option" in --prefix=*) prefix="$arg" ;; *) echo "configure: warning: ignoring option $option" ;; esac ;; *=*) #export "$option" # doesn't work on Solaris var=`echo "$option"|cut -d= -f 1` arg=`echo "$option"|cut -d= -f 2-` eval "$var='$arg'" esac done # # Do tests # # echo test, stolen from GNU autoconf. This really shows UNIX at its worst... case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in *c*,-n*) ECHO_N= ECHO_C=' ' ECHO_T=' ' ;; *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;; *) ECHO_N= ECHO_C='\c' ECHO_T= ;; esac for f in config.d/*; do cat >&5 << EOF configure: PERFORMING TEST $f EOF . "$f" done # # Clean up # trap "" 0 rm -f config.h.bak conftest.c conftest.o conftest # # Generate Makefile # make clean >/dev/null 2>&1 rm -f Makefile 2>/dev/null || chmod 644 Makefile cat > Makefile << EOF # XXX This Makefile is automatically generated by configure. # XXX Modify Makefile.in to change it. PREFIX = $prefix EOF for var in $env_vars $MAKE_VARS; do eval "val=\"\$$var\"" echo "$var = $val" >> Makefile done cat "Makefile.in" >> Makefile if [ -f Makefile.dep ]; then cat Makefile.dep >> Makefile rm -f Makefile.dep fi chmod 444 Makefile echo echo "Done. Now type 'make' to compile"