File: configure

package info (click to toggle)
flake 0.11-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 368 kB
  • sloc: ansic: 3,590; sh: 797; makefile: 180
file content (838 lines) | stat: -rwxr-xr-x 20,511 bytes parent folder | download | duplicates (4)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
#!/bin/sh
#
# Flake configure script
#
# based on ffmpeg configure script (c) 2000, 2001, 2002 Fabrice Bellard
#

# make sure we are running under a compatible shell
unset foo
(: ${foo%%bar}) 2>/dev/null && ! (: ${foo?}) 2>/dev/null
if test "$?" != 0; then
    if test "x$FLAKE_CONFIGURE_EXEC" = x; then
        FLAKE_CONFIGURE_EXEC=1
        export FLAKE_CONFIGURE_EXEC
        exec bash "$0" "$@"
        exec ksh "$0" "$@"
        exec /usr/xpg4/bin/sh "$0" "$@"
    fi
    echo "No compatible shell script interpreter found."
    exit 1
fi

show_help(){
  echo "Usage: configure [options]"
  echo "Options: [defaults in brackets after descriptions]"
  echo
  echo "Standard options:"
  echo "  --help                   print this message"
  echo "  --log[=FILE|yes|no]      log tests and output to FILE [config.err]"
  echo "  --prefix=PREFIX          install in PREFIX [$PREFIX]"
  echo "  --libdir=DIR             install libs in DIR [PREFIX/lib]"
  echo "  --incdir=DIR             install includes in DIR [PREFIX/include/ffmpeg]"
  echo "  --enable-mingw32         enable MinGW native/cross Windows compile"
  echo "  --enable-mingwce         enable MinGW native/cross WinCE compile"
  echo ""
  echo "Advanced options (experts only):"
  echo "  --source-path=PATH       path to source code [$source_path]"
  echo "  --cross-prefix=PREFIX    use PREFIX for compilation tools [$cross_prefix]"
  echo "  --cross-compile          assume a cross-compiler is used"
  echo "  --cc=CC                  use C compiler CC [$cc]"
  echo "  --make=MAKE              use specified make [$make]"
  echo "  --ar=AR                  use specified ar [$ar]"
  echo "  --ranlib=RANLIB          use specified ranlib [$ranlib]"
  echo "  --strip=STRIP            use specified ranlib [$strip]"
  echo "  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS [$CFLAGS]"
  echo "  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS]"
  echo "  --extra-libs=ELIBS       add ELIBS [$ELIBS]"
  echo "  --build-suffix=SUFFIX    suffix for application specific build []"
  echo "  --cpu=CPU                force cpu to CPU  [$cpu]"
  echo "  --tune=CPU               tune code for a particular CPU"
  echo "                           (may fail or perform badly on other CPUs)"
  echo "  --disable-altivec        disable AltiVec usage"
  echo "  --enable-gprof           enable profiling with gprof [$gprof]"
  echo "  --disable-debug          disable debugging symbols"
  echo "  --disable-opts           disable compiler optimizations"
  echo "  --enable-small           optimize for size instead of speed"
  echo "  --disable-strip          disable stripping of executables"
  echo ""
  echo "NOTE: Object files are built at the place where configure is launched."
  exit 1
}

log(){
    echo "$@" >>$logfile
}

log_file(){
    log BEGIN $1
    cat -n $1 >>$logfile
    log END $1
}

echolog(){
    log "$@"
    echo "$@"
}

die(){
    echolog "$@"
    cat <<EOF
If you think configure made a mistake, make sure you are using the latest
version from SVN.  If the latest version fails, report the problem to
justinruggles@bellsouth.net.
EOF
    if enabled logging; then
        cat <<EOF
Include the log file "$logfile" produced by configure as this will help
solving the problem.
EOF
    else
cat <<EOF
Rerun configure with logging enabled (do not use --log=no), and include the
log this produces with your report.
EOF
    fi
    rm -f $TMPC $TMPO $TMPE $TMPS $TMPH
    exit 1
}

