home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / bin / autoheader < prev    next >
Text File  |  1994-12-22  |  7KB  |  251 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="\
  26. Usage: autoheader [-h] [--help] [-m dir] [--macrodir=dir] 
  27.        [-l dir] [--localdir=dir] [--version] [template-file]" 
  28.  
  29. # NLS nuisances.
  30. # Only set `LANG' and `LC_ALL' to "C" if already set.
  31. # These must not be set unconditionally because not all systems understand
  32. # e.g. LANG=C (notably SCO).
  33. if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
  34. if test "${LANG+set}"   = set; then LANG=C;   export LANG;   fi
  35.  
  36. test -z "${AC_MACRODIR}" && AC_MACRODIR=/gnu/lib/autoconf
  37. test -z "${M4}" && M4=/bin/m4
  38. case "${M4}" in
  39. /*) # Handle the case that m4 has moved since we were configured.
  40.     # It may have been found originally in a build directory.
  41.     test -f "${M4}" || M4=m4 ;;
  42. esac
  43.  
  44. localdir=.
  45. show_version=no
  46.  
  47. while test $# -gt 0 ; do
  48.    case "${1}" in 
  49.       -h | --help | --h* )
  50.          /bin/echo "${usage}"; exit 0 ;;
  51.       --localdir=* | --l*=* )
  52.          localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
  53.          shift ;;
  54.       -l | --localdir | --l*)
  55.          shift
  56.          test $# -eq 0 && { /bin/echo "${usage}" 1>&2; exit 1; }
  57.          localdir="${1}"
  58.          shift ;;
  59.       --macrodir=* | --m*=* )
  60.          AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
  61.          shift ;;
  62.       -m | --macrodir | --m* ) 
  63.          shift
  64.          test $# -eq 0 && { /bin/echo "${usage}" 1>&2; exit 1; }
  65.          AC_MACRODIR="${1}"
  66.          shift ;;
  67.       --version | --v* )
  68.          show_version=yes; shift ;;
  69.       -- )     # Stop option processing
  70.         shift; break ;;
  71.       - )    # Use stdin as input.
  72.         break ;;
  73.       -* )
  74.         /bin/echo "${usage}" 1>&2; exit 1 ;;
  75.       * )
  76.         break ;;
  77.    esac
  78. done
  79.  
  80. if test $show_version = yes; then
  81.   version=`sed -n 's/define.AC_ACVERSION.[     ]*\([0-9.]*\).*/\1/p' \
  82.     $AC_MACRODIR/acgeneral.m4`
  83.   echo "Autoconf version $version"
  84.   exit 0
  85. fi
  86.  
  87. TEMPLATES="${AC_MACRODIR}/acconfig.h"
  88. test -r $localdir/acconfig.h && TEMPLATES="${TEMPLATES} $localdir/acconfig.h"
  89.  
  90. case $# in
  91.   0) infile=configure.in ;;
  92.   1) infile=$1 ;;
  93.   *) /bin//bin/echo "$usage" >&2; exit 1 ;;
  94. esac
  95.  
  96. config_h=config.h
  97. syms=
  98. types=
  99. funcs=
  100. headers=
  101. libs=
  102.  
  103. if test "$localdir" != .; then
  104.   use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
  105. else
  106.   use_localdir=
  107. fi
  108.  
  109. # Use the frozen version of Autoconf if available.
  110. r= f=
  111. # Some non-GNU m4's don't reject the --help option, so give them /dev/null.
  112. case `$M4 --help < /dev/null 2>&1` in
  113. *reload-state*) test -r $AC_MACRODIR/autoheader.m4f && { r=--reload f=f; } ;;
  114. *traditional*) ;;
  115. *) echo Autoconf requires GNU m4 1.1 or later >&2; exit 1 ;;
  116. esac
  117.  
  118. # Extract assignments of SYMS, TYPES, FUNCS, HEADERS, and LIBS from the
  119. # modified autoconf processing of the input file.  The sed hair is
  120. # necessary to win for multi-line macro invocations.
  121. eval "`$M4 -I$AC_MACRODIR $use_localdir $r autoheader.m4$f $infile |
  122.        sed -n -e '
  123.         : again
  124.         /^@@@.*@@@$/s/^@@@\(.*\)@@@$/\1/p
  125.         /^@@@/{
  126.             s/^@@@//p
  127.             n
  128.             s/^/@@@/
  129.             b again
  130.         }'`"
  131.  
  132. # Make SYMS newline-separated rather than blank-separated, and remove dups.
  133. # Start each symbol with a blank (to match the blank after "#undef")
  134. # to reduce the possibility of mistakenly matching another symbol that
  135. # is a substring of it.
  136. syms="`for sym in $syms; do /bin/echo $sym; done | sort | uniq | sed 's@^@ @'`"
  137.  
  138. if test $# -eq 0; then
  139.   tmpout=autoh$$
  140.   trap "rm -f $tmpout; exit 1" 1 2 15
  141.   exec > $tmpout
  142. fi
  143.  
  144. # Support "outfile[:infile]", defaulting infile="outfile.in".
  145. case "$config_h" in
  146. *:*) config_h_in=`/bin/echo "$config_h"|sed 's%.*:%%'`
  147.      config_h=`/bin/echo "$config_h"|sed 's%:.*%%'` ;;
  148. *) config_h_in="${config_h}.in" ;;
  149. esac
  150.  
  151. # Don't write "do not edit" -- it will get copied into the
  152. # config.h, which it's ok to edit.
  153. echo "/* ${config_h_in}.  Generated automatically from $infile by autoheader.  */"
  154.  
  155. test -r ${config_h}.top && cat ${config_h}.top
  156. test -r $localdir/acconfig.h &&
  157.   grep @TOP@ $localdir/acconfig.h >/dev/null &&
  158.   sed '/@TOP@/,$d' $localdir/acconfig.h
  159.  
  160. # This puts each template paragraph on its own line, separated by @s.
  161. if test -n "$syms"; then
  162.    # Make sure the boundary of template files is also the boundary
  163.    # of the paragraph.  Extra newlines don't hurt since they will
  164.    # be removed.
  165.    for t in $TEMPLATES; do cat $t; /bin/echo; /bin/echo; done |
  166.    # The sed script is suboptimal because it has to take care of
  167.    # some broken seds (e.g. AIX) that remove '\n' from the
  168.    # pattern/hold space if the line is empty. (junio@twinsun.com).
  169.    sed -n -e '
  170.     /^[     ]*$/{
  171.         x
  172.         s/\n/@/g
  173.         p
  174.         s/.*/@/
  175.         x
  176.     }
  177.     H' | sed -e 's/@@*/@/g' |
  178.    # Select each paragraph that refers to a symbol we picked out above.
  179.    fgrep "$syms" |
  180.    tr @ \\012
  181. fi
  182.  
  183. /bin/echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
  184.   test -z "$ctype" && continue
  185.   # Solaris 2.3 tr rejects noncontiguous characters in character classes.
  186.   sym="`/bin/echo "${ctype}" | tr '[a-z] *' '[A-Z]_P'`"
  187.   echo "
  188. /* The number of bytes in a ${ctype}.  */
  189. #undef SIZEOF_${sym}"
  190. done
  191.  
  192. # /bin/sh on the Alpha gives `for' a random value if $funcs is empty.
  193. if test -n "$funcs"; then
  194.   for func in `for x in $funcs; do /bin/echo $x; done | sort | uniq`; do
  195.     sym="`/bin/echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  196.     echo "
  197. /* Define if you have the ${func} function.  */
  198. #undef HAVE_${sym}"
  199.   done
  200. fi
  201.  
  202. if test -n "$headers"; then
  203.   for header in `for x in $headers; do /bin/echo $x; done | sort | uniq`; do
  204.     sym="`/bin/echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  205.     echo "
  206. /* Define if you have the <${header}> header file.  */
  207. #undef HAVE_${sym}"
  208.   done
  209. fi
  210.  
  211. if test -n "$libs"; then
  212.   for lib in `for x in $libs; do /bin/echo $x; done | sort | uniq`; do
  213.    sym="`/bin/echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  214.     echo "
  215. /* Define if you have the ${lib} library (-l${lib}).  */
  216. #undef HAVE_LIB${sym}"
  217.   done
  218. fi
  219.  
  220. test -r $localdir/acconfig.h &&
  221.   grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
  222.   sed '1,/@BOTTOM@/d' $localdir/acconfig.h
  223. test -f ${config_h}.bot && cat ${config_h}.bot
  224.  
  225. status=0
  226.  
  227. if test -n "$syms"; then
  228.   for sym in $syms; do
  229.     if fgrep $sym $TEMPLATES >/dev/null; then
  230.       : # All is well.
  231.     else
  232.       /bin/echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
  233.       status=1
  234.     fi
  235.   done
  236. fi
  237.  
  238. if test $# -eq 0; then
  239.   if test $status -eq 0; then
  240.     if cmp -s $tmpout ${config_h_in}; then
  241.       rm -f $tmpout
  242.     else
  243.       mv -f $tmpout ${config_h_in}
  244.     fi
  245.   else
  246.     rm -f $tmpout
  247.   fi
  248. fi
  249.  
  250. exit $status
  251.