Mercurial > hg > forks > yadex
view configure @ 117:0612954ba99c default tip
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Oct 2014 16:36:48 +0300 |
parents | 9694eb987bf3 |
children |
line wrap: on
line source
#!/bin/sh # # configure - configure script for Yadex # AYM 2002-09-15 # # This file is copyright André Majorel 2002-2003. # # This program is free software; you can redistribute it and/or modify it under # the terms of version 2 of the GNU General Public License as published by the # Free Software Foundation. # # 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. set -e APPNAME=yadex VERSION=`cat VERSION` CC= CXX= HAVE_READLINE=auto HAVE_GETTIMEOFDAY= HAVE_NANOSLEEP= HAVE_SNPRINTF= HAVE_USLEEP= INTERFACE=x11 # "bgi" or "x11" PLATFORM=unix # "dos" or "unix" PREFIX=/usr/local # # check - perform a test # check () { cdir=/tmp cbasename=${APPNAME}_$$.c cout=${APPNAME}_$$.out printf '%s' "$3" >$cdir/$cbasename printf 'checking %s...' "$1" if (cd $cdir && $CC -c $cbasename $4 $5 $6 >$cout 2>&1) then echo " yes" eval "$2=1" return 0 else echo " no" sed 's/^/> /' $cdir/$cout eval "$2=" return 1 fi } # # genc - generate config.cc # genc () { pathname=$BUILDDIR/config.cc echo generating $pathname ( set -e echo '// DO NOT EDIT -- generated by ./configure' echo echo '#include "config.h"' echo echo 'const char *yadex_etc_path[] =' echo '{' sed 's/\\/\\\\/g; s/"/\\"/g; s/^.*/ "&",/;' $BUILDDIR/config.etc echo ' 0' echo '};' echo echo 'const char *yadex_share_path[] =' echo '{' sed 's/\\/\\\\/g; s/"/\\"/g; s/^.*/ "&",/;' $BUILDDIR/config.share echo ' 0' echo '};' echo ) >$pathname } # # genbool - generate a boolean macro definition # genbool () { name=$1 if [ -n "`eval echo \\$HAVE_"$name"`" ]; then echo "#define Y_$name" else echo "//#define Y_$name" fi } # # genh - generate config.h # genh () { pathname=$BUILDDIR/config.h echo generating $pathname ( set -e echo '// DO NOT EDIT -- generated by ./configure' echo case "$PLATFORM" in dos) echo '#define Y_DOS' echo '//#define Y_UNIX';; unix) echo '//#define Y_DOS' echo '#define Y_UNIX';; *) echo "configure: bad \$PLATFORM \"$PLATFORM\"" >&2 exit 1;; esac case "$INTERFACE" in bgi) echo '#define Y_BGI' echo '//#define Y_X11';; x11) echo '//#define Y_BGI' echo '#define Y_X11';; *) echo "configure: bad \$INTERFACE \"$INTERFACE\"" >&2 exit 1;; esac genbool GETTIMEOFDAY genbool NANOSLEEP genbool SNPRINTF genbool USLEEP genbool READLINE echo echo 'extern const char *yadex_etc_path[];' echo 'extern const char *yadex_share_path[];' echo ) >$pathname } # # Parse the command line # while [ "$#" -ge 1 ] do case "$1" in --help) echo "Usage:" echo " configure --help" echo " configure [--prefix=path] [--cc=string] [--cxx=string] [--with-readline=path] [--without-readline]" exit 0 ;; --cc=*) CC=`expr "x$1" : 'x--cc=\(.*\)'` ;; --cxx=*) CXX=`expr "x$1" : 'x--cxx=\(.*\)'` ;; --prefix=*) PREFIX=`expr "x$1" : 'x--prefix=\(.*\)'` ;; --with-readline=*) READLINE_PREFIX=`expr "x$1" : 'x--with-readline=\(.*\)'` HAVE_READLINE=yes ;; --without-readline*) HAVE_READLINE= ;; -*) echo "configure: bad argument \"$1\"" 1>&2 exit 1 ;; *) echo "configure: too many arguments" 1>&2 exit 1 esac shift done # # Sanity checks # if expr "x$PREFIX" : x/ >/dev/null then true else echo "configure: --prefix: argument is not an absolute path" 1>&2 exit 1 fi # Solaris /bin/grep doesn't know about -Fx. GREP=/usr/xpg4/bin/grep [ -x $GREP ] || GREP=grep # # Look for a C compiler # # We try "gcc" first as commercial Unixen often have a bundled # "cc" command that's useless for our purposes (antiquated KNR # compiler or front-end that just hangs waiting for an answer from # some licence manager). # printf "looking for a C compiler..." if [ -n "$CC" ] then printf ' using user-supplied value:' else CC=gcc if type $CC >/dev/null 2>&1 then : else CC=c89 if type $CC >/dev/null 2>&1 then : else CC=cc if type $CC >/dev/null 2>&1 then : else echo " none" echo "error: none of (gcc, c89, cc) work, is your PATH set right?" 1>&2 exit 1 fi fi fi fi echo " $CC" # # Does the C compiler actually work ? # cdir=/tmp cbasename=${APPNAME}_$$.c cout=${APPNAME}_$$.out echo -n "checking whether the C compiler works..." echo 'int n;' >$cdir/$cbasename if (cd $cdir && $CC -c $cbasename >$cout 2>&1) then echo " yes" else echo " no" sed 's/^/> /' $cdir/$cout echo "error: looks like the C compiler is not working" 1>&2 exit 1 fi # # Do we have gettimeofday() ? # check "for gettimeofday" HAVE_GETTIMEOFDAY ' #include <sys/time.h> #include <time.h> int main (int argc, char *argv[]) { struct timeval tv; struct timezone tz; int n = gettimeofday (&tv, &tz); return n; } ' || true # # Do we have nanosleep() ? # check "for nanosleep" HAVE_NANOSLEEP ' #include <time.h> int main (int argc, char *argv[]) { struct timespec ts; ts.tv_sec = 1; ts.tv_nsec = 1; nanosleep (&ts, &ts); return 0; } ' || true # # Do we have snprintf() ? # check "for snprintf" HAVE_SNPRINTF ' #include <stdio.h> int main (int argc, char *argv[]) { char buf[1]; int n = snprintf (buf, sizeof buf, "%d", 42); return n; } ' || true # # Do we have usleep() ? # check "for usleep" HAVE_USLEEP ' #include <unistd.h> int main (int argc, char *argv[]) { unsigned long usec = 1; usleep (usec); return 0; } ' || true # # Do we have GNU readline? # READLINE_FLAGS= if [ "x$HAVE_READLINE" = "xauto" -o "x$HAVE_READLINE" = "xyes" ] then if [ "x$HAVE_READLINE" = "xyes" ] then READLINE_FLAGS="-I$READLINE_PREFIX/include -L$READLINE_PREFIX/lib" fi check "for readline" HAVE_READLINE ' #include <stdio.h> #include <readline/readline.h> #include <readline/history.h> int main (int argc, char *argv[]) { char* input = readline("test"); add_history(input); return 0; } ' -lreadline $OPTS fi if [ "x$HAVE_READLINE" != "x" ] then EXTRA_LDFLAGS="$EXTRA_LDFLAGS $READLINE_FLAGS -lreadline" fi # # Look for a C++ compiler # # We try "g++" first, then "c++", then "cxx". # printf "looking for a C++ compiler..." if [ -n "$CXX" ] then printf ' using user-supplied value:' else CXX=g++ if type $CXX >/dev/null 2>&1 then : else CXX=c++ if type $CXX >/dev/null 2>&1 then : else CXX=cxx if type $CXX >/dev/null 2>&1 then : else echo " none" echo "error: none of (g++, c++, cxx) work, is your PATH set right?" 1>&2 exit 1 fi fi fi fi echo " $CXX" # # Does the C++ compiler actually work ? # cdir=/tmp cbasename=${APPNAME}_$$.cc cout=${APPNAME}_$$.out printf "checking whether the C++ compiler works..." echo 'int n;' >$cdir/$cbasename if (cd $cdir && $CXX -c $cbasename >$cout 2>&1) then echo " yes" else echo " no" sed 's/^/> /' $cdir/$cout echo "error: looks like the C++ compiler is not working" 1>&2 exit 1 fi # # Does C++ compiler support -std=c++11 ? # printf "checking whether the C++ compiler supports C++11..." cat > $cdir/$cbasename << _EOF_ #include <memory> int main(int argc, char *argv[]) { std::shared_ptr<int> sp(new int(5)); (void) argc; (void) argv; return 0; } _EOF_ if (cd $cdir && $CXX -std=c++11 -c $cbasename >$cout 2>&1) then echo " yes" else echo " no" sed 's/^/> /' $cdir/$cout echo "error: looks like the C++ compiler does not support C++11" 1>&2 exit 1 fi # # Create the directory where the build-specific files go # SYSTEM_RAW="`uname -n`_`uname -a | cksum`" SYSTEM="`echo "$SYSTEM_RAW" | tr -dc '[:alnum:]._-'`" BUILDDIR=obj/$SYSTEM echo "build directory is $BUILDDIR" mkdir -p $BUILDDIR # # FHS paths # if expr "$PREFIX" : '//*usr/*$' >/dev/null then BINDIR=/usr/bin # FHS-ly correct is /usr/games ETCDIR=/etc/$APPNAME/%v ETCDIRNV=/etc/$APPNAME MANDIR=/usr/share/man SHAREDIR=/usr/share/games/$APPNAME/%v SHAREDIRNV=/usr/share/games/$APPNAME elif expr "$PREFIX" : '//*usr//*local/*$' >/dev/null then BINDIR=/usr/local/bin # FHS-ly correct is /usr/local/games ETCDIR=/usr/local/etc/$APPNAME/%v ETCDIRNV=/usr/local/etc/$APPNAME MANDIR=/usr/local/man SHAREDIR=/usr/local/share/games/$APPNAME/%v SHAREDIRNV=/usr/local/share/games/$APPNAME elif expr "$PREFIX" : '//*opt/*$' >/dev/null then echo '/opt ? Surely you mean /opt/something, Mr. Feynman !' 1>&2 exit 1 elif expr "$PREFIX" : '//*opt//*[^/]' >/dev/null then BINDIR=$PREFIX/bin ETCDIR=/etc/opt/`expr "$PREFIX" : '//*opt//*\(.*\)'` ETCDIRNV= MANDIR=$PREFIX/man SHAREDIR=$PREFIX/share SHAREDIRNV= else # Probably /home/joe/* BINDIR=$PREFIX/bin ETCDIR=$PREFIX/etc ETCDIRNV= MANDIR=$PREFIX/man SHAREDIR=$PREFIX/share SHAREDIRNV= fi # # Write Makefile.config # echo generating $BUILDDIR/Makefile.config ( echo "# DO NOT EDIT -- generated by ./configure" echo echo "BINDIR = $BINDIR" echo "CC = $CC" echo "CXX = $CXX" echo "ETCDIR = $ETCDIR" | sed "s/%v/$VERSION/g" echo "ETCDIRNV = $ETCDIRNV" echo "HAVE_GETTIMEOFDAY = $HAVE_GETTIMEOFDAY" echo "HAVE_NANOSLEEP = $HAVE_NANOSLEEP" echo "HAVE_SNPRINTF = $HAVE_SNPRINTF" echo "HAVE_USLEEP = $HAVE_USLEEP" echo "HAVE_READLINE = $HAVE_READLINE" echo "INTERFACE = $INTERFACE" echo "MANDIR = $MANDIR" echo "PLATFORM = $PLATFORM" echo "SHAREDIR = $SHAREDIR" | sed "s/%v/$VERSION/g" echo "SHAREDIRNV = $SHAREDIRNV" echo "EXTRA_CFLAGS = $EXTRA_CFLAGS" echo "EXTRA_CXXFLAGS = $EXTRA_CXXFLAGS" echo "EXTRA_LDFLAGS = $EXTRA_LDFLAGS" ) >$BUILDDIR/Makefile.config # # YGD files search path # echo generating $BUILDDIR/config.share $GREP -Fvx '' <<EOF >"$BUILDDIR/config.share" . ~/.$APPNAME/%v ~/.$APPNAME $SHAREDIR $SHAREDIRNV EOF # # Config files search path # echo generating $BUILDDIR/config.etc $GREP -Fvx '' <<EOF >"$BUILDDIR/config.etc" . ~/.$APPNAME/%v ~/.$APPNAME $ETCDIR $ETCDIRNV EOF # # Write config.h and config.cc # genc genh exit 0