enabled(){
    eval test "\$$1" = "yes"
}

flags_saved(){
    (: ${SAVE_CFLAGS?}) 2>/dev/null
}

save_flags(){
    flags_saved && return
    SAVE_CFLAGS="$CFLAGS"
    SAVE_LDFLAGS="$LDFLAGS"
    SAVE_extralibs="$extralibs"
}

restore_flags(){
    CFLAGS="$SAVE_CFLAGS"
    LDFLAGS="$SAVE_LDFLAGS"
    extralibs="$SAVE_extralibs"
    unset SAVE_CFLAGS
    unset SAVE_LDFLAGS
    unset SAVE_extralibs
}

append(){
    var=$1
    shift
    flags_saved && eval "SAVE_$var=\"\$SAVE_$var $*\""
    eval "$var=\"\$$var $*\""
}

add_cflags(){
    append CFLAGS "$@"
}

add_ldflags(){
    append LDFLAGS "$@"
}

add_extralibs(){
    append extralibs "$@"
}

check_cmd(){
    log "$@"
    "$@" >>$logfile 2>&1
}

check_cc(){
    log check_cc "$@"
    cat >$TMPC
    log_file $TMPC
    check_cmd $cc $CFLAGS "$@" -c -o $TMPO $TMPC
}

check_cpp(){
    log check_cpp "$@"
    cat >$TMPC
    log_file $TMPC
    check_cmd $cc $CFLAGS "$@" -E -o $TMPO $TMPC
}

check_ld(){
    log check_ld "$@"
    check_cc || return
    check_cmd $cc $LDFLAGS "$@" -o $TMPE $TMPO $extralibs
}

check_cflags(){
    log check_cflags "$@"
    check_cc "$@" <<EOF && add_cflags "$@"
int x;
EOF
}

check_ldflags(){
    log check_ldflags "$@"
    check_ld "$@" <<EOF && add_ldflags "$@"
int main(){
    return 0;
}
EOF
}

check_header(){
    log check_header "$@"
    header=$1
    shift
    check_cpp "$@" <<EOF
#include <$header>
int x;
EOF
}

check_exec(){
    check_ld "$@" && { test "$cross_compile" = yes || $TMPE >>$logfile 2>&1; }
}

# set temporary file name
if test ! -z "$TMPDIR" ; then
    TMPDIR1="${TMPDIR}"
elif test ! -z "$TEMPDIR" ; then
    TMPDIR1="${TEMPDIR}"
elif test ! -z "$TEMP" ; then
    TMPDIR1="${TEMP}"
else
    TMPDIR1="/tmp"
fi

TMPC="${TMPDIR1}/flake-conf-${RANDOM}-$$-${RANDOM}.c"
TMPO="${TMPDIR1}/flake-conf-${RANDOM}-$$-${RANDOM}.o"
TMPE="${TMPDIR1}/flake-conf-${RANDOM}-$$-${RANDOM}"
TMPS="${TMPDIR1}/flake-conf-${RANDOM}-$$-${RANDOM}.S"
TMPH="${TMPDIR1}/flake-conf-${RANDOM}-$$-${RANDOM}.h"

