~ubuntu-branches/ubuntu/precise/judy/precise

« back to all changes in this revision

Viewing changes to configure

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Y. Ts'o
  • Date: 2004-01-17 00:04:53 UTC
  • Revision ID: james.westby@ubuntu.com-20040117000453-d5sj6uoon2v1g4gf
Tags: upstream-0.0.4
ImportĀ upstreamĀ versionĀ 0.0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# @(#) $Revision: 4.5 $ $Source: /judy/configure $
 
3
 
 
4
# Hand-edited configure script for the Judy library.  Builds Makefile from
 
5
# Makefile.multi plus make_includes/*.mk.
 
6
#
 
7
# Usage:  <script> [-f <flavor>]
 
8
#
 
9
# Redirect stdout/stderr as desired.  Note the space required after -f.
 
10
#
 
11
# Examples:
 
12
#
 
13
#    ./configure                                # note:  need not be superuser.
 
14
#    ./configure -f debug > configure.out
 
15
#
 
16
# The default flavor is "product"; can also be "debug" or "cov" (for C-Cover
 
17
# measurements).  Invoke in the top judy/ directory.
 
18
#
 
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.)
 
23
#
 
24
# Note:  The pre-existing Makefile.multi is:
 
25
#
 
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)
 
33
#
 
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,
 
36
# benchmarks, etc.
 
37
#
 
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
 
41
# untried platforms.
 
42
#
 
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.
 
46
 
 
47
 
 
48
# CHECK INVOCATION:
 
49
 
 
50
        FLAVOR='product'                # default.
 
51
        export FLAVOR
 
52
 
 
53
        if [ $# = 2 ]
 
54
        then
 
55
            if [ "x$1" = x-f ]
 
56
            then FLAVOR="$2"; shift; shift
 
57
            fi
 
58
        fi
 
59
 
 
60
        if [ $# != 0 ]
 
61
        then
 
62
            echo >&2 "Usage: $0 [-f flavor]\nwhere flavor is one of:" \
 
63
                     "product, debug, cov"
 
64
            exit 1
 
65
        fi
 
66
 
 
67
        case "$FLAVOR" in
 
68
        product | debug | cov) ;;
 
69
        *)  echo >&2 "$0: Error: Flavor must be one of: product, debug, cov"
 
70
            exit 1;;
 
71
        esac
 
72
 
 
73
 
 
74
# DETERMINE PLATFORM:
 
75
#  study judy/make_includes/platform.*.mk.
 
76
 
 
77
        PLATFORM='generic'
 
78
        export PLATFORM
 
79
 
 
80
        SYS=`uname -s`
 
81
        MACH=`uname -m`
 
82
 
 
83
        if [ x$SYS = xHP-UX ]
 
84
        then
 
85
            if [ x$MACH = xia64 ]
 
86
            then PLATFORM='hpux_ipf'
 
87
            else PLATFORM='hpux_pa'             # assumed if not IPF.
 
88
            fi
 
89
        elif [ x$SYS = xLinux ]
 
90
        then
 
91
            if [ x$MACH = xia64 ]
 
92
            then PLATFORM='linux_ipf'
 
93
            else PLATFORM='linux_ia32'          # assumed if not IPF.
 
94
            fi
 
95
        elif [ x$SYS = xNetBSD  ] && [ x$MACH = xi386 ]
 
96
        then
 
97
            PLATFORM='bsd_ia32'
 
98
        elif [ x$SYS = xOpenBSD ] && [ x$MACH = xi386 ]
 
99
        then
 
100
            PLATFORM='bsd_ia32'
 
101
        elif [ x$SYS = xFreeBSD ] && [ x$MACH = xi386 ]
 
102
        then
 
103
            PLATFORM='bsd_ia32'
 
104
        elif [ x$SYS = xOSF1    ] && [ x$MACH = xalpha ]
 
105
        then
 
106
            PLATFORM='alpha_64'
 
107
        fi
 
108
 
 
109
# Handle unrecognized platform:
 
110
 
 
111
        if [ x$PLATFORM = xgeneric ]
 
112
        then
 
113
            cat >&2 <<-EOF
 
114
 
 
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:
 
119
 
 
120
                make_includes/platform.generic.mk
 
121
 
 
122
        Send email to the maintainer (doug@sourcejudy.com) with requests 
 
