mdw-setup: Fix for constructing Makefile.am from m4 source.
[cfd] / mkaclocal.in
1 #! /bin/sh
2 # -*-sh-*-
3 #
4 # $Id: mkaclocal.in,v 1.2 1997/09/11 09:06:33 mdw Exp $
5 #
6 # Create an `aclocal.m4' file containing the right macros.
7 #
8 # (c) 1997 Mark Wooding
9 #
10
11 #----- Licensing notice -----------------------------------------------------
12 #
13 # This file is part of the Common Files Distribution (`common').
14 #
15 # `Common' is free software; you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation; either version 2 of the License, or
18 # (at your option) any later version.
19 #
20 # `Common' is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with `common'; if not, write to the Free Software Foundation,
27 # Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
29 set -e
30
31 # --- Configuration variables ---
32
33 prefix=@prefix@
34 exec_prefix=@exec_prefix@
35 bindir=@bindir@
36 datadir=@datadir@/@PACKAGE@
37
38 # --- Parse command line ---
39
40 mode=x
41 out="aclocal.m4"
42 in="configure.in"
43 stdlib=true
44
45 while [ $# -gt 0 ]; do
46 case $1 in
47 -h | --h | --he | --hel | --help)
48 cat <<EOF
49 Usage: mkaclocal [-lx] [-c CONFIG] [-o OUTPUT] [LIBRARY...]
50
51 In \`extract' mode (-x, default), constructs an \`aclocal.m4' file containing
52 the right macros for the \`configure.in' script CONFIG (by default this is
53 \`configure.in'). The output is written to OUTPUT, or \`aclocal.m4' if none
54 was specified.
55
56 In addition to libraries specified on the command line, the files
57 \`aclocal.glob' and \`aclocal.site' contained in the shared file repository,
58 and \`aclocal.lib' in the current directory are also searched.
59
60 If \`aclocal.lib' contains the string \`*@--TOP--@*', the preceding text is
61 written at the top of any output file generated.
62
63 In \`list' mode (-l), lists the macros defined in the various libraries.
64
65 Options:
66
67 -h, --help Print this help text.
68 -v, --version Print the program's version number.
69 -l, --list List chunks defined in text libraries.
70 -x, --extract Extract chunks from text libraries (default).
71 -n, --no-stdlib Don't read from the standard libraries.
72 -c, --config=CONFIG Read CONFIG, not \`configure.in', to decide which
73 macros need extracting.
74 -o, --output=OUTPUT Extract chunks to OUTPUT, not \`aclocal.m4'.
75 EOF
76 exit 0
77 ;;
78 -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
79 version=`echo '$Revision: 1.2 $' |
80 sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'`
81 echo "mkaclocal $version; Common Files Distribution version @VERSION@"
82 exit 0
83 ;;
84 -c | --c | --co | --con | --conf | --confi | --config)
85 in="$2";
86 shift
87 ;;
88 -c*)
89 in=`echo $1 | sed -e 's/^-[a-z]//'`
90 ;;
91 --c=* | --co=* | --con=* | --conf=* | --confi=* | --config=*)
92 in=`echo $1 | sed -e 's/^--[a-z]*=//'`
93 ;;
94 -o | --o | --ou | --out | --outp | --outpu | --output)
95 out="$2";
96 shift
97 ;;
98 -o*)
99 out=`echo $1 | sed -e 's/^-[a-z]//'`
100 ;;
101 --o=* | --ou=* | --out=* | --outp=* | --outpu=* | --output=*)
102 out=`echo $1 | sed -e 's/^--[a-z]*=//'`
103 ;;
104 -n | --no-s* | --no-st* | --no-std* | --no-stdl* | \
105 --no-stdli* | --no-stdlib)
106 stdlib=false
107 ;;
108 -l | --l | --li | --lis | --list)
109 mode=l
110 ;;
111 -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract)
112 mode=x
113 ;;
114 --)
115 shift
116 break
117 ;;
118 -)
119 break
120 ;;
121 -*)
122 echo "mkaclocal: unknown option \`$1'" >&2
123 exit 1
124 ;;
125 *)
126 break
127 ;;
128 esac
129 shift
130 done
131
132 if $stdlib; then
133 set -- \
134 `test -r $datadir/aclocal.site && echo "$datadir/aclocal.site"` \
135 `test -r ./aclocal.lib && echo "./aclocal.lib"` \
136 "$@"
137 else
138 set -- \
139 `test -r ./aclocal.lib && echo "./aclocal.lib"` \
140 "$@"
141 fi
142
143 # --- Now do the job ---
144
145 case $mode in
146
147 l)
148 $bindir/txtlib -l "$@" | sort | uniq
149 ;;
150
151 x)
152 t=${TMPDIR-/tmp}/mkaclocal.$$
153 doaclocal=false
154 if $stdlib && [ $out = aclocal.m4 ]; then
155 doaclocal=true
156 out=acinclude.m4
157 fi
158 if mkdir -m700 $t; then :
159 else
160 echo >&2 "mkaclocal: cculd not create temporary directory"
161 exit 1
162 fi
163 echo -NOTICE- >$t/a
164 created=no
165
166 $bindir/txtlib -l "$@" | sort | uniq | while read LINE; do
167 echo "/$LINE/ i\\
168 $LINE"
169 done >$t/sed
170
171 until { echo -NOTICE-; sed -n -f $t/sed $in; } | sort | uniq >$t/b
172 cmp -s $t/a $t/b
173 do
174 $bindir/txtlib "$@" <$t/b >$out.tmp
175 in=$out.tmp
176 mv $t/b $t/a
177 created=yes
178 done
179
180 if [ "$created" = "yes" ]; then
181 { test -r ./aclocal.lib &&
182 grep "\*@--TOP--@\*" ./aclocal.lib >/dev/null &&
183 sed -e "/\*@--TOP--@\*/, $ d" ./aclocal.lib
184 cat $out.tmp
185 } >$out.new
186 mv $out.new $out
187 else
188 rm -f $out
189 fi
190
191 rm -fr $t $out.tmp
192 if $doaclocal; then aclocal; fi
193 ;;
194 esac