You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/09/14 17:36:45 UTC

[PATCH] Fix the auto header check

Ok, the below patch tries to fix the auto header checks we recently
introduced. Our problem was that we used TestCompile to determine wheter a C
header file exists or not (i.e. we tried to compile a test source). This
failed horrible because of inter-header dependencies on some platforms.  The
correct way is to only _PRE-PROCESS_ the test source (as GNU Autoconf does).
But for this we first have to determine how we can run the C pre-processor
directly.  The below patch does both checks.  Now even after fiddling a lot
with different platforms, it's still not tested under all platforms, but at
least works reliable on the ones I tested it under. So, it's time (the 18th is
our release date, friends!) to let others try it out, too. 

PS: The patch for src/Configure is a little bit larger than you
    might expect. That's just because I also fixed the execution
    order for the checks.

Greetings,
                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: src/CHANGES
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/CHANGES,v
retrieving revision 1.1057
diff -u -r1.1057 CHANGES
--- CHANGES	1998/09/12 11:26:00	1.1057
+++ CHANGES	1998/09/14 15:30:37
@@ -1,5 +1,17 @@
 Changes with Apache 1.3.2
 
+  *) Fix the recently introduced C header file checking: We now
+     use the C pre-processor pass only (and no longer the complete compiler
+     pass) to determine whether a C header file exists or not. Because only
+     this way we're safe against inter-header dependencies (which cause
+     horrible portability problems). The only drawback is that we now have a
+     CPP variable which has to be determined first (we do a similar approach
+     as GNU Autoconf does here). When all fails the user still has to option
+     to override it manually via APACI or src/Configuration. As a fallback at
+     least for the header check we can directly check the existance of the
+     file under /usr/include, too.
+     [Ralf S. Engelschall] PR#2777, ...
+
   *) Fix mod_auth_*.html documents: NSCA -> NCSA
      [Youichirou Koga <y-...@jp.FreeBSD.org>] PR#2991
Index: configure
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/configure,v
retrieving revision 1.45
diff -u -r1.45 configure
--- configure	1998/08/25 10:51:51	1.45
+++ configure	1998/09/14 15:19:14
@@ -278,7 +278,7 @@
     echo "##  restoring your configuration. Additional parameters can be supplied." >>$configstatus
     echo "##" >>$configstatus
     echo "" >>$configstatus
-    for var in CC OPTIM CFLAGS CFLAGS_SHLIB LDFLAGS LD_SHLIB LDFLAGS_SHLIB \
+    for var in CC CPP OPTIM CFLAGS CFLAGS_SHLIB LDFLAGS LD_SHLIB LDFLAGS_SHLIB \
                LDFLAGS_SHLIB_EXPORT LIBS INCLUDES RANLIB; do
         eval "val=\"\$$var\""
         if [ ".$val" != . ]; then
@@ -954,7 +954,7 @@
 
 #   generate settings from imported environment variables
 OIFS="$IFS" IFS="$DIFS"
-for var in CC OPTIM CFLAGS CFLAGS_SHLIB LDFLAGS LD_SHLIB LDFLAGS_SHLIB \
+for var in CC CPP OPTIM CFLAGS CFLAGS_SHLIB LDFLAGS LD_SHLIB LDFLAGS_SHLIB \
            LDFLAGS_SHLIB_EXPORT LIBS INCLUDES RANLIB DEPS; do
     eval "val=\"\$$var\"";
     if [ ".$val" != . ]; then
Index: src/Configuration.tmpl
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/Configuration.tmpl,v
retrieving revision 1.110
diff -u -r1.110 Configuration.tmpl
--- Configuration.tmpl	1998/09/12 20:16:52	1.110
+++ Configuration.tmpl	1998/09/14 15:08:42
@@ -58,6 +58,7 @@
 EXTRA_DEPS=
 
 #CC=
+#CPP=
 #OPTIM=
 #RANLIB=
 
Index: src/Configure
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/Configure,v
retrieving revision 1.287
diff -u -r1.287 Configure
--- Configure	1998/09/10 08:58:42	1.287
+++ Configure	1998/09/14 15:14:39
@@ -794,6 +794,63 @@
 fi
 
 ####################################################################