123
        if you have problems building Judy on your platform.
 
124
 
 
125
        EOF
 
126
        fi
 
127
 
 
128
        INTTYPES_H='-UHAVE_INTTYPES_H'
 
129
        export INTTYPES_H
 
130
 
 
131
        STDINT_H='-UHAVE_STDINT_H'
 
132
        export STDINT_H
 
133
 
 
134
        if [ -s /usr/include/inttypes.h ]; then                     
 
135
                 INTTYPES_H='-DHAVE_INTTYPES_H'
 
136
        fi
 
137
        if [ -s /usr/include/stdint.h ]; then                      
 
138
                 STDINT_H='-DHAVE_STDINT_H'
 
139
        fi
 
140
 
 
141
        ENDIAN_C='endian.c'
 
142
        CONFIG_H='src/config.h'
 
143
 
 
144
        echo "Constructing (\"$CONFIG_H\")..."
 
145
        rm -f "$CONFIG_H"                       # old version if any.
 
146
 
 
147
        cat > $ENDIAN_C <<-EOF
 
148
        int
 
149
        main()
 
150
        {
 
151
            union
 
152
            {
 
153
                long      l;
 
154
                char      c[sizeof(long)];
 
155
            } u;
 
156
            u.l = 1;
 
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");
 
166
            #endif
 
167
            #ifdef HAVE_STDINT_H
 
168
                printf("#define HAVE_STDINT_H    1\n");
 
169
            #endif
 
170
            return 0;
 
171
        }
 
172
        EOF
 
173
        cc $STDINT_H $INTTYPES_H $ENDIAN_C -o endian
 
174
        rm -f "$ENDIAN_C"
 
175
        ./endian > $CONFIG_H
 
176
        rm -f endian
 
177
 
 
178
# BUILD MAKEFILE:
 
179
#
 
180
# Note:  $PLATFORM and $FLAVOR are already in the environment.
 
181
 
 
182
        INPUT='Makefile.multi'
 
183
        OUTPUT='Makefile'
 
184
 
 
185
        echo "Building Judy makefile (\"$OUTPUT\")..."
 
186
        rm -f "$OUTPUT"                         # old version if any.
 
187
 
 
188
        cat > $OUTPUT <<-EOF
 
189
 
 
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'
 
198
        STDINT_H='$STDINT_H'
 
199
 
 
200
        EOF
 
201
 
 
202
# The rest of this script was borrowed from "expinc" (expand includes) with
 
203
# minimum modifications.
 
204
 
 
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:
 
208
#
 
209
#       # <depth> file <filename> line <number> [(entry <count>)]
 
210
#
 
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).
 
215
#
 
216
# Warning:  Be sure to invoke this script with the same env parameters that are
 
217
# set at the time of calling make.
 
218
#
 
219
# Set $debug non-zero to get lots of debug output, such as "debug=1
 
220
# ./configure".
 
221
 
 
222
# Notes:
 
223
#
 
224
# This script isn't as smart as make itself:
 
225
#
 
226
# - It doesn't handle multi-line macro values; it just saves the first line of
 
227
#   the macro value.
 
228
#
 
229
# - It assumes make macros always supercede environment parameters passed in
 
230
#   (does not support make -e).
 
231
#
 
232
# - It assumes only "$(<name>)" macros, and no other types, are used in
 
233
#   "include" lines.
 
234
#
 
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.
 
238
#
 
239
# However, like make:
 
240
#
 
241
# - Macro values can contain other macros.
 
242
#
 
243
# - The value of a macro at the time of encountering an "include" line is
 
244
#   applied, even if the macro is later reassigned.
 
245
#
 
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.
 
250
 
 
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:
 
253
#
 
254
# - define macros (with or without parameters)
 
255
# - expand macros
 
256
# - expand include statements
 
257
# - resolve #if statements
 
258
# - strip comments
 
259
#
 
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.
 
262
 
 
263
 
 
264
# CHECK INVOCATION;
 
265
 
 
266
    if false                            # original expinc code.
 
267
    then
 
