File: configure

package info (click to toggle)
flint 2.5.2-19
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 30,308 kB
  • sloc: ansic: 289,367; cpp: 11,210; python: 1,280; sh: 649; makefile: 283
file content (746 lines) | stat: -rwxr-xr-x 19,220 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
#!/bin/sh

# (C) 2007, Robert Bradshaw, William Hart, William Stein, Michael Abshoff
# (C) 2011, William Hart
# (C) 2012, William Hart, Jean-Pierre Flori, Thomas DuBuisson
# (C) 2012, Jan Engelhardt

PREFIX="/usr/local"
GMP_DIR="/usr/local"
MPFR_DIR="/usr/local"
NTL_DIR="/usr/local"
GC_DIR="/usr/local"
BLAS_DIR="/usr/local"
WANT_NTL=0
WANT_BLAS=0
SHARED=1
STATIC=1
TLS=1
PTHREAD=1
REENTRANT=0
WANT_GC=0
WANT_TLS=0
WANT_CXX=0
ASSERT=0
BUILD=
EXTENSIONS=
EXT_MODS=
EXTRA_BUILD=
FLINT_DLL=0
FLINT_LIBNAME=
FLINT_SOLIB=0

# soname version, minor release number and patch number

# flint => soname
# 2.5.0 => 13.5.0
# 2.5.1 => 13.5.1
# 2.5.2 => 13.5.2

FLINT_MAJOR=13
FLINT_MINOR=5
FLINT_PATCH=2

usage()
{
   echo "Usage: ./configure <options> <args>"
   echo "   where <options> may be"
   echo "     -h display usage information"
   echo "   where <args> may be:"
   echo "     --prefix=<path>      Specify path to installation location (default: /usr/local)"
   echo "     --with-mpir=<path>   Specify location of MPIR (default: /usr/local)"
   echo "     --with-gmp=<path>    Specify location of GMP (default: /usr/local)"
   echo "     --with-mpfr=<path>   Specify location of MPFR (default: /usr/local)"
   echo "     --with-blas[=<path>] Use BLAS and specify its location (default: /usr/local)"
   echo "     --without-blas       Do not use BLAS (default)"
   echo "     --with-ntl[=<path>]  Build NTL interface and specify its location (default: /usr/local)"
   echo "     --without-ntl        Do not build NTL interface (default)"
   echo "     --extensions=<path>  Specify location of extension modules"
   echo "     --build=arch-os      Specify architecture/OS combination rather than use values from uname -m/-s"
   echo "     --enable-shared      Build a shared library (default)"
   echo "     --disable-shared     Do not build a shared library"
   echo "     --enable-static      Build a static library (default)"
   echo "     --disable-static     Do not build a static library"
   echo "     --single             Faster [non-reentrant if tls or pthread not used] version of library (default)"
   echo "     --reentrant          Build fully reentrant [with or without tls, with pthread] version of library"
   echo "     --with-gc=<path>     GC safe build with path to gc"
   echo "     --enable-pthread     Use pthread (default)"
   echo "     --disable-pthread    Do not use pthread"
   echo "     --enable-tls         Use thread-local storage (default)"
   echo "     --disable-tls        Do not use thread-local storage"
   echo "     --enable-assert      Enable use of asserts (use for debug builds only)"
   echo "     --disable-assert     Disable use of asserts (default)"
   echo "     --enable-cxx         Enable C++ wrapper tests"
   echo "     --disable-cxx        Disable C++ wrapper tests (default)"
   echo "     CC=<name>            Use the C compiler with the given name (default: gcc)"
   echo "     CXX=<name>           Use the C++ compiler with the given name (default: g++)"
   echo "     AR=<name>            Use the AR library builder with the given name (default: ar)"
   echo "     LDCONFIG=<name>      Use the given dynamic linker"
   echo "     CFLAGS=<flags>       Pass the given flags to the compiler"
   echo "     CXXFLAGS=<flags>     Pass the given flags to the C++ compiler"
   echo "     ABI=[32|64]          Tell the compiler to use given ABI (default: empty)"
}

