autoconf-2.13-mawk
[platform/upstream/autoconf213.git] / autoreconf.sh
1 #! @SHELL@
2 # autoreconf - remake all Autoconf configure scripts in a directory tree
3 # Copyright (C) 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., 59 Temple Place - Suite 330, Boston, MA
18 # 02111-1307, USA.
19
20 usage="\
21 Usage: autoreconf [-f] [-h] [--help] [-m dir] [--macrodir=dir]
22        [-l dir] [--localdir=dir] [--force] [--verbose] [--version]
23        [--cygnus] [--foreign] [--gnits] [--gnu] [-i] [--include-deps]"
24
25 localdir=
26 verbose=no
27 show_version=no
28 force=no
29 automake_mode=--gnu
30 automake_deps=
31
32 test -z "$AC_MACRODIR" && AC_MACRODIR=@datadir@
33
34 while test $# -gt 0; do
35   case "$1" in 
36   -h | --help | --h*)
37     echo "$usage"; exit 0 ;;
38   --localdir=* | --l*=* )
39     localdir="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
40     shift ;;
41   -l | --localdir | --l*)
42     shift
43     test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
44     localdir="${1}"
45     shift ;;
46   --macrodir=* | --m*=* )
47     AC_MACRODIR="`echo \"$1\" | sed -e 's/^[^=]*=//'`"
48     shift ;;
49   -m | --macrodir | --m*)
50     shift
51     test $# -eq 0 && { echo "$usage" 1>&2; exit 1; }
52     AC_MACRODIR="$1"
53     shift ;;
54   --verbose | --verb*)
55     verbose=yes; shift ;;
56   -f | --force)
57     force=yes; shift ;;
58   --version | --vers*)
59     show_version=yes; shift ;;
60   --cygnus | --foreign | --gnits | --gnu)
61     automake_mode=$1; shift ;;
62   --include-deps | -i)
63     automake_deps=$1; shift ;;
64   --)     # Stop option processing.
65     shift; break ;;
66   -*) echo "$usage" 1>&2; exit 1 ;;
67   *) break ;;
68   esac
69 done
70
71 if test $show_version = yes; then
72   version=`sed -n 's/define.AC_ACVERSION.[      ]*\([0-9.]*\).*/\1/p' \
73     $AC_MACRODIR/acgeneral.m4`
74   echo "Autoconf version $version"
75   exit 0
76 fi
77
78 if test $# -ne 0; then
79   echo "$usage" 1>&2; exit 1
80 fi
81
82 # The paths to the autoconf and autoheader scripts, at the top of the tree.
83 top_autoconf=`echo $0|sed s%autoreconf%autoconf%`
84 top_autoheader=`echo $0|sed s%autoreconf%autoheader%`
85
86 # Make a list of directories to process.
87 # The xargs grep filters out Cygnus configure.in files.
88 find . -name configure.in -print |
89 xargs grep -l AC_OUTPUT |
90 sed 's%/configure\.in$%%; s%^./%%' |
91 while read dir; do
92   (
93   cd $dir || continue
94
95   case "$dir" in
96   .) dots= ;;
97   *) # A "../" for each directory in /$dir.
98      dots=`echo /$dir|sed 's%/[^/]*%../%g'` ;;
99   esac
100
101   case "$0" in
102   /*)  autoconf=$top_autoconf; autoheader=$top_autoheader ;;
103   */*) autoconf=$dots$top_autoconf; autoheader=$dots$top_autoheader ;;
104   *)   autoconf=$top_autoconf; autoheader=$top_autoheader ;;
105   esac
106
107   case "$AC_MACRODIR" in
108   /*)  macrodir_opt="--macrodir=$AC_MACRODIR" ;;
109   *)   macrodir_opt="--macrodir=$dots$AC_MACRODIR" ;;
110   esac
111
112   case "$localdir" in
113   "")  localdir_opt=
114        aclocal=aclocal.m4 ;;
115   /*)  localdir_opt="--localdir=$localdir"
116        aclocal=$localdir/aclocal.m4 ;;
117   *)   localdir_opt="--localdir=$dots$localdir"
118        aclocal=$dots$localdir/aclocal.m4 ;;
119   esac
120
121   # Regenerate aclocal.m4 if necessary.  FIXME: if aclocal searches
122   # nonstandard directories, we need to deal with that here.  The
123   # easiest way is to move this info into configure.in.
124   run_aclocal=no
125   if test -f "$aclocal" &&
126      grep 'generated automatically by aclocal' $aclocal > /dev/null
127   then
128      run_aclocal=yes
129   else
130      if test -f `echo $aclocal | sed 's,/*[^/]*$,,;s,^$,.,'`/acinclude.m4
131      then
132         run_aclocal=yes
133      fi
134   fi
135   if test $run_aclocal = yes
136   then
137      if test $force = no &&
138         ls -lt configure.in $aclocal \
139                `echo $aclocal | sed 's,/*[^/]*$,,;s,^$,.,'`/acinclude.m4 |
140           sed 1q |
141           grep 'aclocal\.m4$' > /dev/null
142      then
143         :
144      else
145         test $verbose = yes && echo running aclocal in $dir, creating $aclocal
146         aclocal --output=$aclocal -I `echo $aclocal | sed 's,/*[^/]*$,,;s,^$,.,'`
147      fi
148   fi
149
150   # Re-run automake if required.  Assumes that there is a Makefile.am
151   # in the topmost directory.
152   if test -f Makefile.am
153   then
154      amforce=
155      test $force = no && amforce=--no-force
156      test $verbose = yes && echo running automake`test x"$amforce" = x || echo " ($amforce)"` in $dir
157      automake $amforce $automake_mode $automake_deps
158   fi
159
160   test ! -f $aclocal && aclocal=
161
162   if test $force = no && test -f configure &&
163     ls -lt configure configure.in $aclocal | sed 1q |
164       grep 'configure$' > /dev/null
165   then
166     :
167   else
168     test $verbose = yes && echo running autoconf in $dir
169     $autoconf $macrodir_opt $localdir_opt
170   fi
171
172   if grep 'A[CM]_CONFIG_HEADER' configure.in >/dev/null; then
173     templates=`sed -n '/A[CM]_CONFIG_HEADER/ {
174         s%[^#]*A[CM]_CONFIG_HEADER[     ]*(\([^)]*\).*%\1%
175         p
176         q
177       }' configure.in`
178     tcount=`set -- $templates; echo $#`
179     template=`set -- $templates; echo $1 | sed '
180         s/.*://
181         t colon
182         s/$/.in/
183         : colon
184         s/:.*//
185       '`
186     stamp=`echo $template | sed 's,/*[^/]*$,,;s,^$,.,'`/stamp-h`test "$tcount" -gt 1 && echo "$tcount"`.in
187     if test ! -f "$template" || grep autoheader "$template" >/dev/null; then
188       if test $force = no && test -f $template &&
189          ls -lt $template configure.in $aclocal $stamp 2>/dev/null \
190                 `echo $localdir_opt | sed -e 's/--localdir=//' \
191                                           -e '/./ s%$%/%'`acconfig.h |
192            sed 1q | egrep "$template$|$stamp$" > /dev/null
193       then
194         :
195       else
196         test $verbose = yes && echo running autoheader in $dir
197         $autoheader $macrodir_opt $localdir_opt && 
198         { test $verbose != yes || echo touching $stamp; } &&
199         touch $stamp
200       fi
201     fi
202   fi
203   )
204 done