b91e2391 |
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 | |
46 | while [ $# -gt 0 ]; do |
47 | case $1 in |
48 | -h | --h | --he | --hel | --help) |
49 | cat <<EOF |
50 | Usage: mkaclocal [-lx] [-c CONFIG] [-o OUTPUT] [LIBRARY...] |
51 | |
52 | In \`extract' mode (-x, default), constructs an \`aclocal.m4' file containing |
53 | the right macros for the \`configure.in' script CONFIG (by default this is |
54 | \`configure.in'). The output is written to OUTPUT, or \`aclocal.m4' if none |
55 | was specified. |
56 | |
57 | In addition to libraries specified on the command line, the files |
58 | \`aclocal.glob' and \`aclocal.site' contained in the shared file repository, |
59 | and \`aclocal.lib' in the current directory are also searched. |
60 | |
61 | If \`aclocal.lib' contains the string \`*@--TOP--@*', the preceding text is |
62 | written at the top of any output file generated. |
63 | |
64 | In \`list' mode (-l), lists the macros defined in the various libraries. |
65 | |
66 | Options: |
67 | |
68 | -h, --help Print this help text. |
69 | -v, --version Print the program's version number. |
70 | -l, --list List chunks defined in text libraries. |
71 | -x, --extract Extract chunks from text libraries (default). |
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 "txtlib $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 | -l | --l | --li | --lis | --list) |
105 | mode=l |
106 | ;; |
107 | -x | --e | --ex | --ext | --extr | --extra | --extrac | --extract) |
108 | mode=x |
109 | ;; |
110 | --) |
111 | shift |
112 | break |
113 | ;; |
114 | -) |
115 | break |
116 | ;; |
117 | -*) |
118 | echo "mkaclocal: unknown option \`$1'" >&2 |
119 | exit 1 |
120 | ;; |
121 | *) |
122 | break |
123 | ;; |
124 | esac |
125 | shift |
126 | done |
127 | |
128 | set \ |
129 | "$datadir/aclocal.glob" \ |
130 | `test -r $datadir/aclocal.site && echo "$datadir/aclocal.site"` \ |
131 | `test -r ./aclocal.lib && echo "./aclocal.lib"` \ |
132 | "$@" |
133 | |
134 | # --- Now do the job --- |
135 | |
136 | case $mode in |
137 | |
138 | l) |
139 | $bindir/txtlib -l "$@" | sort | uniq |
140 | ;; |
141 | |
142 | x) |
143 | t=/tmp/mkaclocal.$$ |
144 | if mkdir -m 700 $t; then : |
145 | else |
146 | echo >&2 "mkaclocal: cculd not creat etemporary directory" |
147 | exit 1 |
148 | fi |
149 | echo -NOTICE- >$t/a |
150 | created=no |
151 | |
152 | $bindir/txtlib -l "$@" | sort | uniq | while read LINE; do |
153 | echo "/$LINE/ i\\ |
154 | $LINE" |
155 | done >$t/sed |
156 | |
157 | until { echo -NOTICE-; sed -n -f $t/sed $in; } | sort | uniq >$t/b |
158 | cmp -s $t/a $t/b |
159 | do |
160 | $bindir/txtlib "$@" <$t/b >$out.tmp |
161 | in=$out.tmp |
162 | mv $t/b $t/a |
163 | created=yes |
164 | done |
165 | |
166 | if [ "$created" = "yes" ]; then |
167 | { test -r ./aclocal.lib && |
168 | grep "\*@--TOP--@\*" ./aclocal.lib >/dev/null && |
169 | sed -e "/\*@--TOP--@\*/, $ d" ./aclocal.lib |
170 | cat $out.tmp |
171 | } >$out |
172 | else |
173 | rm -f $out |
174 | fi |
175 | |
176 | rm -fr $t $out.tmp |
177 | ;; |
178 | esac |