#!/bin/sh exstat=1 trap 'rm -f Makefile dummy dummy.exe testfunc.c testfunc testfunc.exe; exit $exstat' 0 1 2 3 15 # # Yet another Apache Configure helper script. # This script tests certain aspects of the compilation # process. Right now, it can perform 5 tests: # # ./helpers/TestCompile lib # Which checks to see if exists on this system # # ./helpers/TestCompile lib # Which checks to see if exists on this system and # contains func. # # ./helpers/TestCompile func # Which checks to see if exists # # ./helpers/TestCompile header
# Which checks to see if header file
exists # # ./helpers/TestCompile sanity # Which does a simple sanity check/test compile # # ./helpers/TestCompile sizeof # Which prints out the sizeof (sure would be nice # if sizeof could be use in preprocessor if's) # # ./helpers/TestCompile byteorder # Which prints out the byte order of the machine # (12: little endian, 21: big endian) # # It does these by creating a small mini-makefile, based on # ../Makefile.config and trying to compile a small dummy # program. If the compilation succeeds, we assume the test # was successful as well. # # This must be run as './helpers/TestCompile' from # the ./src directory (same directory that Configure is # located) if you want to test it out. Configure must # also call it as './helpers/TestCompile' # # Initially written by Jim Jagielski for the Apache configuration mechanism # # This script falls under the Apache License. # See http://www.apache.org/docs/LICENSE cd ./helpers # # Handle "verbose", "silent" and "runit" flags # VERBOSE=no RUNIT="no" case "$1" in "-v") VERBOSE="yes" shift ;; "-s") VERBOSE="no" shift ;; "-r") RUNIT="yes" shift ;; esac # # Make sure have the right arguments # case "$1" in "lib") if [ "x$2" = "x" ]; then exit fi TLIB="-l$2" if [ "x$VERBOSE" = "xyes" ]; then ERRDIR="" else ERRDIR='2>/dev/null' fi if [ "x$3" = "x" ]; then TARGET='dummy' else TARGET='testfunc' echo "int main(void) { $3(); return(0); }" > testfunc.c fi ;; "sizeof") if [ "x$2" = "x" ]; then exit fi TLIB="" if [ "x$VERBOSE" = "xyes" ]; then ERRDIR="" else ERRDIR='2>/dev/null' fi TARGET='testfunc' cat <testfunc.c #include #include int main(void) { printf("%d\n", sizeof($2)); return(0); } EOF ;; "byteorder") TLIB="" if [ "x$VERBOSE" = "xyes" ]; then ERRDIR="" else ERRDIR='2>/dev/null' fi TARGET='testfunc' cat <testfunc.c #include #include int main(void) { /* Are we little or big endian? From Harbison & Steele */ union { long l; char c[sizeof(long)]; } u; u.l = 1; printf("%s\n", u.c[sizeof(long)-1] == 1 ? "21" : "12"); return(0); } EOF ;; "sanity") TLIB="" if [ "x$VERBOSE" = "xno" ]; then ERRDIR='2>/dev/null' else ERRDIR="" fi TARGET='dummy' ;; "func") if [ "x$2" = "x" ]; then exit fi TLIB="" if [ "x$VERBOSE" = "xyes" ]; then ERRDIR="" else ERRDIR='2>/dev/null' fi TARGET='testfunc' cat <testfunc.c int main(void) { $2(); return(0); } EOF ;; "header") if [ "x$2" = "x" ]; then exit fi TLIB="" if [ "x$VERBOSE" = "xyes" ]; then ERRDIR="" else ERRDIR='2>/dev/null' fi TARGET='testfunc' cat <testfunc.c #include <$2> int main(void) { return(0); } EOF ;; *) exit ;; esac # # Get makefile settings and build a basic Makefile # rm -f dummy cat ../Makefile.config > Makefile cat <> Makefile CFLAGS=\$(OPTIM) \$(CFLAGS1) \$(EXTRA_CFLAGS) LIBS=\$(EXTRA_LIBS) \$(LIBS1) INCLUDES=\$(INCLUDES1) \$(EXTRA_INCLUDES) LDFLAGS=\$(LDFLAGS1) \$(EXTRA_LDFLAGS) dummy: cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) helpers/dummy.c -o helpers/dummy $TLIB \$(LIBS) testfunc: cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) helpers/testfunc.c -o helpers/testfunc $TLIB \$(LIBS) EOF # Now run that Makefile eval "${MAKE-make} ${TARGET} $ERRDIR >&2" # And see if dummy exists and is executable, if so, then we # assume the condition we are testing for is good # # Use our PrintPath helper script using the "-p" option to # have PrintPath just search this directory. if ./PrintPath -s -p`pwd` $TARGET ; then if [ "x$RUNIT" = "xyes" ]; then `pwd`/$TARGET fi exstat=0 fi