+## Now check how we can _directly_ run the C pre-processor
+##
+TCPP=`egrep '^CPP=' Makefile.config | tail -1 | awk -F= '{print $2}'`
+if [ ".$TCPP" != . ]; then
+    CPP=`CC=$CC CPP=$TCPP ./helpers/findcpp.sh`
+else
+    CPP=`CC=$CC ./helpers/findcpp.sh`
+fi
+if [ ".$TCPP" = . ]; then
+    echo "CPP=$CPP" >> Makefile.config
+fi 
+echo " + setting C pre-processor to $CPP"
+
+####################################################################
+## Now check for existance of non-standard system header files
+## and start generation of the ap_config_auto.h header
+##
+AP_CONFIG_AUTO_H="include/ap_config_auto.h"
+echo "/*" >$AP_CONFIG_AUTO_H
+echo " *  ap_config_auto.h -- Automatically determined configuration stuff" >>$AP_CONFIG_AUTO_H
+echo " *  THIS FILE WAS AUTOMATICALLY GENERATED - DO NOT EDIT!" >>$AP_CONFIG_AUTO_H
+echo " */" >>$AP_CONFIG_AUTO_H
+echo "" >>$AP_CONFIG_AUTO_H
+echo "#ifndef AP_CONFIG_AUTO_H" >>$AP_CONFIG_AUTO_H
+echo "#define AP_CONFIG_AUTO_H" >>$AP_CONFIG_AUTO_H
+
+echo " + checking for system header files"
+CHECK_FOR_HEADERS="dlfcn.h dl.h bstring.h crypt.h unistd.h sys/resource.h sys/select.h sys/processor.h"
+for header in $CHECK_FOR_HEADERS; do
+    echo "" >>$AP_CONFIG_AUTO_H
+    echo "/* check: #include <$header> */" >>$AP_CONFIG_AUTO_H
+    name="`echo $header | sed -e 's:/:_:g' -e 's:\.:_:g' | tr '[a-z]' '[A-Z]'`"
+    CPP=$CPP ./helpers/checkheader.sh $header
+    if [ $? -eq 0 ]; then
+        echo "#ifndef HAVE_${name}" >>$AP_CONFIG_AUTO_H
+        echo "#define HAVE_${name} 1" >>$AP_CONFIG_AUTO_H
+        echo "#endif" >>$AP_CONFIG_AUTO_H
+    else
+        echo "#ifdef HAVE_${name}" >>$AP_CONFIG_AUTO_H
+        echo "#undef HAVE_${name}" >>$AP_CONFIG_AUTO_H
+        echo "#endif" >>$AP_CONFIG_AUTO_H
+    fi
+done
+
+####################################################################
+# Special AIX 4.x support: need to check for sys/processor.h
+# to decide whether the Processor Binding can be used or not
+case "$PLAT" in
+    *-ibm-aix*)
+        CPP=$CPP ./helpers/checkheader.sh sys/processor.h
+        if [ $? -eq 0 ]; then
+            CFLAGS="$CFLAGS -DAIX_BIND_PROCESSOR"
+        fi
+        ;;
+esac
+
+####################################################################
 ## Look for OPTIM and save for later
 ##
 TOPTIM=`egrep '^OPTIM=' Makefile.config | tail -1 | awk -F= '{print $2}'`
@@ -1226,17 +1283,6 @@
     esac
 fi
 
-# AIX 4.x support: Special Case: need to check for sys/processor.h
-# before we usually would.
-# Processor Binding
-case "$PLAT" in
-    *-ibm-aix*)
-        if ./helpers/TestCompile header sys/processor.h ; then
-            CFLAGS="$CFLAGS -DAIX_BIND_PROCESSOR"
-        fi
-        ;;
-esac
-
 ####################################################################
 ## Find out what modules we want and try and configure things for them
 ## Module lines can look like this:
@@ -1687,35 +1733,6 @@
 fi
 
 ####################################################################
-## Now check for existance of non-standard system header files
-## and start generation of the ap_config_auto.h header
-##
-AP_CONFIG_AUTO_H="include/ap_config_auto.h"
-echo "/*" >$AP_CONFIG_AUTO_H
-echo " *  ap_config_auto.h -- Automatically determined configuration stuff" >>$AP_CONFIG_AUTO_H
-echo " *  THIS FILE WAS AUTOMATICALLY GENERATED - DO NOT EDIT!" >>$AP_CONFIG_AUTO_H
-echo " */" >>$AP_CONFIG_AUTO_H
-echo "" >>$AP_CONFIG_AUTO_H
-echo "#ifndef AP_CONFIG_AUTO_H" >>$AP_CONFIG_AUTO_H
-echo "#define AP_CONFIG_AUTO_H" >>$AP_CONFIG_AUTO_H
-
-echo " + checking for system header files"
-CHECK_FOR_HEADERS="dlfcn.h dl.h bstring.h crypt.h unistd.h sys/resource.h sys/select.h sys/processor.h"
-for header in $CHECK_FOR_HEADERS; do
-    echo "" >>$AP_CONFIG_AUTO_H
-    echo "/* check: #include <$header> */" >>$AP_CONFIG_AUTO_H
-    name="`echo $header | sed -e 's:/:_:g' -e 's:\.:_:g' | tr '[a-z]' '[A-Z]'`"
-    if ./helpers/TestCompile header $header; then
-        echo "#ifndef HAVE_${name}" >>$AP_CONFIG_AUTO_H
-        echo "#define HAVE_${name} 1" >>$AP_CONFIG_AUTO_H
-        echo "#endif" >>$AP_CONFIG_AUTO_H
-    else
-        echo "#ifdef HAVE_${name}" >>$AP_CONFIG_AUTO_H
-        echo "#undef HAVE_${name}" >>$AP_CONFIG_AUTO_H
-        echo "#endif" >>$AP_CONFIG_AUTO_H
-    fi
-done
-
 ## Finish building ap_config_auto.h
 ##
 ## We pick out all -D's from CFLAGS and insert them as defines into