# default parameters
logging="yes"
logfile="config.err"
PREFIX="/usr/local"
libdir='${PREFIX}/lib'
incdir='${PREFIX}/include'
bindir='${PREFIX}/bin'
cross_prefix=""
cross_compile="no"
cc="gcc"
ar="ar"
ranlib="ranlib"
make="make"
strip="strip"
cpu=`uname -m`
tune="generic"
altivec="default"
case "$cpu" in
  i386|i486|i586|i686|i86pc|BePC)
    cpu="x86"
  ;;
  x86_64|amd64)
    cpu="x86"
    canon_arch="`$cc -dumpmachine | sed -e 's,\([^-]*\)-.*,\1,'`"
    if [ x"$canon_arch" = x"x86_64" -o x"$canon_arch" = x"amd64" ]; then
      if [ -z "`echo $CFLAGS | grep -- -m32`"  ]; then
        cpu="x86_64"
      fi
    fi
  ;;
  # armv4l is a subset of armv5tel
  armv4l|armv5tel)
    cpu="armv4l"
  ;;
  alpha)
    cpu="alpha"
  ;;
  "Power Macintosh"|ppc|ppc64|powerpc)
    cpu="powerpc"
  ;;
  mips|mipsel|IP*)
    cpu="mips"
  ;;
  sun4u|sparc64)
    cpu="sparc64"
  ;;
  sparc)
    cpu="sparc"
  ;;
  sh4)
    cpu="sh4"
  ;;
  parisc|parisc64)
    cpu="parisc"
  ;;
  s390|s390x)
    cpu="s390"
  ;;
  m68k)
    cpu="m68k"
  ;;
  ia64)
    cpu="ia64"
  ;;
  bfin)
    cpu="bfin"
  ;;
  *)
    cpu="unknown"
  ;;
esac
gprof="no"
mingw32="no"
mingwce="no"
os2="no"
optimize="yes"
debug="yes"
dostrip="yes"
installstrip="-s"
extralibs="-lm"
bigendian="no"
inttypes="yes"
LIBOBJFLAGS=""
PROJLDFLAGS=-Wl,--warn-common
LDCONFIG="ldconfig"
LIBPREF="lib"
LIBSUF=".a"
LIB='$(LIBPREF)$(NAME)$(LIBSUF)'
EXESUF=""
BUILDSUF=""
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"'

# OS specific
targetos=`uname -s`
case $targetos in
BeOS)
PREFIX="/boot/home/config"
add_cflags "-DPIC -fomit-frame-pointer"
# 3 gcc releases known for BeOS, each with ugly bugs
gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
case "$gcc_version" in
2.9-beos-991026*|2.9-beos-000224*) echo "R5/GG gcc"
;;
*20010315*) echo "BeBits gcc"
add_cflags "-fno-expensive-optimizations"
;;
esac
;;
SunOS)
make="gmake"
PROJLDFLAGS=""
;;
NetBSD)
make="gmake"
;;
OpenBSD)
make="gmake"
LIBOBJFLAGS="\$(PIC)"
;;
FreeBSD)
make="gmake"
add_cflags "-pthread"
;;
GNU/kFreeBSD)
add_cflags "-pthread"
;;
BSD/OS)
extralibs="-lpoll -lgnugetopt -lm"
make="gmake"
strip="strip -d"
installstrip=""
;;
Darwin)
cc="cc"
extralibs=""
strip="strip -x"
installstrip=""
PROJLDFLAGS="-Wl,-dynamic,-search_paths_first"
LIB_INSTALL_EXTRA_CMD='$(RANLIB) "$(libdir)/$(LIB)"'
;;
MINGW32*)
# Note: the rest of the mingw32 config is done afterwards as mingw32
# can be forced on the command line for Linux cross compilation.
mingw32="yes"
;;
CYGWIN*)
targetos=CYGWIN
extralibs=""
EXESUF=".exe"
;;
Linux)
;;
IRIX*)
targetos=IRIX
ranlib="echo ignoring ranlib"
make="gmake"
;;
OS/2)
TMPE=$TMPE".exe"
ar="emxomfar -p128"
ranlib="echo ignoring ranlib"
strip="echo ignoring strip"
add_cflags "-Zomf"
PROJLDFLAGS="-Zomf -Zstack 16384 -s"
LIBPREF=""
LIBSUF=".lib"
EXESUF=".exe"
extralibs=""
os2="yes"

;;
*)
targetos="${targetos}-UNKNOWN"
;;
esac

