chiark / gitweb /
Support Automake's `aclocal' scheme. Deposit Autoconf fragments in
[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 #----- Revision history -----------------------------------------------------
30 #
31 # $Log$
32
33 set -e
34
35 # --- Configuration variables ---
36
37 prefix=@prefix@
38 exec_prefix=@exec_prefix@
39 bindir=@bindir@
40 datadir=@datadir@/@PACKAGE@
41
42 # --- Parse command line ---
43
44 mode=x
45 out="aclocal.m4"
46 in="configure.in"
47 stdlib=true
48
49 while [ $# -gt 0 ]; do
50   case $1 in
51     -h | --h | --he | --hel | --help)
52       cat <<EOF
53 Usage: mkaclocal [-lx] [-c CONFIG] [-o OUTPUT] [LIBRARY...]
54
55 In \`extract' mode (-x, default), constructs an \`aclocal.m4' file containing
56 the right macros for the \`configure.in' script CONFIG (by default this is
57 \`configure.in').  The output is written to OUTPUT, or \`aclocal.m4' if none
58 was specified.
59
60 In addition to libraries specified on the command line, the files
61 \`aclocal.glob' and \`aclocal.site' contained in the shared file repository,
62 and \`aclocal.lib' in the current directory are also searched.
63
64 If \`aclocal.lib' contains the string \`*@--TOP--@*', the preceding text is
65 written at the top of any output file generated.
66
67 In \`list' mode (-l), lists the macros defined in the various libraries.
68
69 Options:
70
71 -h, --help              Print this help text.
72 -v, --version           Print the program's version number.
73 -l, --list              List chunks defined in text libraries.
74 -x, --extract           Extract chunks from text libraries (default).
75 -n, --no-stdlib         Don't read from the standard libraries.
76 -c, --config=CONFIG     Read CONFIG, not \`configure.in', to decide which
77                         macros need extracting.
78 -o, --output=OUTPUT     Extract chunks to OUTPUT, not \`aclocal.m4'.
79 EOF
80       exit 0
81       ;;
82     -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
83       version=`echo '$Revision: 1.2 $' |
84         sed -n -e 's;^.*: \([0-9.]*\) *\\$;\1;p'`
85       echo "mkaclocal $version; Common Files Distribution version @VERSION@"
86       exit 0
87       ;;
88     -c | --c | --co | --con | --conf | --confi | --config)
89       in="$2";
90       shift
91       ;;
92     -c*)
93       in=`echo $1 | sed -e 's/^-[a-z]//'`
94       ;;
95     --c=* | --co=* | --con=* | --conf=* | --confi=* | --config=*)
96       in=`echo $1 | sed -e 's/^--[a-z]*=//'`
97       ;;
98     -o | --o | --ou | --out | --outp | --outpu | --output)
99       out="$2";
100       shift
101       ;;
102     -o*)
103       out=`echo $1 | sed -e 's/^-[a-z]//'`
104       ;;
105     --o=* | --ou=* | --out=* | --outp=* | --outpu=* | --output=*)
106       out=`echo $1 | sed -e 's/^--[a-z]*=//'`
107       ;;
108     -n | --no-s* | --no-st* | --no-std* | --no-stdl* | \
109     --no-stdli* | --no-stdlib)
110       stdlib=false
111       ;;
112     -l | --l | --li | --lis | --list)
113       mode=l
114       ;;
115     -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract)
116       mode=x
117       ;;
118     --)
119       shift
120       break
121       ;;
122     -)
123       break
124       ;;
125     -*)
126       echo "mkaclocal: unknown option \`$1'" >&2
127       exit 1
128       ;;
129     *)
130       break
131       ;;
132   esac
133   shift
134 done
135
136 if $stdlib; then
137   set -- \
138     `test -r $datadir/aclocal.site && echo "$datadir/aclocal.site"` \
139     `test -r ./aclocal.lib && echo "./aclocal.lib"` \
140     "$@"
141 else
142   set -- \
143     `test -r ./aclocal.lib && echo "./aclocal.lib"` \
144     "$@"
145 fi
146
147 # --- Now do the job ---
148
149 case $mode in
150
151   l)
152     $bindir/txtlib -l "$@" | sort | uniq
153     ;;
154
155   x)
156     t=${TMPDIR-/tmp}/mkaclocal.$$
157     doaclocal=false
158     if $stdlib && [ $out = aclocal.m4 ]; then
159       doaclocal=true
160       out=acinclude.m4
161     fi
162     if mkdir -m700 $t; then :
163     else
164       echo >&2 "mkaclocal: cculd not create temporary directory"
165       exit 1
166     fi
167     echo -NOTICE- >$t/a
168     created=no
169
170     $bindir/txtlib -l "$@" | sort | uniq | while read LINE; do
171       echo "/$LINE/ i\\
172 $LINE"
173     done >$t/sed
174
175     until { echo -NOTICE-; sed -n -f $t/sed $in; } | sort | uniq >$t/b
176           cmp -s $t/a $t/b
177     do
178       $bindir/txtlib "$@" <$t/b >$out.tmp
179       in=$out.tmp
180       mv $t/b $t/a
181       created=yes
182     done
183
184     if [ "$created" = "yes" ]; then
185       { test -r ./aclocal.lib &&
186           grep "\*@--TOP--@\*" ./aclocal.lib >/dev/null &&
187           sed -e "/\*@--TOP--@\*/, $ d" ./aclocal.lib
188         cat $out.tmp
189       } >$out.new
190       mv $out.new $out
191     else
192       rm -f $out
193     fi
194
195     rm -fr $t $out.tmp
196     if $doaclocal; then aclocal; fi
197     ;;
198 esac