home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / TestCompile < prev   
Encoding:
Text File  |  1998-12-09  |  3.2 KB  |  157 lines

  1. #!/bin/sh
  2. exstat=1
  3. trap 'rm -f Makefile dummy dummy.exe testfunc.c testfunc testfunc.exe; exit $exstat' 0 1 2 3 15
  4. #
  5. # Yet another Apache Configure helper script.
  6. # This script tests certain aspects of the compilation
  7. # process. Right now, it can perform 5 tests:
  8. #
  9. # ./helpers/TestCompile lib <libname>
  10. #    Which checks to see if <libname> exists on this system
  11. #
  12. # ./helpers/TestCompile lib <libname> <func>
  13. #    Which checks to see if <libname> exists on this system and
  14. #    contains func.
  15. #
  16. # ./helpers/TestCompile func <function>
  17. #    Which checks to see if <function> exists
  18. #
  19. # ./helpers/TestCompile header <header>
  20. #    Which checks to see if header file <header> exists
  21. #
  22. # ./helpers/TestCompile sanity
  23. #    Which does a simple sanity check/test compile
  24. #
  25. # It does these by creating a small mini-makefile, based on
  26. # ../Makefile.config and trying to compile a small dummy
  27. # program. If the compilation succeeds, we assume the test
  28. # was successful as well.
  29. #
  30. # This must be run as './helpers/TestCompile' from
  31. # the ./src directory (same directory that Configure is
  32. # located) if you want to test it out. Configure must
  33. # also call it as './helpers/TestCompile'
  34. #
  35. # This script falls under the Apache License.
  36. # See http://www.apache.org/docs/LICENSE
  37.  
  38.  
  39. cd ./helpers
  40.  
  41. #
  42. # Handle "verbose" and "silent" flags
  43. #
  44. case "$1" in
  45.     "-v")
  46.         VERBOSE="yes"
  47.     shift
  48.     ;;
  49.     "-s")
  50.         VERBOSE="no"
  51.     shift
  52.     ;;
  53. esac
  54.  
  55. #
  56. # Make sure have the right arguments
  57. #
  58.  
  59. case "$1" in
  60.     "lib")
  61.     if [ "x$2" = "x" ]; then
  62.         exit
  63.     fi
  64.     TLIB="-l$2"
  65.     if [ "$VERBOSE" = "yes" ]; then
  66.         ERRDIR=""
  67.     else
  68.         ERRDIR='2>/dev/null'
  69.     fi
  70.     if [ "x$3" = "x" ]; then
  71.         TARGET='dummy'
  72.     else
  73.         TARGET='testfunc'
  74.         echo "int main(void) { $3(); return(0); }" > testfunc.c
  75.     fi
  76.     ;;
  77.     "sanity")
  78.     TLIB=""
  79.     if [ "$VERBOSE" = "no" ]; then
  80.         ERRDIR='2>/dev/null'
  81.     else
  82.         ERRDIR=""
  83.     fi
  84.     TARGET='dummy'
  85.     ;;
  86.     "func")
  87.     if [ "x$2" = "x" ]; then
  88.         exit
  89.     fi
  90.     TLIB=""
  91.     if [ "$VERBOSE" = "yes" ]; then
  92.         ERRDIR=""
  93.     else
  94.         ERRDIR='2>/dev/null'
  95.     fi
  96.     TARGET='testfunc'
  97.     cat <<EOF >testfunc.c
  98. int main(void) {
  99.     $2();
  100.     return(0);
  101. }
  102. EOF
  103.     ;;
  104.     "header")
  105.     if [ "x$2" = "x" ]; then
  106.         exit
  107.     fi
  108.     TLIB=""
  109.     if [ "$VERBOSE" = "yes" ]; then
  110.         ERRDIR=""
  111.     else
  112.         ERRDIR='2>/dev/null'
  113.     fi
  114.     TARGET='testfunc'
  115.     cat <<EOF >testfunc.c
  116. #include <$2>
  117. int main(void) {
  118.     return(0);
  119. }
  120. EOF
  121.     ;;
  122.     *)
  123.         exit
  124.     ;;
  125. esac
  126.  
  127. #
  128. # Get makefile settings and build a basic Makefile
  129. #
  130. rm -f dummy
  131. cat ../Makefile.config > Makefile
  132. cat <<EOF >> Makefile
  133. CFLAGS=\$(OPTIM) \$(CFLAGS1) \$(EXTRA_CFLAGS)
  134. LIBS=\$(EXTRA_LIBS) \$(LIBS1)
  135. INCLUDES=\$(INCLUDES1) \$(EXTRA_INCLUDES)
  136. LDFLAGS=\$(LDFLAGS1) \$(EXTRA_LDFLAGS)
  137.  
  138. dummy:
  139.     cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) helpers/dummy.c -o helpers/dummy $TLIB \$(LIBS)
  140.  
  141. testfunc:
  142.     cd ..; \$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) helpers/testfunc.c -o helpers/testfunc $TLIB \$(LIBS)
  143. EOF
  144.  
  145. # Now run that Makefile
  146. eval "${MAKE} ${TARGET} >/dev/null $ERRDIR"
  147.  
  148. # And see if dummy exists and is executable, if so, then we
  149. # assume the condition we are testing for is good
  150. #
  151. # Use our PrintPath helper script using the "-p" option to
  152. # have PrintPath just search this directory.
  153.  
  154. if ./PrintPath -s -p`pwd` $TARGET ; then
  155.     exstat=0
  156. fi
  157.