# find source path
source_path="`dirname $0`"
source_path_used="yes"
if test -z "$source_path" -o "$source_path" = "." ; then
    source_path=`pwd`
    source_path_used="no"
else
    source_path="`cd \"$source_path\"; pwd`"
fi

if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
    show_help
fi

FLAKE_CONFIGURATION=" "
for opt do
  FLAKE_CONFIGURATION="$FLAKE_CONFIGURATION""$opt "
done

for opt do
  optval="${opt#*=}"
  case "$opt" in
  --log)
  ;;
  --log=*) logging="$optval"
  ;;
  --prefix=*) PREFIX="$optval"; force_prefix=yes
  ;;
  --libdir=*) libdir="$optval"; force_libdir=yes
  ;;
  --incdir=*) incdir="$optval"
  ;;
  --source-path=*) source_path="$optval"
  ;;
  --cross-prefix=*) cross_prefix="$optval"
  ;;
  --cross-compile) cross_compile=yes
  ;;
  --cc=*) cc="$optval"
  ;;
  --make=*) make="$optval"
  ;;
  --ar=*) ar="$optval"
  ;;
  --ranlib=*) ranlib="$optval"
  ;;
  --strip=*) strip="$optval"
  ;;
  --extra-cflags=*) add_cflags "$optval"
  ;;
  --extra-ldflags=*) EXTRALDFLAGS="$optval"
  ;;
  --extra-libs=*) extralibs="$optval"
  ;;
  --build-suffix=*) BUILDSUF="$optval"
  ;;
  --cpu=*) cpu="$optval"
  ;;
  --tune=*) tune="$optval"
  ;;
  --disable-altivec) altivec="no"
  ;;
  --enable-gprof) gprof="yes"
  ;;
  --enable-mingw32) mingw32="yes"
  ;;
  --enable-mingwce) mingwce="yes"
  ;;
  --disable-debug) debug="no"
  ;;
  --disable-opts) optimize="no"
  ;;
  --enable-small) optimize="small"
  ;;
  --disable-strip) dostrip="no"
  ;;
  --help) show_help
  ;;
  *)
  echo "Unknown option \"$opt\"."
  echo "See $0 --help for available options."
  exit 1
  ;;
  esac
done

if test "$logging" != no; then
    test "$logging" = yes || logfile="$logging"
    echo "# $0 $@" >$logfile
    set >>$logfile
else
    logfile=/dev/null
fi

if test "$mingw32" = "yes" -o "$mingwce" = "yes"; then
    EXESUF=".exe"
    if test "$force_prefix" != yes; then PREFIX="$PROGRAMFILES/Flake"; fi
    if test "$force_libdir" != yes; then bindir='${PREFIX}'; fi
fi

# Combine PROFLDFLAGS, EXTRALDFLAGS and the LDFLAGS environment variable.
LDFLAGS="$PROJLDFLAGS $EXTRALDFLAGS $LDFLAGS"

test -n "$cross_prefix" && cross_compile=yes
cc="${cross_prefix}${cc}"
ar="${cross_prefix}${ar}"
ranlib="${cross_prefix}${ranlib}"
strip="${cross_prefix}${strip}"

#Darwin CC versions
needmdynamicnopic="no"
if test $targetos = Darwin; then
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
        add_cflags "-qpdf2 -qlanglvl=extc99 -qmaxmem=-1 -qarch=auto -qtune=auto"
    else
        gcc_version="`$cc -v 2>&1 | grep version | cut -d ' ' -f3-`"
        case "$gcc_version" in
            *2.95*)
                add_cflags "-no-cpp-precomp -pipe"
                ;;
            *[34].*)
                add_cflags "-no-cpp-precomp -pipe -force_cpusubtype_ALL -Wno-sign-compare"
                needmdynamicnopic="yes"
                ;;
            *)
                add_cflags "-no-cpp-precomp -pipe"
                needmdynamicnopic="yes"
                ;;
        esac
    fi
    if test $optimize != "no"; then
        add_cflags "-fomit-frame-pointer"
    fi