absolute_path(){
   dirlist="$1"
   retval=""
   for dir in $dirlist; do
      case $dir in
        /*) dir=$dir;;
        *) dir=$PWD/$dir;;
      esac
      retval=$retval" "$dir
   done
   echo $retval
}

while [ "$1" != "" ]; do
   PARAM=`echo $1 | sed 's/=.*//'`
   VALUE=`echo $1 | sed 's/[^=]*//; s/=//'`
   case "$PARAM" in
      -h|--help)
         usage
         exit 0
         ;;
      --with-mpir|--with-gmp)
         GMP_DIR=$(absolute_path "$VALUE")
         ;;
      --with-mpfr)
         MPFR_DIR=$(absolute_path "$VALUE")
         ;;
      --with-ntl)
         WANT_NTL=1
         if [ ! -z "$VALUE" ]; then
            NTL_DIR=$(absolute_path "$VALUE")
         fi
         ;;
      --without-ntl)
         WANT_NTL=0
         ;;
      --with-blas)
         WANT_BLAS=1
         if [ ! -z "$VALUE" ]; then
            BLAS_DIR=$(absolute_path "$VALUE")
         fi
         ;;
      --without-blas)
         WANT_BLAS=0
         ;;
      --extensions)
         EXTENSIONS=$(absolute_path "$VALUE")
         ;;
      --build)
         BUILD="$VALUE"
         ;;
      --prefix)
         PREFIX=$VALUE
         ;;
      --enable-shared)
         SHARED=1
         ;;
      --disable-shared)
         SHARED=0
         ;;
      --enable-static)
         STATIC=1
         ;;
      --disable-static)
         STATIC=0
         ;;
      --single)
         REENTRANT=0
         ;;
      --reentrant)
         REENTRANT=1
         ;;
      --with-gc)
	 WANT_GC=1
         if [ ! -z "$VALUE" ]; then
            GC_DIR="$VALUE"
         fi
         ;;
      --enable-pthread)
         PTHREAD=1
         ;;
      --disable-pthread)
         PTHREAD=0
         ;;
      --enable-tls)
         TLS=1
         WANT_TLS=1;;
      --disable-tls)
         TLS=0
         ;;
      --enable-assert)
         ASSERT=1
         ;;
      --disable-assert)
         ASSERT=0
         ;;
      --enable-cxx)
         WANT_CXX=1
         ;;
      --disable-cxx)
         WANT_CXX=0
         ;;
      AR)
         AR="$VALUE"
         ;;
      CC)
         CC="$VALUE"
         ;;
      LDCONFIG)
         LDCONFIG="$VALUE"
         ;;
      CXX)
         CXX="$VALUE"
         ;;
      CFLAGS)
         CFLAGS="$VALUE"
         ;;
      CXXFLAGS)
         CXXFLAGS="$VALUE"
         ;;
      ABI)
         ABI="$VALUE"
         ;;
      *)
         usage
         exit 1
         ;;
   esac
   shift
done

#find dependencies

LIBS="m"

if [ -d "${GMP_DIR}/lib" ]; then
   GMP_LIB_DIR="${GMP_DIR}/lib"
   GMP_INC_DIR="${GMP_DIR}/include"
elif [ -d "${GMP_DIR}/lib64" ]; then
   GMP_LIB_DIR="${GMP_DIR}/lib64"
   GMP_INC_DIR="${GMP_DIR}/include"
elif [ -d "${GMP_DIR}/.libs" ]; then
   GMP_LIB_DIR="${GMP_DIR}/.libs"
   GMP_INC_DIR="${GMP_DIR}"
else
   echo "Invalid GMP directory"
   exit 1
fi
LIB_DIRS="${LIB_DIRS} ${GMP_LIB_DIR}"
INC_DIRS="${INC_DIRS} ${GMP_INC_DIR}"
LIBS="${LIBS} gmp"

if [ -d "${MPFR_DIR}/lib" ]; then
   MPFR_LIB_DIR="${MPFR_DIR}/lib"
   MPFR_INC_DIR="${MPFR_DIR}/include"
elif [ -d "${MPFR_DIR}/lib64" ]; then
   MPFR_LIB_DIR="${MPFR_DIR}/lib64"
   MPFR_INC_DIR="${MPFR_DIR}/include"
elif [ -d "${MPFR_DIR}/.libs" ]; then
   MPFR_LIB_DIR="${MPFR_DIR}/.libs"
   MPFR_INC_DIR="${MPFR_DIR}"
elif [ -d "${MPFR_DIR}/src/.libs" ]; then
   MPFR_LIB_DIR="${MPFR_DIR}/src/.libs"
   MPFR_INC_DIR="${MPFR_DIR}/src"
else
   echo "Invalid MPFR directory"
   exit 1
fi
LIB_DIRS="${LIB_DIRS} ${MPFR_LIB_DIR}"
INC_DIRS="${INC_DIRS} ${MPFR_INC_DIR}"
LIBS="${LIBS} mpfr"

