home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / findcpp.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-09-17  |  2.2 KB  |  73 lines

  1. #!/bin/sh
  2. ##
  3. ##  findcpp.sh -- Find out how to _directly_ run the C Pre-Processor (CPP)
  4. ##  Written by Ralf S. Engelschall for the Apache configuration mechanism
  5. ##
  6. #
  7. # This script falls under the Apache License.
  8. # See http://www.apache.org/docs/LICENSE
  9.  
  10.  
  11. #   create a test C source:
  12. #   - has to use extension ".c" because some CPP only accept this one
  13. #   - uses assert.h because this is a standard header and harmless to include
  14. #   - contains a Syntax Error to make sure it passes only the preprocessor
  15. #     but not the real compiler pass
  16. cat >conftest.c <<EOF
  17. #include <assert.h>
  18. Syntax Error
  19. EOF
  20.  
  21. #   some braindead systems have a CPP define for a directory :-(
  22. if [ ".$CPP" != . ]; then
  23.     if [ -d "$CPP" ]; then
  24.         CPP=''
  25.     fi
  26. fi
  27. if [ ".$CPP" != . ]; then
  28.     #   case 1: user provided a default CPP variable (we only check)
  29.     (eval "$CPP conftest.c >/dev/null") 2>conftest.out
  30.     my_error=`grep -v '^ *+' conftest.out`
  31.     if [ ".$my_error" != . ]; then
  32.         CPP=''
  33.     fi
  34. else
  35.     #   case 2: no default CPP variable (we have to find one)
  36.     #   1. try the standard -E option
  37.     CPP="${CC-cc} -E"
  38.     (eval "$CPP conftest.c >/dev/null") 2>conftest.out
  39.     my_error=`grep -v '^ *+' conftest.out`
  40.     if [ ".$my_error" != . ]; then
  41.         #   2. try the -E option and GCC's -traditional-ccp option
  42.         CPP="${CC-cc} -E -traditional-cpp"
  43.         (eval "$CPP conftest.c >/dev/null") 2>conftest.out
  44.         my_error=`grep -v '^ *+' conftest.out`
  45.         if [ ".$my_error" != . ]; then
  46.             #   3. try a standalone cpp command in $PATH and lib dirs
  47.             CPP="`./helpers/PrintPath cpp`"
  48.             if [ ".$CPP" = . ]; then
  49.                 CPP="`./helpers/PrintPath -p/lib:/usr/lib:/usr/local/lib cpp`"
  50.             fi
  51.             if [ ".$CPP" != . ]; then
  52.                 (eval "$CPP conftest.c >/dev/null") 2>conftest.out
  53.                 my_error=`grep -v '^ *+' conftest.out`
  54.                 if [ ".$my_error" != . ]; then
  55.                     #   ok, we gave up...
  56.                     CPP=''
  57.                 fi
  58.             fi
  59.         fi
  60.     fi
  61. fi
  62.  
  63. #   cleanup after work
  64. rm -f conftest.*
  65.  
  66. #   Ok, empty CPP variable now means it's not available
  67. if [ ".$CPP" = . ]; then
  68.     CPP='NOT-AVAILABLE'
  69. fi
  70.  
  71. echo $CPP
  72.  
  73.