fi

# Can only do AltiVec on PowerPC
if test $altivec = "default"; then
    if test $cpu = "powerpc"; then
        altivec="yes"
    else
        altivec="no"
    fi
fi

# Add processor-specific flags
TUNECPU="generic"
POWERPCMODE="32bits"
if test $tune != "generic"; then
    case $tune in
        601|ppc601|PowerPC601)
            add_cflags "-mcpu=601"
            if test $altivec = "yes"; then
                echo "WARNING: Tuning for PPC601 but AltiVec enabled!";
            fi
            TUNECPU=ppc601
        ;;
        603*|ppc603*|PowerPC603*)
            add_cflags "-mcpu=603"
            if test $altivec = "yes"; then
                echo "WARNING: Tuning for PPC603 but AltiVec enabled!";
            fi
            TUNECPU=ppc603
        ;;
        604*|ppc604*|PowerPC604*)
            add_cflags "-mcpu=604"
            if test $altivec = "yes"; then
                echo "WARNING: Tuning for PPC604 but AltiVec enabled!";
            fi
            TUNECPU=ppc604
        ;;
        G3|g3|75*|ppc75*|PowerPC75*)
            add_cflags "-mcpu=750 -mtune=750 -mpowerpc-gfxopt"
            if test $altivec = "yes"; then
                echo "WARNING: Tuning for PPC75x but AltiVec enabled!";
            fi
            TUNECPU=ppc750
        ;;
        G4|g4|745*|ppc745*|PowerPC745*)
            add_cflags "-mcpu=7450 -mtune=7450 -mpowerpc-gfxopt"
            if test $altivec = "no"; then
                echo "WARNING: Tuning for PPC745x but AltiVec disabled!";
            fi
            TUNECPU=ppc7450
        ;;
        74*|ppc74*|PowerPC74*)
            add_cflags "-mcpu=7400 -mtune=7400 -mpowerpc-gfxopt"
            if test $altivec = "no"; then
                echo "WARNING: Tuning for PPC74xx but AltiVec disabled!";
            fi
            TUNECPU=ppc7400
        ;;
        G5|g5|970|ppc970|PowerPC970|power4*|Power4*)
            add_cflags "-mcpu=970 -mtune=970 -mpowerpc-gfxopt -mpowerpc64"
            if test $altivec = "no"; then
                echo "WARNING: Tuning for PPC970 but AltiVec disabled!";
            fi
            TUNECPU=ppc970
            POWERPCMODE="64bits"
        ;;
        power5*|Power5*)
            add_cflags "-mcpu=power5 -mtune=power5 -mpowerpc-gfxopt -mpowerpc64"
            if test $altivec = "no"; then
                echo "WARNING: Tuning for POWER5 but AltiVec disabled!";
            fi
            TUNECPU=power5
            POWERPCMODE="64bits"
        ;;
        i[3456]86|pentium|pentiumpro|pentium-mmx|pentium[234]|prescott|k6|k6-[23]|athlon|athlon-tbird|athlon-4|athlon-[mx]p|winchip-c6|winchip2|c3|nocona|athlon64|k8|opteron|athlon-fx)
            add_cflags "-march=$tune"
        ;;
        ev4|ev45|ev5|ev56|ev6|ev67|21064|21164|21164a|21164pc|21164PC|21264|21264a)
            add_cflags "-mcpu=$tune"
        ;;
        sparc64)
            add_cflags "-mcpu=v9 -mtune=v9"
        ;;
        *)
        echo "WARNING: Unknown CPU \"$tune\", ignored."
        ;;
    esac
fi

# compiler sanity check
check_exec <<EOF
int main(){
    return 0;
}
EOF
if test "$?" != 0; then
    echo "$cc is unable to create an executable file."
    if test -z "$cross_prefix" -a "$cross_compile" = no; then
        echo "If $cc is a cross-compiler, use the --cross-compile option."
    fi
    die "C compiler test failed."