--- /dev/null	Mon Sep 14 17:23:01 1998
+++ src/helpers/findcpp.sh	Mon Sep 14 17:28:23 1998
@@ -0,0 +1,68 @@
+#!/bin/sh
+##
+##  findcpp.sh -- Find out how to _directly_ run the C Pre-Processor (CPP)
+##  Written by Ralf S. Engelschall for the Apache configuration mechanism
+##
+
+#   create a test C source:
+#   - has to use extension ".c" because some CPP only accept this one
+#   - uses assert.h because this is a standard header and harmless to include
+#   - contains a Syntax Error to make sure it passes only the preprocessor
+#     but not the real compiler pass
+cat >conftest.c <<EOF
+#include <assert.h>
+Syntax Error
+EOF
+
+#   some braindead systems have a CPP define for a directory :-(
+if [ ".$CPP" != . ]; then
+    if [ -d "$CPP" ]; then
+        CPP=''
+    fi
+fi
+if [ ".$CPP" != . ]; then
+    #   case 1: user provided a default CPP variable (we only check)
+    (eval "$CPP conftest.c >/dev/null") 2>conftest.out
+    my_error=`grep -v '^ *+' conftest.out`
+    if [ ".$my_error" != . ]; then
+        CPP=''
+    fi
+else
+    #   case 2: no default CPP variable (we have to find one)
+    #   1. try the standard -E option
+    CPP="${CC-cc} -E"
+    (eval "$CPP conftest.c >/dev/null") 2>conftest.out
+    my_error=`grep -v '^ *+' conftest.out`
+    if [ ".$my_error" != . ]; then
+        #   2. try the -E option and GCC's -traditional-ccp option
+        CPP="${CC-cc} -E -traditional-cpp"
+        (eval "$CPP conftest.c >/dev/null") 2>conftest.out
+        my_error=`grep -v '^ *+' conftest.out`
+        if [ ".$my_error" != . ]; then
+            #   3. try a standalone cpp command in $PATH and lib dirs
+            CPP="`helpers/findprg.sh cpp`"
+            if [ ".$CPP" = . ]; then
+                CPP="`helpers/findprg.sh -p/lib:/usr/lib:/usr/local/lib cpp`"
+            fi
+            if [ ".$CPP" != . ]; then
+                (eval "$CPP conftest.c >/dev/null") 2>conftest.out
+                my_error=`grep -v '^ *+' conftest.out`
+                if [ ".$my_error" != . ]; then
+                    #   ok, we gave up...
+                    CPP=''
+                fi
+            fi
+        fi
+    fi
+fi
+
+#   cleanup after work
+rm -f conftest.*
+
+#   Ok, empty CPP variable now means it's not available
+if [ ".$CPP" = . ]; then
+    CPP='NOT-AVAILABLE'
+fi
+
+echo $CPP
+
--- /dev/null	Mon Sep 14 17:23:01 1998
+++ src/helpers/checkheader.sh	Mon Sep 14 17:28:42 1998
@@ -0,0 +1,30 @@
+#!/bin/sh
+##
+##  checkheader.sh -- Check whether a C header file exists
+##  Written by Ralf S. Engelschall for the Apache configuration mechanism
+##
+
+header=$1
+rc=1
+if [ ".$CPP" = . ]; then
+    CPP='NOT-AVAILABLE'
+fi
+if [ ".$CPP" != ".NOT-AVAILABLE" ]; then
+    #   create a test C source
+    cat >conftest.c <<EOF
+#include <$header>
+Syntax Error
+EOF
+    (eval "$CPP conftest.c >/dev/null") 2>conftest.out
+    my_error=`grep -v '^ *+' conftest.out`
+    if [ ".$my_error" = . ]; then
+        rc=0
+    fi
+else
+    if [ -f "/usr/include/$header" ]; then
+        rc=0
+    fi
+fi
+rm -f conftest.*
+exit $rc
+