268
        if [ $# != 1  -o  "x$1" = x-? ]
 
269
        then
 
270
            echo >&2 "usage: $0 makefile (must be a named file, not \"-\")"
 
271
            exit 1
 
272
        fi
 
273
        INPUT="$1"
 
274
    fi
 
275
 
 
276
        if [ ! -r "$INPUT" ]
 
277
        then echo >&2 "$0: Cannot read file \"$INPUT\"."; exit 1
 
278
        fi
 
279
 
 
280
 
 
281
# EXPAND MAKEFILE:
 
282
 
 
283
        TAB='   '
 
284
        MAXDEPTH='20'                   # for includes and macros.
 
285
 
 
286
        [ -z "$debug" ] && debug=0
 
287
 
 
288
        set |
 
289
 
 
290
        awk 'BEGIN { maxdepth = 20 }
 
291
 
 
292
 
 
293
# SAVE ENV PARAMETER NAMES AND VALUES from the set command:
 
294
 
 
295
        {
 
296
            pos = index ($0, "=");
 
297
            macro [substr ($0, 1, pos - 1)] = substr ($0, pos + 1);
 
298
        }
 
299
 
 
300
 
 
301
# READ LINE FROM CURRENT INPUT FILE:
 
302
#
 
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.
 
306
 
 
307
        END {
 
308
 
 
309
            if ('"$debug"')
 
310
                for (name in macro)
 
311
                    print "debug: env \"" name "\" = \"" macro [name] "\"";
 
312
 
 
313
            errcmd = "cat >&2";                 # for error text.
 
314
            depth_reenter = 0;                  # depth of re-entered file.
 
315
 
 
316
 
 
317
# EMIT COMMENT ABOUT STARTING FIRST FILE:
 
318
 
 
319
            print "# > file \"" (incfile [depth = 0] = "'"$INPUT"'") \
 
320
                  "\" line", (incline [depth] = 0) + 1;
 
321
 
 
322
            incfile_entries ["'"$INPUT"'"] = 1;
 
323
 
 
324
 
 
325
# PROCESS EACH INPUT LINE:
 
326
 
 
327
            while (1)                           # until exit.
 
328
            {
 
329
                ++ incline [depth];             # line number to read.
 
330
 
 
331
 
 
332
# HANDLE READ ERROR:
 
333
 
 
334
                if ((rc = (getline < incfile [depth])) < 0)
 
335
                {
 
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";
 
340
 
 
341
                    print errtext;
 
342
                    print errtext | errcmd;
 
343
                    exit;
 
344
                }
 
345
 
 
346
 
 
347
# HANDLE EOF:
 
348
#
 
349
# Be sure to close() the file so if it is re-entered, getline starts over.
 
350
 
 
351
                if (rc == 0)
 
352
                {
 
353
                    if (depth == 0) exit;       # all done.
 
354
 
 
355
                    close (incfile [depth]);
 
356
 
 
357
                    if (depth_reenter == depth--)  # closing re-entered file.
 
358
                        depth_reenter = 0;
 
359
 
 
360
# Emit comment about returning to next outer file:
 
361
 
 
362
                    printf ("# <");
 
363
 
 
364
                    for (count = 1; count <= depth; ++count)
 
365
                        printf ("-");
 
366
 
 
367
                    print " file \"" incfile [depth] "\" line", \
 
368
                          incline [depth] + 1;
 
369
 
 
370
                    continue;
 
371
                }
 
372
 
 
373
 
 
374
# PASS THROUGH THE INPUT LINE JUST READ, before doing anything else:
 
375
 
 
376
                print;
 
377
 
 
378
 
 
379
# SKIP BLANK OR COMMENT LINE:
 
380
 
 
381
                if ((NF == 0) || ($1 ~ /^#/))
 
382
                    continue;
 
383
 
 
384
 
 
385
# HANDLE INCLUDE LINE:
 
386
 
 
387
                if ($0 ~ /^include[ '"$TAB"']/)         # per make(1).
 
388
                {
 
389
                    if (depth >= maxdepth)
 
390
                    {
 
391
                        errtext = "'"$0"': error: maximum include depth (" \
 
392
                                  maxdepth ") exceeded, file \"" \
 
393
                                  incfile [depth] "\", line " incline [depth];
 
394
 
 
395
                        print errtext;
 
396
                        print errtext | errcmd;
 
397
                        exit;
 
398
                    }
 
399
 
 
400
                    file = substr ($0, 9);
 
401
 
 
402
# Trim leading or trailing whitespace in filename:
 
403
 
 
404
                    sub ("^[ '"$TAB"']*",  "", file);
 
405
                    sub ( "[ '"$TAB"']*$", "", file);
 
406
 
 
407
                    if ('"$debug"')
 
408
                        print "debug: \"" $0 "\", file: \"" file "\"";
 
409
 
 
410
# Expand macros in filename:
 
411
 
 
412
                    macrodepth = 0;
 
413
 
 
414
                    while (pos = index (file, "$("))
 
415
                    {
 
416
                        if (! (len = index (substr (file, pos), ")")))
 
417
                            break;              # no closing paren.
 
418
 
 
419
                        if (len < 4)
 
420
                        {
 
421
                            errtext = "'"$0"': error: null macro name, " \
 
422
                                      "file \"" incfile [depth] "\", line " \
 
423
                                      incline [depth];
 
424
 
 
425
                            print errtext;
 
426
                            print errtext | errcmd;
 
427
                            exit;
 
428
                        }
 
429
 
 
430
                        if (++macrodepth > maxdepth)
 
431
                        {
 
432
                            errtext = "'"$0"': error: maximum macro depth (" \
 
433
                                      maxdepth ") exceeded, file \"" \
 
434
                                  incfile [depth] "\", line " incline [depth];
 
435
 
 
436
                            print errtext;
 
437
                            print errtext | errcmd;
 
438
                            exit;
 
439
                        }
 
440
 
 
441
                        file = substr (file, 1, pos - 1) \
 
442
                               macro [substr (file, pos + 2, len - 3)] \
 
443
                               substr (file, pos + len);
 
444
                    } # while.
 
445
 
 
446
# Emit comment about starting next inner file:
 
447
 
 
448
                    printf ("# ");
 
449
 
 
450
                    for (count = 0; count <= depth; ++count)
 
451
                        printf ("-");
 
452
 
 
453
                    printf ("> %s", "file \"" (incfile [++depth] = file) \
 
454
                                    "\" line " (incline [depth] = 0) + 1);
 
455
 
 
456
# Check for re-entering included file:
 
457
#
 
458
# For files included by a re-included file, just finish the previous line.
 
459
 
 
460
                    if ((++ incfile_entries [file] == 1) || depth_reenter)
 
461
                    {
 
462
                        print "";
 
463
                    }
 
464
                    else
 
465
                    {
 
466
                        print " (entry " incfile_entries [file] ")";
 
467
                        depth_reenter = depth;
 
468
 
 
469
                        print "'"$0"': warning: include file \"" \
 
470
                              file "\" included", incfile_entries [file], \
 
471
                              "times" | errcmd;
 
472
                    }
 
473
 
 
474
                    continue;
 
475
 
 
476
                } # if.
 
477
 
 
478
                if ('"$debug"')
 
479
                    print "debug: \"" $0 "\"";
 
480
 
 
481
 
 
482
# HANDLE NON-INCLUDE LINE; LOOK FOR MACRO DEFINITION:
 
483
#
 
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)).
 
487
 
 
488
                if ($0 !~ \
 
489
                    /^[ '"$TAB"']*[^= '"$TAB"'][^= '"$TAB"']*[ '"$TAB"']*=/)
 
490
                {
 
491
                    continue;
 
492
                }
 
493
 
 
494
                pos   = index  ($0, "=");
 
495
                name  = substr ($0, 1, pos - 1);
 
496
                value = substr ($0, pos + 1);
 
497
 
 
498
# Trim leading or trailing whitespace:
 
499
 
 
500
                sub ("^[ '"$TAB"']*",  "", name);
 
501
                sub ( "[ '"$TAB"']*$", "", name);
 
502
                sub ("^[ '"$TAB"']*",  "", value);
 
503
                sub ( "[ '"$TAB"']*$", "", value);
 
504
 
 
505
                if ('"$debug"')
 
506
                {
 
507
                    print "debug: \"" $0 "\", name: \"" name "\", value: \"" \
 
508
                          value "\"";
 
509
                }
 
510
 
 
511
                macro [name] = value;
 
512
                continue;
 
513
 
 
514
            } # while.
 
515
        }' |
 
516
 
 
517
 
 
518
# Original expinc ended here, but this version comments out "include" lines
 
519
# passed through above, and puts the output in a known file:
 
520
 
 
521
        sed 's/^include/# include/' >> "$OUTPUT"
 
522
 
 
523
        echo
 
524
        echo "$0 completed; run 'make'"
 
525
        echo