fi

# AltiVec flags: The FSF version of GCC differs from the Apple version
if test $cpu = "powerpc"; then
    if test $altivec = "yes"; then
        if test -n "`$cc -v 2>&1 | grep version | grep Apple`"; then
            add_cflags "-faltivec"
        else
            add_cflags "-maltivec -mabi=altivec"
        fi
    fi
fi

# ---
# big/little-endian test
if test "$cross_compile" = "no"; then
    check_ld <<EOF || die "endian test failed" && $TMPE && bigendian="yes"
#include <inttypes.h>
int main(int argc, char ** argv){
        volatile uint32_t i=0x01234567;
        return (*((uint8_t*)(&i))) == 0x67;
}
EOF
else
    # programs cannot be launched if cross compiling, so make a static guess
    if test "$cpu" = "powerpc" -o "$cpu" = "mips" ; then
        bigendian="yes"
    fi
fi

# ---
# *inttypes.h* test
check_header inttypes.h || inttypes=no

# test for lrintf in math.h
check_exec <<EOF && have_lrintf=yes || have_lrintf=no
#define _ISOC9X_SOURCE  1
#include <math.h>
int main( void ) { return (lrintf(3.999f) > 0)?0:1; }
EOF

# test for strnlen in string.h
check_exec <<EOF && have_strnlen=yes || have_strnlen=no
#define _ISOC9X_SOURCE  1
#include <string.h>
int main( void ) { return (strnlen("help", 6) == 4)?0:1; }
EOF

if enabled debug; then
    add_cflags -g
else
    add_cflags -DNDEBUG
fi

# add some useful compiler flags if supported
check_cflags -Wdeclaration-after-statement
check_cflags -Wall
check_cflags -Wno-switch
check_cflags -Wdisabled-optimization
check_cflags -Wpointer-arith
check_cflags -Wredundant-decls
check_cflags -Winline

# not all compilers support -Os
test "$optimize" = "small" && check_cflags -Os

if enabled optimize; then
    if test -n "`$cc -v 2>&1 | grep xlc`"; then
        add_cflags  "-O5"
        add_ldflags "-O5"
    else
        add_cflags "-O3"
    fi
fi

if test "$gprof" = "yes" ; then
    add_cflags  "-p"
    add_ldflags "-p"
fi

echo "install prefix   $PREFIX"
echo "source path      $source_path"
echo "C compiler       $cc"
echo "make             $make"
echo "CPU              $cpu ($tune)"
if test "$BUILDSUF" != ""; then
    echo "build suffix     $BUILDSUF"
fi
echo "big-endian       $bigendian"
echo "inttypes.h       $inttypes"
echo "lrintf()         $have_lrintf"
echo "strnlen()        $have_strnlen"
if test $cpu = "powerpc"; then
    echo "AltiVec enabled  $altivec"
fi
echo "gprof enabled    $gprof"
echo "debug symbols    $debug"
echo "strip symbols    $dostrip"
echo "optimize         $optimize"

echo "Creating config.mak and config.h..."

date >> config.log
echo "   $0 $FLAKE_CONFIGURATION" >> config.log
echo "# Automatically generated by configure - do not modify!" > config.mak
echo "/* Automatically generated by configure - do not modify! */" > $TMPH
echo "#define FLAKE_CONFIGURATION "'"'"$FLAKE_CONFIGURATION"'"' >> $TMPH

echo "PREFIX=$PREFIX" >> config.mak
echo "prefix=\$(DESTDIR)\${PREFIX}" >> config.mak
echo "libdir=\$(DESTDIR)$libdir" >> config.mak
echo "incdir=\$(DESTDIR)$incdir" >> config.mak
echo "bindir=\$(DESTDIR)$bindir" >> config.mak
echo "MAKE=$make" >> config.mak
echo "CC=$cc" >> config.mak
echo "AR=$ar" >> config.mak
echo "RANLIB=$ranlib" >> config.mak
if test "$dostrip" = "yes" ; then
    echo "STRIP=$strip" >> config.mak
    echo "INSTALLSTRIP=$installstrip" >> config.mak
