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