home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / autoconf-2.10-src.tgz / tar.out / fsf / autoconf / autoheader.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1996-09-24  |  8KB  |  252 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=@datadir@
  37. test -z "${M4}" && M4=@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.          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 && { 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 && { 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.         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.   *) 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 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=`echo "$config_h"|sed 's%.*:%%'`
  147.      config_h=`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; echo; 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. echo "$types" | tr , \\012 | sort | uniq | while read ctype; do
  184.   test -z "$ctype" && continue
  185.   sym="`echo "${ctype}" | tr 'abcdefghijklmnopqrstuvwxyz *' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_P'`"
  186.   echo "
  187. /* The number of bytes in a ${ctype}.  */
  188. #undef SIZEOF_${sym}"
  189. done
  190.  
  191. # /bin/sh on the Alpha gives `for' a random value if $funcs is empty.
  192. if test -n "$funcs"; then
  193.   for func in `for x in $funcs; do echo $x; done | sort | uniq`; do
  194.     sym="`echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
  195.     echo "
  196. /* Define if you have the ${func} function.  */
  197. #undef HAVE_${sym}"
  198.   done
  199. fi
  200.  
  201. if test -n "$headers"; then
  202.   for header in `for x in $headers; do echo $x; done | sort | uniq`; do
  203.  
  204.     sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
  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 echo $x; done | sort | uniq`; do
  213.    sym="`echo ${lib} | sed 's/[^a-zA-Z0-9_]/_/g' | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`"
  214.     echo "
  215. /* Define if you have the ${lib} library (-l${lib}).  */
  216. #undef HAVE_LIB${sym}"
  217.   done
  218. fi
  219.  
  220. # Handle the case where @BOTTOM@ is the first line of acconfig.h.
  221. test -r $localdir/acconfig.h &&
  222.   grep @BOTTOM@ $localdir/acconfig.h >/dev/null &&
  223.   sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h
  224. test -f ${config_h}.bot && cat ${config_h}.bot
  225.  
  226. status=0
  227.  
  228. if test -n "$syms"; then
  229.   for sym in $syms; do
  230.     if fgrep $sym $TEMPLATES >/dev/null; then
  231.       : # All is well.
  232.     else
  233.       echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
  234.       status=1
  235.     fi
  236.   done
  237. fi
  238.  
  239. if test $# -eq 0; then
  240.   if test $status -eq 0; then
  241.     if cmp -s $tmpout ${config_h_in}; then
  242.       rm -f $tmpout
  243.     else
  244.       mv -f $tmpout ${config_h_in}
  245.     fi
  246.   else
  247.     rm -f $tmpout
  248.   fi
  249. fi
  250.  
  251. exit $status
  252.