home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / autoconf-1.11-src.lha / GNU / src / amiga / autoconf-1.11 / autoheader.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1994-06-12  |  7KB  |  236 lines

  1. #!/bin/sh
  2. # autoheader -- create `config.h.in' from `configure.in'
  3. # Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
  4.  
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9.  
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. # Written by Roland McGrath.
  20.  
  21. # If given no args, create `config.h.in' from template file `configure.in'.
  22. # With one arg, create a header file on standard output from
  23. # the given template file.
  24.  
  25. usage="Usage: autoheader [-h] [--help] [-m dir] [--macrodir=dir] 
  26.                   [-v] [--version] [template-file]" 
  27.  
  28. # NLS nuisances.
  29. # These must not be set unconditionally because not all systems understand
  30. # e.g. LANG=C (notably SCO).
  31. if test "${LC_ALL+set}" = 'set' ; then LC_ALL=C; export LC_ALL; fi
  32. if test "${LANG+set}"   = 'set' ; then LANG=C;   export LANG;   fi
  33.  
  34. test -z "${AC_MACRODIR}" && AC_MACRODIR=@datadir@
  35. test -z "${M4}" && M4=@M4@
  36. case "${M4}" in
  37. /*) # Handle the case that m4 has moved since we were configured.
  38.     # It may have been found originally in a build directory.
  39.     test -f "${M4}" || M4=m4 ;;
  40. esac
  41.  
  42. print_version=""
  43. while test $# -gt 0 ; do
  44.    case "z${1}" in 
  45.       z-h | z--help | z--h* )
  46.          /bin/echo "${usage}"; exit 0 ;;
  47.       z--macrodir=* | z--m*=* )
  48.          AC_MACRODIR="`/bin/echo \"${1}\" | sed -e 's/^[^=]*=//'`"
  49.          shift ;;
  50.       z-m | z--macrodir | z--m* ) 
  51.          shift
  52.          test $# -eq 0 && { /bin/echo "${usage}" 1>&2; exit 1; }
  53.          AC_MACRODIR="${1}"
  54.          shift ;;
  55.       z-v | z--version | z--v* )
  56.          print_version="-DAC_PRINT_VERSION"
  57.          shift ;;
  58.       z-- )     # Stop option processing
  59.         shift; break ;;
  60.       z- )    # Use stdin as input.
  61.         break ;;
  62.       z-* )
  63.         /bin/echo "${usage}" 1>&2; exit 1 ;;
  64.       * )
  65.         break ;;
  66.    esac
  67. done
  68.  
  69. TEMPLATES="${AC_MACRODIR}/acconfig.h"
  70. test -r acconfig.h && TEMPLATES="${TEMPLATES} acconfig.h"
  71. MACROFILES="${AC_MACRODIR}/acgeneral.m4 ${AC_MACRODIR}/acspecific.m4"
  72. test -r ${AC_MACRODIR}/aclocal.m4 \
  73.    && MACROFILES="${MACROFILES} ${AC_MACRODIR}/aclocal.m4"
  74. test -r aclocal.m4 && MACROFILES="${MACROFILES} aclocal.m4"
  75. MACROFILES="${print_version} ${MACROFILES}"
  76.  
  77. case $# in
  78.   0) if test -n "$print_version"
  79.        then infile=/dev/null
  80.        else infile=configure.in; fi ;;
  81.   1) infile=$1 ;;
  82.   *) /bin/echo "$usage" >&2; exit 1 ;;
  83. esac
  84.  
  85. # These are the alternate definitions of the acgeneral.m4 macros we want to
  86. # redefine.  They produce strings in the output marked with "@@@" so we can
  87. # easily extract the information we want.  The `#' at the end of the first
  88. # line of each definition seems to be necessary to prevent m4 from eating
  89. # the newline, which makes the @@@ not always be at the beginning of a line.
  90. frob='define([AC_DEFINE],[#
  91. @@@syms="$syms $1"@@@
  92. ])dnl
  93. define([AC_SIZEOF_TYPE],[#
  94. @@@types="$types,$1"@@@
  95. ])dnl
  96. define([AC_HAVE_FUNCS],[#
  97. @@@funcs="$funcs $1"@@@
  98. ])dnl
  99. define([AC_HAVE_HEADERS],[#
  100. @@@headers="$headers $1"@@@
  101. ])dnl
  102. define([AC_CONFIG_HEADER],[#
  103. @@@config_h=$1@@@
  104. ])dnl
  105. define([AC_HAVE_LIBRARY], [#
  106. changequote(/,/)dnl
  107. define(/libname/, dnl
  108. patsubst(patsubst($1, /lib\([^\.]*\)\.a/, /\1/), /-l/, //))dnl
  109. changequote([,])dnl
  110. @@@libs="$libs libname"@@@
  111. # If it was found, we do:
  112. $2
  113. # If it was not found, we do:
  114. $3
  115. ])dnl
  116. '
  117.  
  118. config_h=config.h
  119. syms=
  120. types=
  121. funcs=
  122. headers=
  123. libs=
  124.  
  125. # We extract assignments of SYMS, TYPES, FUNCS, HEADERS, and LIBS from the
  126. # modified autoconf processing of the input file.  The sed hair is
  127. # necessary to win for multi-line macro invocations.
  128. eval "`/bin/echo \"$frob\" \
  129.        | $M4 $MACROFILES - $infile \
  130.        | sed -n -e '
  131.         : again
  132.         /^@@@.*@@@$/s/^@@@\(.*\)@@@$/\1/p
  133.         /^@@@/{
  134.             s/^@@@//p
  135.             n
  136.             s/^/@@@/
  137.             b again
  138.         }'`"
  139.  
  140. test -n "$print_version" && exit 0
  141.  
  142. # Make SYMS newline-separated rather than blank-separated, and remove dups.
  143. syms="`for sym in $syms; do /bin/echo $sym; done | sort | uniq`"
  144.  
  145. if test $# -eq 0; then
  146.   tmpout=autoh$$
  147.   trap "rm -f $tmpout; exit 1" 1 2 15
  148.   exec > $tmpout
  149. fi
  150.  
  151. # Don't write "do not edit" -- it will get copied into the
  152. # config.h, which it's ok to edit.
  153. /bin/echo "/* ${config_h}.in.  Generated automatically from $infile by autoheader.  */"
  154.  
  155. test -f ${config_h}.top && cat ${config_h}.top
  156.  
  157. # This puts each paragraph on its own line, separated by @s.
  158. if test -n "$syms"; then
  159.    # Make sure the boundary of template files is also the boundary
  160.    # of the paragraph.  Extra newlines don't hurt since they will
  161.    # be removed.
  162.    for t in $TEMPLATES; do cat $t; /bin/echo; /bin/echo; done |
  163.    # The sed script is suboptimal because it has to take care of
  164.    # some broken seds (e.g. AIX) that remove '\n' from the
  165.    # pattern/hold space if the line is empty. (junio@twinsun.com).
  166.    sed -n -e '
  167.     /^[     ]*$/{
  168.         x
  169.         s/\n/@/g
  170.         p
  171.         s/.*/@/
  172.         x
  173.     }
  174.     H' | sed -e 's/@@*/@/g' |
  175.    # Select each paragraph that refers to a symbol we picked out above.
  176.    fgrep "$syms" |
  177.    tr @ \\012
  178. fi
  179.  
  180. /bin/echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
  181.   test -z "$ctype" && continue
  182.   # Solaris 2.3 tr rejects noncontiguous characters in character classes.
  183.   sym="`/bin/echo "${ctype}" | tr '[a-z] *' '[A-Z]_P'`"
  184.   /bin/echo "
  185. /* The number of bytes in a ${ctype}.  */
  186. #undef SIZEOF_${sym}"
  187. done
  188.  
  189. for func in `for x in $funcs; do /bin/echo $x; done | sort | uniq`; do
  190.   sym="`/bin/echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  191.   /bin/echo "
  192. /* Define if you have ${func}.  */
  193. #undef HAVE_${sym}"
  194. done
  195.  
  196. for header in `for x in $headers; do /bin/echo $x; done | sort | uniq`; do
  197.   sym="`/bin/echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  198.   /bin/echo "
  199. /* Define if you have the <${header}> header file.  */
  200. #undef HAVE_${sym}"
  201. done
  202.  
  203. for lib in `for x in $libs; do /bin/echo $x; done | sort | uniq`; do
  204.   sym="`/bin/echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  205.   /bin/echo "
  206. /* Define if you have the ${lib} library (-l${lib}).  */
  207. #undef HAVE_LIB${sym}"
  208. done
  209.  
  210. test -f ${config_h}.bot && cat ${config_h}.bot
  211.  
  212. status=0
  213.  
  214. for sym in $syms; do
  215.   if fgrep $sym $TEMPLATES >/dev/null; then
  216.     : # All is well.
  217.   else
  218.     /bin/echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
  219.     status=1
  220.   fi
  221. done
  222.  
  223. if test $# -eq 0; then
  224.   if test $status -eq 0; then
  225.     if cmp -s $tmpout ${config_h}.in; then
  226.       rm -f $tmpout
  227.     else
  228.       mv -f $tmpout ${config_h}.in
  229.     fi
  230.   else
  231.     rm -f $tmpout
  232.   fi
  233. fi
  234.  
  235. exit $status
  236.