#configure extra libraries

if [ "$WANT_NTL" = "1" ]; then
   if [ -d "${NTL_DIR}/lib" ]; then
      NTL_LIB_DIR="${NTL_DIR}/lib"
      NTL_INC_DIR="${NTL_DIR}/include"
   elif [ -d "${NTL_DIR}/lib64" ]; then
      NTL_LIB_DIR="${NTL_DIR}/lib64"
      NTL_INC_DIR="${NTL_DIR}/include"
   else
      echo "Invalid NTL directory"
      exit 1
   fi
   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${NTL_INC_DIR}"
   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${NTL_LIB_DIR}"
   EXTRA_LIBS="${EXTRA_LIBS} ntl"
fi

if [ "$WANT_BLAS" = "1" ]; then
   if [ -d "${BLAS_DIR}" ]; then
      BLAS_LIB_DIR="${BLAS_DIR}"
      BLAS_INC_DIR="${BLAS_DIR}"
   else
      echo "Invalid BLAS directory"
      exit 1
   fi
   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${BLAS_INC_DIR}"
   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${BLAS_LIB_DIR}"
   EXTRA_LIBS="${EXTRA_LIBS} openblas"
fi
CONFIG_BLAS="#define HAVE_BLAS ${WANT_BLAS}"

if [ "$WANT_GC" = "1" ]; then
   if [ -d "${GC_DIR}" ]; then
      GC_LIB_DIR="${GC_DIR}/lib"
      GC_INC_DIR="${GC_DIR}/include"
   else
      echo "Invalid GC directory"
      exit 1
   fi
   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${GC_INC_DIR}"
   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${GC_LIB_DIR}"
   EXTRA_LIBS="${EXTRA_LIBS} gc"
fi
CONFIG_GC="#define HAVE_GC ${WANT_GC}"

# defaults for CC, CXX and AR

if [ -z "$CC" ]; then
   CC=gcc
fi

if [ -z "$CXX" ]; then
   CXX=g++
fi

if [ -z "$AR" ]; then
   AR=ar
fi

#handle gc and reentrant flags

if [ "$WANT_GC" = "1" ]; then
      TLS=0
      if [ "$WANT_TLS" = "1" ]; then
          echo "****WARNING**** GC does not support TLS....disabling TLS"
      fi
      cp fmpz/link/fmpz_gc.c fmpz/fmpz.c
      cp fmpz-conversions-gc.in fmpz-conversions.h
else
   if [ "$REENTRANT" = "1" ]; then
      cp fmpz/link/fmpz_reentrant.c fmpz/fmpz.c
      cp fmpz-conversions-reentrant.in fmpz-conversions.h
   else
      cp fmpz/link/fmpz_single.c fmpz/fmpz.c
      cp fmpz-conversions-single.in fmpz-conversions.h
   fi
fi
# Architecture handler

KERNEL=`uname`

if [ -z "$BUILD" ]; then
   ARCH=`uname -m`

   if [ "$(uname | cut -d_ -f1)" = "MSYS" ]; then
      if [ "$(ARCH)" = "x86_64" ]; then
         OS="MINGW64"
      else
	 OS="MINGW32"
      fi
   elif [ "$(uname | cut -d_ -f1)" = "MINGW32" ]; then
      if [ "$ABI" = "64" ]; then
         OS="MINGW64"
      else
         OS="MINGW32"
      fi
   elif [ "$(uname | cut -d_ -f1)" = "MINGW64" ]; then
      if [ "$ABI" = "64" ]; then
         OS="MINGW64"
      else
         OS="MINGW32"
      fi
   elif [ "$(uname | cut -d_ -f1)" = "CYGWIN" ]; then
      if [ "$ARCH" = "x86_64" ]; then
         if [ "$ABI" = "32" ]; then
            OS="CYGWIN32"
         else
            OS="CYGWIN64"
            ABI="64"
         fi
      else
         OS="CYGWIN32"
      fi
   else
      OS=`uname -s`
   fi
else
   ARCH=`echo "$BUILD" | cut -d- -f1`
   OS=`echo "$BUILD" | cut -d- -f2`
fi

case "$ARCH" in
   x86_64 | amd64)
      MACHINE="x86_64";;
   x86 | i*86 | pc)
      MACHINE="x86";;
   ia64)
      MACHINE="ia64";;
   sparc | sun4*)
      MACHINE="sparc";;
   sparc64)
      MACHINE="sparc64";;
   ppc64 | powerpc64)
      MACHINE="ppc64";;
   ppc | powerpc | [P|p]ower*)
      MACHINE="ppc";;
   mips64)
      MACHINE="mips64";;
   *)
      MACHINE="unknown";;
