2
# @(#) $Revision: 4.5 $ $Source: /judy/configure $
4
# Hand-edited configure script for the Judy library. Builds Makefile from
5
# Makefile.multi plus make_includes/*.mk.
7
# Usage: <script> [-f <flavor>]
9
# Redirect stdout/stderr as desired. Note the space required after -f.
13
# ./configure # note: need not be superuser.
14
# ./configure -f debug > configure.out
16
# The default flavor is "product"; can also be "debug" or "cov" (for C-Cover
17
# measurements). Invoke in the top judy/ directory.
19
# This script uses the pre-existing Makefile.multi (for multi-platforms) to
20
# create a single-platform, single-flavor Judy Makefilefor any one of four
21
# known platforms: hpux_pa, hpux_ipf, linux_ia32, linux_ipf. (Also win_ia32
22
# and win_ipf, but these are not certain to work.)
24
# Note: The pre-existing Makefile.multi is:
26
# - static (not generated, such as by configure, for historical reasons)
27
# - monolithic (not recursive descent)
28
# - rich (many targets)
29
# - mature (many parameterizations, clean placement of constructed files, etc)
30
# - multi-platform (using "include"s of platform-specific parts)
31
# - multi-flavor (using "include"s of flavor-specific parts)
32
# - deliverable-complete (knows how to build all deliverable files)
34
# However, Makefile.multi is not complete at the top level of the Judy source
35
# tree in that it does not know about manual tests, regression tests,
38
# The Judy Makefile.multi grew organically out of a platform-centered view.
39
# Ideally it should be converted to a more feature-centered, portable view that
40
# would allow the use of autoconf and good chances of working on previously
43
# So what does this configure script do? It uses uname(1) to determine the
44
# correct platform and invokes the makefile accordingly, while attempting to
45
# use only common shell features, nothing fancy.
50
FLAVOR='product' # default.
56
then FLAVOR="$2"; shift; shift
62
echo >&2 "Usage: $0 [-f flavor]\nwhere flavor is one of:" \
68
product | debug | cov) ;;
69
*) echo >&2 "$0: Error: Flavor must be one of: product, debug, cov"
75
# study judy/make_includes/platform.*.mk.
86
then PLATFORM='hpux_ipf'
87
else PLATFORM='hpux_pa' # assumed if not IPF.
89
elif [ x$SYS = xLinux ]
92
then PLATFORM='linux_ipf'
93
else PLATFORM='linux_ia32' # assumed if not IPF.
95
elif [ x$SYS = xNetBSD ] && [ x$MACH = xi386 ]
98
elif [ x$SYS = xOpenBSD ] && [ x$MACH = xi386 ]
101
elif [ x$SYS = xFreeBSD ] && [ x$MACH = xi386 ]
104
elif [ x$SYS = xOSF1 ] && [ x$MACH = xalpha ]
109
# Handle unrecognized platform:
111
if [ x$PLATFORM = xgeneric ]
115
$0: Cannot determine a known platform from the output of
116
uname -s ("$SYS") and uname -m ("$MACH"). Judy has been built and
117
tested only on specific platforms (see below). Judy was written in
118
portable ANSI C. Therefore will try to build using:
120
make_includes/platform.generic.mk
122
Send email to the maintainer (doug@sourcejudy.com) with requests
123
if you have problems building Judy on your platform.
128
INTTYPES_H='-UHAVE_INTTYPES_H'
131
STDINT_H='-UHAVE_STDINT_H'
134
if [ -s /usr/include/inttypes.h ]; then
135
INTTYPES_H='-DHAVE_INTTYPES_H'
137
if [ -s /usr/include/stdint.h ]; then
138
STDINT_H='-DHAVE_STDINT_H'
142
CONFIG_H='src/config.h'
144
echo "Constructing (\"$CONFIG_H\")..."
145
rm -f "$CONFIG_H" # old version if any.
147
cat > $ENDIAN_C <<-EOF
154
char c[sizeof(long)];
157
printf("/* This file was constructed from configure - edits will be lost */\n\n");
158
printf("/* #define JU_LITTLE_ENDIAN 1 for little endian machine */\n");
159
printf("/* #define JU_64BIT 1 for a 64 bit machine */\n\n");
160
if (u.c[sizeof(long) - 1] != 1)
161
printf("#define JU_LITTLE_ENDIAN 1\n");
162
if (sizeof(long) == 8)
163
printf("#define JU_64BIT 1\n");
164
#ifdef HAVE_INTTYPES_H
165
printf("#define HAVE_INTTYPES_H 1\n");
168
printf("#define HAVE_STDINT_H 1\n");
173
cc $STDINT_H $INTTYPES_H $ENDIAN_C -o endian
180
# Note: $PLATFORM and $FLAVOR are already in the environment.
182
INPUT='Makefile.multi'
185
echo "Building Judy makefile (\"$OUTPUT\")..."
186
rm -f "$OUTPUT" # old version if any.
190
# Makefile ("$OUTPUT") for the Judy library package,
191
# constructed `date`,
192
# by "$0" from "$INPUT" and subsidiary parts,
193
# \$PLATFORM = "$PLATFORM"
194
# \$FLAVOR = "$FLAVOR"
195
# \$INTTYPES_H = "$INTTYPES_H"
196
# \$STDINT_H = "$STDINT_H"
197
INTTYPES_H='$INTTYPES_H'
202
# The rest of this script was borrowed from "expinc" (expand includes) with
203
# minimum modifications.
205
# This script knows enough about environment parameters, and make(1) macro
206
# definitions and run-time "include" statements, to expand makefile includes,
207
# even those that use macros. The output contains:
209
# # <depth> file <filename> line <number> [(entry <count>)]
211
# comments emitted as appropriate. The <depth> field indicates the depth and
212
# direction (entry/return) of each file. Errors and warnings go to stderr.
213
# The stdout IS runnable by make, because the original include lines are
214
# commented out (unlike the original expinc).
216
# Warning: Be sure to invoke this script with the same env parameters that are
217
# set at the time of calling make.
219
# Set $debug non-zero to get lots of debug output, such as "debug=1
224
# This script isn't as smart as make itself:
226
# - It doesn't handle multi-line macro values; it just saves the first line of
229
# - It assumes make macros always supercede environment parameters passed in
230
# (does not support make -e).
232
# - It assumes only "$(<name>)" macros, and no other types, are used in
235
# - Since it uses getline, it can REPORT when an open makefile re-includes
236
# ITSELF, but not READ FROM itself a second time (it tries, but gets it
237
# wrong). This is a pathological case that should be rare.
239
# However, like make:
241
# - Macro values can contain other macros.
243
# - The value of a macro at the time of encountering an "include" line is
244
# applied, even if the macro is later reassigned.
246
# - If a makefile in another directory is invoked using make -f, or viewed
247
# using this script, paths to include files are wrong unless they have
248
# env-param-driven paths; so run this script in the same directory as the
249
# makefile being expanded.
251
# Ideally we'd have a flexible, run-time-programmable, C-based preprocessor, a
252
# superset of cpp, that would optionally do all of cpp's work:
254
# - define macros (with or without parameters)
256
# - expand include statements
257
# - resolve #if statements
260
# Due to lack of time I have not written such a beast. In lieu of this general
261
# purpose tool, the following shell script must suffice for makefiles only.
266
if false # original expinc code.
268
if [ $# != 1 -o "x$1" = x-? ]
270
echo >&2 "usage: $0 makefile (must be a named file, not \"-\")"
277
then echo >&2 "$0: Cannot read file \"$INPUT\"."; exit 1
284
MAXDEPTH='20' # for includes and macros.
286
[ -z "$debug" ] && debug=0
290
awk 'BEGIN { maxdepth = 20 }
293
# SAVE ENV PARAMETER NAMES AND VALUES from the set command:
296
pos = index ($0, "=");
297
macro [substr ($0, 1, pos - 1)] = substr ($0, pos + 1);
301
# READ LINE FROM CURRENT INPUT FILE:
303
# Expand "include"s as they are encountered, and store macro values as they are
304
# defined. This awk script runs entirely in "END" so it can use getline to
305
# process the (nested) included files.
311
print "debug: env \"" name "\" = \"" macro [name] "\"";
313
errcmd = "cat >&2"; # for error text.
314
depth_reenter = 0; # depth of re-entered file.
317
# EMIT COMMENT ABOUT STARTING FIRST FILE:
319
print "# > file \"" (incfile [depth = 0] = "'"$INPUT"'") \
320
"\" line", (incline [depth] = 0) + 1;
322
incfile_entries ["'"$INPUT"'"] = 1;
325
# PROCESS EACH INPUT LINE:
327
while (1) # until exit.
329
++ incline [depth]; # line number to read.
334
if ((rc = (getline < incfile [depth])) < 0)
336
errtext = "'"$0"': error: cannot getline from file \"" \
337
incfile [depth] "\", line " incline [depth] \
338
"; note: both make(1) and this command must " \
339
"run in the correct directory";
342
print errtext | errcmd;
349
# Be sure to close() the file so if it is re-entered, getline starts over.
353
if (depth == 0) exit; # all done.
355
close (incfile [depth]);
357
if (depth_reenter == depth--) # closing re-entered file.
360
# Emit comment about returning to next outer file:
364
for (count = 1; count <= depth; ++count)
367
print " file \"" incfile [depth] "\" line", \
374
# PASS THROUGH THE INPUT LINE JUST READ, before doing anything else:
379
# SKIP BLANK OR COMMENT LINE:
381
if ((NF == 0) || ($1 ~ /^#/))
385
# HANDLE INCLUDE LINE:
387
if ($0 ~ /^include[ '"$TAB"']/) # per make(1).
389
if (depth >= maxdepth)
391
errtext = "'"$0"': error: maximum include depth (" \
392
maxdepth ") exceeded, file \"" \
393
incfile [depth] "\", line " incline [depth];
396
print errtext | errcmd;
400
file = substr ($0, 9);
402
# Trim leading or trailing whitespace in filename:
404
sub ("^[ '"$TAB"']*", "", file);
405
sub ( "[ '"$TAB"']*$", "", file);
408
print "debug: \"" $0 "\", file: \"" file "\"";
410
# Expand macros in filename:
414
while (pos = index (file, "$("))
416
if (! (len = index (substr (file, pos), ")")))
417
break; # no closing paren.
421
errtext = "'"$0"': error: null macro name, " \
422
"file \"" incfile [depth] "\", line " \
426
print errtext | errcmd;
430
if (++macrodepth > maxdepth)
432
errtext = "'"$0"': error: maximum macro depth (" \
433
maxdepth ") exceeded, file \"" \
434
incfile [depth] "\", line " incline [depth];
437
print errtext | errcmd;
441
file = substr (file, 1, pos - 1) \
442
macro [substr (file, pos + 2, len - 3)] \
443
substr (file, pos + len);
446
# Emit comment about starting next inner file:
450
for (count = 0; count <= depth; ++count)
453
printf ("> %s", "file \"" (incfile [++depth] = file) \
454
"\" line " (incline [depth] = 0) + 1);
456
# Check for re-entering included file:
458
# For files included by a re-included file, just finish the previous line.
460
if ((++ incfile_entries [file] == 1) || depth_reenter)
466
print " (entry " incfile_entries [file] ")";
467
depth_reenter = depth;
469
print "'"$0"': warning: include file \"" \
470
file "\" included", incfile_entries [file], \
479
print "debug: \"" $0 "\"";
482
# HANDLE NON-INCLUDE LINE; LOOK FOR MACRO DEFINITION:
484
# It is optional whitespace followed by any non-null string of chars except "="
485
# or whitespace, followed optionally by whitespace, then by "=", then more
486
# optional whitespace (per make(1)).
489
/^[ '"$TAB"']*[^= '"$TAB"'][^= '"$TAB"']*[ '"$TAB"']*=/)
494
pos = index ($0, "=");
495
name = substr ($0, 1, pos - 1);
496
value = substr ($0, pos + 1);
498
# Trim leading or trailing whitespace:
500
sub ("^[ '"$TAB"']*", "", name);
501
sub ( "[ '"$TAB"']*$", "", name);
502
sub ("^[ '"$TAB"']*", "", value);
503
sub ( "[ '"$TAB"']*$", "", value);
507
print "debug: \"" $0 "\", name: \"" name "\", value: \"" \
511
macro [name] = value;
518
# Original expinc ended here, but this version comments out "include" lines
519
# passed through above, and puts the output in a known file:
521
sed 's/^include/# include/' >> "$OUTPUT"
524
echo "$0 completed; run 'make'"