1#! /bin/sh
2# @(#)autoconf	1.8 09/04/19 Copyright 1999-2009 J. Schilling
3#
4# autoconf -- create `configure' using m4 macros
5# Copyright (C) 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
6
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2, or (at your option)
10# any later version.
11
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20# 02111-1307, USA.
21
22# If given no args, create `configure' from template file `configure.in'.
23# With one arg, create a configure script on standard output from
24# the given template file.
25
26usage="\
27Usage: autoconf [-h] [--help] [-m dir] [--macrodir=dir]
28       [-l dir] [--localdir=dir] [--version] [template-file]"
29
30# NLS nuisances.
31# Only set these to C if already set.  These must not be set unconditionally
32# because not all systems understand e.g. LANG=C (notably SCO).
33# Fixing LC_MESSAGES prevents Solaris sh from translating var values in `set'!
34# Non-C LC_CTYPE values break the ctype check.
35if test "${LANG+set}"   = set; then LANG=C;   export LANG;   fi
36if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi
37if test "${LC_MESSAGES+set}" = set; then LC_MESSAGES=C; export LC_MESSAGES; fi
38if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
39
40: ${AC_MACRODIR=.}
41
42: ${M4=/usr/bin/gm4}
43$M4 < /dev/null 2> /dev/null || M4=/opt/sfw/bin/gm4
44$M4 < /dev/null 2> /dev/null || M4=/usr/sfw/bin/gm4
45$M4 < /dev/null 2> /dev/null || M4=/opt/csw/bin/gm4
46$M4 < /dev/null 2> /dev/null || M4=gm4
47$M4 < /dev/null 2> /dev/null || M4=m4
48
49: ${AWK=/usr/bin/gawk}
50$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=/opt/sfw/bin/gawk
51$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=/usr/sfw/bin/gawk
52$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=/opt/csw/bin/gawk
53$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=gawk
54$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=nawk
55$AWK '{print 1}' < /dev/null 2> /dev/null || AWK=awk
56
57case "${M4}" in
58/*) # Handle the case that m4 has moved since we were configured.
59    # It may have been found originally in a build directory.
60    test -f "${M4}" || M4=/usr/sfw/bin/gm4
61    test -f "${M4}" || M4=m4 ;;
62esac
63
64: ${TMPDIR=/tmp}
65tmpout=${TMPDIR}/acout.$$
66localdir=
67show_version=no
68
69while test $# -gt 0 ; do
70   case "${1}" in
71      -h | --help | --h* )
72         echo "${usage}" 1>&2; exit 0 ;;
73      --localdir=* | --l*=* )
74         localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
75         shift ;;
76      -l | --localdir | --l*)
77         shift
78         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
79         localdir="${1}"
80         shift ;;
81      --macrodir=* | --m*=* )
82         AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
83         shift ;;
84      -m | --macrodir | --m* )
85         shift
86         test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
87         AC_MACRODIR="${1}"
88         shift ;;
89      --version | --v* )
90         show_version=yes; shift ;;
91      -- )     # Stop option processing
92        shift; break ;;
93      - )	# Use stdin as input.
94        break ;;
95      -* )
96        echo "${usage}" 1>&2; exit 1 ;;
97      * )
98        break ;;
99   esac
100done
101
102if test $show_version = yes; then
103  version=`sed -n 's/define.AC_ACVERSION.[ 	]*\([0-9.]*\).*/\1/p' \
104    $AC_MACRODIR/acgeneral.m4`
105  echo "Autoconf version $version"
106  exit 0
107fi
108
109case $# in
110  0) infile=configure.in ;;
111  1) infile="$1" ;;
112  *) echo "$usage" >&2; exit 1 ;;
113esac
114
115trap 'rm -f $tmpin $tmpout; exit 1' 1 2 15
116
117tmpin=${TMPDIR}/acin.$$ # Always set this, to avoid bogus errors from some rm's.
118if test z$infile = z-; then
119  infile=$tmpin
120  cat > $infile
121elif test ! -r "$infile"; then
122  echo "autoconf: ${infile}: No such file or directory" >&2
123  exit 1
124fi
125
126if test -n "$localdir"; then
127  use_localdir="-I$localdir -DAC_LOCALDIR=$localdir"
128else
129  use_localdir=
130fi
131
132# Use the frozen version of Autoconf if available.
133r= f=
134# Some non-GNU m4's don't reject the --help option, so give them /dev/null.
135case `$M4 --help < /dev/null 2>&1` in
136*reload-state*) test -r $AC_MACRODIR/autoconf.m4f && { r=--reload f=f; } ;;
137*traditional*) ;;
138*) echo Autoconf requires GNU m4 1.1 or later >&2; rm -f $tmpin; exit 1 ;;
139esac
140
141$M4 -I$AC_MACRODIR $use_localdir $r autoconf.m4$f $infile > $tmpout ||
142  { rm -f $tmpin $tmpout; exit 2; }
143
144# You could add your own prefixes to pattern if you wanted to check for
145# them too, e.g. pattern='\(AC_\|ILT_\)', except that UNIX sed doesn't do
146# alternation.
147pattern="AC_"
148
149status=0
150if grep "^[^#]*${pattern}" $tmpout > /dev/null 2>&1; then
151  echo "autoconf: Undefined macros:" >&2
152  sed -n "s/^[^#]*\\(${pattern}[_A-Za-z0-9]*\\).*/\\1/p" $tmpout |
153    while read macro; do
154      grep -n "^[^#]*$macro" $infile /dev/null
155      test $? -eq 1 && echo >&2 "***BUG in Autoconf--please report*** $macro"
156    done | sort -u >&2
157  status=1
158fi
159
160if test $# -eq 0; then
161  exec 4> configure; chmod +x configure
162else
163  exec 4>&1
164fi
165
166# Put the real line numbers into configure to make config.log more helpful.
167$AWK '
168/__oline__/ { printf "%d:", NR + 1 }
169           { print }
170' $tmpout | sed '
171/__oline__/s/^\([0-9][0-9]*\):\(.*\)__oline__/\2\1/
172' >&4
173
174rm -f $tmpout
175
176exit $status
177