esac

#ABI flag
if [ "$ABI" = "32" ]; then
   ABI_FLAG="-m32"
   case "$MACHINE" in
      x86_64)
         MACHINE="x86";;
      sparc64)
         MACHINE="sparc";;
      ppc64)
         MACHINE="ppc";;
      *)
         ;;
   esac
elif [ "$ABI" = "64" ]; then
   ABI_FLAG="-m64"
   if [ "$MACHINE" = "sparc" ]; then
      MACHINE="sparc64"
   fi
   if [ "$MACHINE" = "x86" ]; then
      MACHINE="x86_64"
   fi
fi

if [ "$MACHINE" = "sparc" ] || [ "$MACHINE" = "sparc64" ]; then
   if [ "$CC" = "gcc" ]; then
      CC="gcc -mno-relax"
   fi
fi

echo "Configuring...${MACHINE}-${OS}"

#FLINT shared library

if [ -z "$FLINT_LIB" ]; then
   case "$OS" in
      Darwin)
         FLINT_LIBNAME="libflint.dylib"
         FLINT_LIB="libflint-$FLINT_MAJOR.$FLINT_MINOR.$FLINT_PATCH.dylib"
         EXTRA_SHARED_FLAGS="-install_name $PREFIX/lib/$FLINT_LIB -compatibility_version $FLINT_MAJOR.$FLINT_MINOR -current_version $FLINT_MAJOR.$FLINT_MINOR.$FLINT_PATCH -Wl,-rpath,$GMP_LIB_DIR -Wl,-rpath,$MPFR_LIB_DIR";;
      CYGWIN* | MINGW*)
         FLINT_LIBNAME="libflint.dll"
         FLINT_LIB="libflint-$FLINT_MAJOR.dll"
         EXTRA_SHARED_FLAGS="-static-libgcc -shared -Wl,--export-all-symbols -Wl,-soname,libflint-$FLINT_MAJOR.dll.$FLINT_MINOR.$FLINT_PATCH -Wl,-rpath,$GMP_LIB_DIR -Wl,-rpath,$MPFR_LIB_DIR"
         FLINT_DLL=1;;
      *)
	 FLINT_LIBNAME="libflint.so"
         FLINT_LIB="libflint.so.$FLINT_MAJOR.$FLINT_MINOR.$FLINT_PATCH"
         EXTRA_SHARED_FLAGS="-Wl,-soname,libflint.so.$FLINT_MAJOR -Wl,-rpath,$GMP_LIB_DIR -Wl,-rpath,$MPFR_LIB_DIR"
	 FLINT_SOLIB=1
   esac
fi

# sometimes LDCONFIG is not to be found in the path. Look at some common places.
case "$OS" in
   MINGW*|CYGWIN*|Darwin)
      LDCONFIG="true";;
   *)
      if [ -z "$LDCONFIG" ]; then
         LDCONFIG="true"
         if [ "$FLINT_SOLIB" = "1" ]; then
            if command -v ldconfig > /dev/null; then
               LDCONFIG="ldconfig"
            elif [ -x /sbin/ldconfig ]; then
               LDCONFIG="/sbin/ldconfig"
            fi
         fi
      fi;;
esac

#extension for executables

if [ -z "$EXEEXT" ]; then
   case "$OS" in
      CYGWIN* | MINGW*)
         EXEEXT=".exe";;
      *)
         EXEEXT="";;
   esac
fi

#don't build both shared and static lib on MinGW and Cygwin

case "$OS" in
   CYGWIN* | MINGW*)
      if [ "$STATIC" = "1" ] && [ "$SHARED" = "1" ]; then
         echo "Building both static and shared versions of MPIR/GMP on $OS is currently"
         echo "unsupported, and so is it for MPFR and FLINT."
         echo "You should pass --disable-shared or --disable-static to configure"
         echo "depending on the versions of MPIR/GMP and MPFR you built."
         exit 1
      fi
      ;;
   *)
      ;;
esac 

#select fft_tuning parameters

case "$MACHINE" in
   x86_64 | ia64 | sparc64 | ppc64)
      cp fft_tuning64.in fft_tuning.h;;
   *)
      cp fft_tuning32.in fft_tuning.h;;
esac

