#!/bin/sh # # Copyright 2009 # Kaz Kylheku # Vancouver, Canada # All rights reserved. # # BSD License: # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in # the documentation and/or other materials provided with the # distribution. # 3. The name of the author may not be used to endorse or promote # products derived from this software without specific prior # written permission. # # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. # # Save command line in a way that can be re-run. # This takes care of spaces, but if there are shell-meta characters # in the arguments, oops. # cmdline= for arg in "$0" "$@" ; do [ -n "$cmdline" ] && cmdline="$cmdline " case $arg in *" "* | " "* | *" " ) cmdline=$cmdline$(printf "\"%s\"" "$arg") ;; * ) cmdline=$cmdline$arg ;; esac done # # Parse configuration variables # while [ $# -gt 0 ] ; do case $1 in --no-* ) var=${1#--no-} val= ;; --*=* ) var=${1%=*} var=${var#--} val=${1#*=} ;; --*= ) var=${1%=*} var=${var#--} val= ;; --* ) var=${1#--} val=y ;; *=* ) var=${1%=*} val=${1#*=} ;; *= ) var=${1%=*} val= ;; * ) printf "$0: '$1' doesn't look like a configuration variable assignment\n" printf "$0: use --help to get help\n" exit 1 esac if ! printf $var | grep -q -E '^[A-Za-z_][A-Za-z0-9_]*$' ; then printf "$0: '$var' isn't a proper configuration variable name\n" exit 1; fi eval "$var='$val'" shift done # # Establish default values for any variables that are not specified # on the command line. The default derivations from prefix are in # Make syntax. They go verbatim into the generated config.make. # This way they can be overridden more flexibly at make time. # prefix=${prefix-/usr/local} install_prefix=${install_prefix-} bindir=${datadir-'$(prefix)/bin'} datadir=${datadir-'$(prefix)/share/txr'} mandir=${mandir-'$(prefix)/share/man'} cross=${cross-} compiler_prefix=${compiler_prefix-} cc=${cc-'$(cross)$(compiler_prefix)gcc'} tool_prefix=${tool_prefix-} lex=${lex-'$(cross)$(tool_prefix)flex'} lexlib=${lexlib--lfl} yacc=${yacc-'$(cross)$(tool_prefix)yacc'} opt_flags=${opt_flags--O2} lang_flags=${lang_flags--ansi -std=c89 -D_POSIX_C_SOURCE=2} diag_flags=${diag_flags--Wall} debug_flags=${debug_flags--g} lex_dbg_flags=${lex_dbg_flags-} txr_dbg_opts=${txr_dbg_opts---gc-debug} # # If --help was given (or --help= or help=) then # print help and exit. The termination status is failed, to indicate # that configuration was not done. # if [ -n "$help" ] ; then cat <&1) set -- $output if [ $1 != "GNU" -o $2 != "Make" ] ; then printf "missing\n" exit 1 fi make_version=$3 save_ifs=$IFS ; IFS=. ; set -- $make_version ; IFS=$save_ifs if [ $1 -lt 3 -o \( $1 -eq 3 -a $2 -lt 80 \) ] ; then printf "too old (%s found, 3.80 or newer needed)\n" $make_version exit 1 else printf "yes (%s found)\n" $make_version fi # # Verify sanity of --prefix and other directories. # printf "Checking installation paths:\n" for name in prefix bindir datadir mandir; do eval path="\$install_prefix\${$name}" printf "\$(install_prefix)\$(%s)=%s ... " $name "$path" test_access=y case "$path" in " "* | *" "* | *" " ) printf "incorrect (contains spaces)\n" exit 1 ;; -* ) printf "incorrect (resembles a command option)\n" exit 1 ;; *'$('* ) # It's a make expression; can't test it test_access= ;; /* ) ;; * ) printf "incorrect (must be absolute path)\n" exit 1 ;; esac if [ $test_access ] ; then test_prefix=$path while true ; do if [ -e $test_prefix ] ; then if [ ! -d $test_prefix ] ; then printf "incorrect ('%s' is not a directory)!\n" $test_prefix exit 1 fi if [ ! -w $test_prefix ] ; then printf "okay\n (but no write access to '%s'\n" $test_prefix printf " so 'make install' will require root privileges)\n" else printf "okay\n" fi break fi test_prefix=$(dirname $test_prefix) done else printf "okay\n (make variable derivation)\n" fi done # # First, we have to figure out whether we are configured straight # in the source directory, or whether we are in a separate build directory. # In the latter case, we set up a symbolic link to the Makefile. # source_dir="$(dirname $0)" # # Compute an absolute path to the source directory. # top_srcdir="$(cd "$source_dir" ; pwd -P)" printf "Checking source directory %s ..." "$top_srcdir" case "$top_srcdir" in " "* | *" "* | *" " ) printf " bad (contains spaces)\n" exit 1 ;; * ) printf " okay\n" ;; esac if [ "$source_dir" != "." ] ; then printf "symlinking Makefile -> $source_dir/Makefile\n" ln -sf "$source_dir/Makefile" . else printf "warning: its recommended to build in a separate directory\n" fi # # Save configuration in config.log # cat > config.log < config.make < (give password, if asked) make install !