else
    echo "STRIP=echo ignoring strip" >> config.mak
    echo "INSTALLSTRIP=" >> config.mak
fi

test "$needmdynamicnopic" = yes && add_cflags -mdynamic-no-pic

echo "OPTFLAGS=$CFLAGS" >> config.mak
echo "LDFLAGS=$LDFLAGS" >> config.mak
echo "LDCONFIG=$LDCONFIG" >> config.mak
echo "LIBOBJFLAGS=$LIBOBJFLAGS" >> config.mak
echo "BUILDSUF=$BUILDSUF" >> config.mak
echo "LIBPREF=$LIBPREF" >> config.mak
echo "LIBSUF=\${BUILDSUF}$LIBSUF" >> config.mak
echo "LIB=$LIB" >> config.mak
echo "EXESUF=\${BUILDSUF}$EXESUF" >> config.mak

echo "#define TUNECPU $TUNECPU" >> $TMPH
if test "$bigendian" = "yes" ; then
  echo "WORDS_BIGENDIAN=yes" >> config.mak
  echo "#define WORDS_BIGENDIAN 1" >> $TMPH
fi
if test "$inttypes" != "yes" ; then
  echo "#define EMULATE_INTTYPES 1" >> $TMPH
fi
if test "$have_lrintf" = "yes" ; then
  echo "#define HAVE_LRINTF 1" >> $TMPH
fi
if test "$have_strnlen" = "yes" ; then
  echo "#define HAVE_STRNLEN 1" >> $TMPH
fi

libflake_version=`grep '#define FLAKE_VERSION ' "$source_path/libflake/flake.h" | sed 's/[^0-9\.]//g'`

echo "LIB_INSTALL_EXTRA_CMD=${LIB_INSTALL_EXTRA_CMD}" >> config.mak
echo "EXTRALIBS=$extralibs" >> config.mak

if test "$mingw32" = "yes" ; then
  echo "#ifndef __MINGW32__" >> $TMPH
  echo "#define __MINGW32__ 1" >> $TMPH
  echo "#endif" >> $TMPH
fi

if test "$mingwce" = "yes" ; then
  echo "#define CONFIG_WINCE 1" >> $TMPH
  echo "#ifndef __MINGW32__" >> $TMPH
  echo "#define __MINGW32__ 1" >> $TMPH
  echo "#endif" >> $TMPH
fi

if test "$os2" = "yes" ; then
  echo "#define CONFIG_OS2 1" >> $TMPH
fi

if test "$targetos" = "SunOS" ; then
  echo "#define CONFIG_SUNOS 1" >> $TMPH
fi

if test "$targetos" = "Darwin"; then
  echo "#define CONFIG_DARWIN 1"  >> $TMPH
fi

# build tree in object directory if source path is different from current one
if test "$source_path_used" = "yes" ; then
    DIRS="\
         libflake \
         flake \
         util \
         "
    FILES="\
          Makefile \
          libflake/Makefile \
          flake/Makefile \
          util/Makefile \
          "
    for dir in $DIRS ; do
            mkdir -p $dir
    done
    for f in $FILES ; do
        ln -sf "$source_path/$f" $f
    done
fi
echo "SRC_PATH=$source_path" >> config.mak
echo "BUILD_ROOT=$PWD" >> config.mak

# Do not overwrite config.h if unchanged to avoid superfluous rebuilds.
diff $TMPH config.h >/dev/null 2>&1
if test "$?" != "0" ; then
        mv -f $TMPH config.h
else
        echo "config.h is unchanged"
fi

rm -f $TMPO $TMPC $TMPE $TMPS $TMPH