#test for popcnt flag and set needed CFLAGS

mkdir -p build
rm -f build/test-popcnt > /dev/null 2>&1
MSG="Testing __builtin_popcountl..."
printf "%s" "$MSG"
echo "int main(int argc, char ** argv) { 
#if defined(_WIN64)
return __builtin_popcountll(argc) == 100;
#else
return __builtin_popcountl(argc) == 100;
#endif 
}" > build/test-popcnt.c
$CC build/test-popcnt.c -o ./build/test-popcnt > /dev/null 2>&1
if [ $? -eq 0 ]; then
   printf "%s\n" "yes"
   CONFIG_POPCNT_INTRINSICS="#define POPCNT_INTRINSICS"

   if [ "$MACHINE" = "x86_64" ]; then
      MSG="Testing native popcount..."
      printf "%s" "$MSG"
      touch build/test-popcnt.c
      rm build/test-popcnt
      $CC -mpopcnt build/test-popcnt.c -o ./build/test-popcnt > /dev/null 2>&1
      build/test-popcnt > /dev/null 2>&1
      if [ $? -eq 0 ]; then
         printf "%s\n" "yes"
         POPCNT_FLAG="-mpopcnt"
      else
         printf "%s\n" "no"
      fi
      rm -f build/test-popcnt{,.c}
   #in case -mpopcnt is not available, the test program will use an illegal
   #instruction and that will print out something on stderr when the if
   #construction is exited, whence the following "2> /dev/null"
   fi 2> /dev/null
else
   rm -f build/test-popcnt.c
   printf "%s\n" "no"
fi

#defaults for CFLAGS

if [ -z "$CFLAGS" ]; then
   if [ "$OS" = "MINGW64" ]; then
      CFLAGS="-O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
   elif [ "$OS" = "CYGWIN64" ]; then
      CFLAGS="-O2 -funroll-loops -g -D _WIN64 $POPCNT_FLAG $ABI_FLAG"
   elif [ "$MACHINE" = "mips64" ]; then
      CFLAGS="-O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
   else
      CFLAGS="-ansi -pedantic -Wall -O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
   fi
fi

#this is needed on PPC G5 and does not hurt on other OS Xes

if [ "$KERNEL" = Darwin ]; then
   CFLAGS="-fno-common $CFLAGS"
fi

#PIC flag

if [ -z "$PIC_FLAG" ]; then
   case "$OS" in
      CYGWIN* | MINGW*)
         ;;
      *)
         PIC_FLAG="-fPIC";;
   esac
fi

#test support for thread-local storage

CONFIG_TLS="#define HAVE_TLS 0"

if [ "$TLS" = "1" ]; then
   mkdir -p build
   rm -f build/test-tls > /dev/null 2>&1
   MSG="Testing __thread..."
   printf "%s" "$MSG"
   echo "__thread int x = 42; int main(int argc, char ** argv) { return x != 42; }" > build/test-tls.c
   $CC build/test-tls.c -o ./build/test-tls > /dev/null 2>&1
   if [ $? -eq 0 ]; then
      build/test-tls > /dev/null 2>&1
      if [ $? -eq 0 ]; then
         printf "%s\n" "yes"
         CONFIG_TLS="#define HAVE_TLS 1"
      else
         printf "%s\n" "no"
      fi
      rm -f build/test-tls{,.c}
   else
      rm -f build/test-tls.c
      printf "%s\n" "no"
   #build-tls can segfault on systems where tls is not available
   fi 2> /dev/null
fi

#fenv configuration

CONFIG_FENV="#define HAVE_FENV 0"

mkdir -p build
MSG="Testing fenv..."
printf "%s" "$MSG"
echo "#include <fenv.h>" > build/test-fenv.h
if ($CC -E build/test-fenv.h > /dev/null 2>&1) then
    printf "%s\n" "yes"
    CONFIG_FENV="#define HAVE_FENV 1"
else
    printf "%s\n" "no"
fi
rm -f build/test-fenv.h

#pthread configuration

CONFIG_PTHREAD="#define HAVE_PTHREAD ${PTHREAD}"


#external modules

EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${EXTENSIONS}"

#include paths

INCS="-I\$(CURDIR)"
for INC_DIR in ${INC_DIRS} ${EXTRA_INC_DIRS}; do
   INCS="${INCS} -I${INC_DIR}"
done

#library paths

LLIBS="-L\$(CURDIR)"
for LIB_DIR in ${LIB_DIRS} ${EXTRA_LIB_DIRS}; do
   LLIBS="${LLIBS} -L${LIB_DIR}"
