-
Notifications
You must be signed in to change notification settings - Fork 3
/
acconfig
204 lines (180 loc) · 5.69 KB
/
acconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#! /usr/bin/perl
$VERSION="0.10";
$PREFIX="/usr/local";
# -* perl *-
# Copyright (C) 1988 Eleftherios Gkioulekas <lf@amath.washington.edu>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# As a special exception to the GNU General Public License, if you
# distribute this file as part of a program that contains a configuration
# script generated by Autoconf, you may include it under the same
# distribution terms that you use for the rest of that program.
# =======================
# == Usage information ==
# =======================
sub usage
{
print <<"EOF";
Usage:
% acconfig
Options:
--help Print this message
--version Show version information
Purpose:
This utility parses aclocal.m4 and creates an appropriate acconfig.h.
In your m4 files put the following lines:
dnl ACCONFIG [BOTTOM | TOP | TEMPLATE]
dnl .....
dnl END ACCONFIG
Everything that appears in ... will be included in acconfig.h
The parameter [bottom|top|template] determines where in acconfig.h
the enclosed text is meant to appear.
EOF
exit(0);
}
sub version
{
print <<"EOF";
acconfig $VERSION - Automatic generator for acconfig.h
Copyright (C) 1998 Eleftherios Gkioulekas <lf\@amath.washington.edu>
This is free software, and you are welcome to redistribute it and modify
it under certain conditions. There is ABSOLUTELY NO WARRANTY for this
software. For details refer to version 2 of the GNU General Public License.
EOF
exit(0);
}
sub invalid
{
print "Invalid usage. For help:\n";
print "% acconfig --help\n";
exit(1);
}
sub throw_error
{
local($errormsg) = @_;
print "line $line: $errormsg \n";
exit(1);
}
# ==================
# == The main fun ==
# ==================
# No more than one argument
do invalid() if ($#ARGV > 0);
# If there is one argument then check for --version or --help
if ($#ARGV == 0)
{
do version() if ($ARGV[0] eq "--version");
do usage() if ($ARGV[0] eq "--help");
# else, invalid usage
do invalid();
}
# Load the aclocal.m4 file in memory
open(FILE,"aclocal.m4") || die "Can't open aclocal.m4: $!";
@aclocal_content = <FILE>;
close(FILE);
# Load the configure.in file in memory
open(FILE,"configure.in") || die "Can't open configure.in: $!";
@configure_in_content = <FILE>;
@aclocal_content = (@aclocal_content, @configure_in_content);
close(FILE);
# Strip the carriage returns for each line
chop(@aclocal_content);
# Initialize contents of acconfig.h
$bottom_content = "";
$top_content = "";
$template_content = "";
# Initialize the state of the parser
# 0 if outside @acconfig
# 1 if inside and it is bottom
# 2 if inside and it is top
# 3 if inside and it is template
$inside_acconfig = 0;
# Now loop over the contents of aclocal.m4 and do it
$line = 0;
foreach (@aclocal_content)
{
#
# Do these things if we are in state 0
#
if ($inside_acconfig == 0)
{
# Detect whether the current line is a directive to switch state
if (/^dnl ACCONFIG BOTTOM/) { $inside_acconfig = 1; }
elsif (/^dnl ACCONFIG TOP/) { $inside_acconfig = 2; }
elsif (/^dnl ACCONFIG TEMPLATE/) { $inside_acconfig = 3; }
# Catch a couple of possible errors
elsif (/^dnl ACCONFIG/) { throw_error("invalid ACCONFIG directive."); }
elsif (/^dnl END/) { throw_error("unmatched END directive."); }
}
#
# Do these things if we are in state 1, 2 or 3
#
elsif ($inside_acconfig == 1 ||
$inside_acconfig == 2 ||
$inside_acconfig == 3)
{
# Detect whether we go back to state 0
if (/^dnl END ACCONFIG/) { $inside_acconfig = 0; }
# If this is an ordinary dnl line then add it to bottom_content
elsif (/^dnl/)
{
# Get rid of the dnl prefix
s/^dnl //g;
# Add the line to the appropriate content variable
if ($inside_acconfig == 1)
{ $bottom_content = $bottom_content . $_ . "\n"; }
if ($inside_acconfig == 2)
{ $top_content = $top_content . $_ . "\n"; }
if ($inside_acconfig == 3)
{ $template_content = $template_content . $_ . "\n"; }
}
# If this is something else, then that's an error!
else { throw_error("non-dnl line while inside ACCONFIG."); }
}
else
{ throw_error("INTERNAL ERROR: invalid value for inside_acconfig."); }
# Increase the line number by one
$line = $line + 1;
}
# Now generate acconfig.h
open(OUT,">acconfig.h");
print OUT <<"END";
/*
** This file has been automatically generated by 'acconfig' from aclocal.m4
** Copyright (C) 1988 Eleftherios Gkioulekas <lf\@amath.washington.edu>
**
** This file is free software; as a special exception the author gives
** unlimited permission to copy and/or distribute it, with or without
** modifications, as long as this notice is preserved.
**
** This program is distributed in the hope that it will be useful, but
** WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
** implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/* This is the top section */
$top_content
\@TOP\@
/* This is the template section */
/* These are standard for all packages using Automake */
#undef PACKAGE
#undef VERSION
/* And now the rest of the boys */
$template_content
\@BOTTOM\@
/* This is the bottom section */
$bottom_content
END
close(OUT);