done

#linker params

if [ "$PTHREAD" = "1" ]; then
   lLIBS2="-lpthread ${lLIBS2}"
fi


for LIB in ${EXTRA_LIBS} ${LIBS}; do
   lLIBS2="-l${LIB} ${lLIBS2}"
done
lLIBS="-lflint $lLIBS2"
LIBS2="$LLIBS $lLIBS2"
LIBS="$LLIBS $lLIBS"

#paths for dynamic linker

case "$OS" in
   CYGWIN* | MINGW*)
      DLPATH="PATH";;
   Darwin)
      DLPATH="DYLD_LIBRARY_PATH";;
   sparc)
      DLPATH="LD_LIBRARY_PATH32";;
   sparc64)
      DLPATH="LD_LIBRARY_PATH64";;
   *)
      DLPATH="LD_LIBRARY_PATH";;
esac

DLPATH_ADD="\$(CURDIR)"
for LIB_DIR in ${LIB_DIRS} ${EXTRA_LIB_DIRS}; do
   DLPATH_ADD="${DLPATH_ADD}:${LIB_DIR}"
done

#cxx

if [ "$WANT_CXX" = "1" ]; then
   EXTRA_BUILD="$EXTRA_BUILD flintxx"
fi

if [ -z "$CXXFLAGS" ]; then
   CXXFLAGS="$CFLAGS"
fi

#write out config.h

echo "/* This file is autogenerated by ./configure -- do not edit! */" > config.h
echo "$CONFIG_POPCNT_INTRINSICS" >> config.h
echo "$CONFIG_BLAS" >> config.h
echo "$CONFIG_TLS" >> config.h
echo "$CONFIG_FENV" >> config.h
echo "$CONFIG_PTHREAD" >> config.h
echo "$CONFIG_GC" >> config.h
echo "#define FLINT_REENTRANT $REENTRANT" >> config.h
echo "#define WANT_ASSERT $ASSERT" >> config.h
if [ "$FLINT_DLL" = "1" ]; then
   echo "#ifdef FLINT_USE_DLL" >> config.h
   echo "#define FLINT_DLL __declspec(dllimport)" >> config.h
   echo "#else" >> config.h
   echo "#define FLINT_DLL __declspec(dllexport)" >> config.h
   echo "#endif" >> config.h
else
   echo "#define FLINT_DLL" >> config.h
fi

#write out Makefile

echo "# This file is autogenerated by ./configure -- do not edit!" > Makefile
echo "" >> Makefile
echo "SHELL=/bin/sh" >> Makefile
echo "" >> Makefile
echo "FLINT_STATIC=$STATIC" >> Makefile
echo "FLINT_SHARED=$SHARED" >> Makefile
echo "FLINT_LIB=$FLINT_LIB" >> Makefile
echo "FLINT_LIBNAME=$FLINT_LIBNAME" >> Makefile
echo "FLINT_SOLIB=$FLINT_SOLIB" >> Makefile
echo "EXEEXT=$EXEEXT" >> Makefile
echo "PREFIX=$PREFIX" >> Makefile
echo "" >> Makefile
echo "WANT_NTL=$WANT_NTL" >> Makefile
echo "" >> Makefile
echo "INCS=$INCS" >> Makefile
echo "LIBS=$LIBS" >> Makefile
echo "LIBS2=$LIBS2" >> Makefile
echo "" >> Makefile
echo "CC=$CC" >> Makefile
echo "CXX=$CXX" >> Makefile
echo "AR=$AR" >> Makefile
echo "LDCONFIG=$LDCONFIG" >> Makefile
echo "" >> Makefile
echo "CFLAGS=$CFLAGS" >> Makefile
echo "CXXFLAGS=$CXXFLAGS" >> Makefile
echo "ABI_FLAG=$ABI_FLAG" >> Makefile
echo "PIC_FLAG=$PIC_FLAG" >> Makefile
echo "EXTRA_SHARED_FLAGS=$EXTRA_SHARED_FLAGS" >> Makefile
echo "" >> Makefile
echo "DLPATH=$DLPATH" >> Makefile
echo "DLPATH_ADD=$DLPATH_ADD" >> Makefile
echo "EXTENSIONS=$EXTENSIONS" >> Makefile
echo "EXTRA_BUILD_DIRS=$EXTRA_BUILD" >> Makefile
echo "" >> Makefile

cat Makefile.in >> Makefile

echo "FLINT was successfully configured."