1#!/bin/sh
2
3# (C) 2007, Robert Bradshaw, William Hart, William Stein, Michael Abshoff
4# (C) 2011, William Hart
5# (C) 2012, William Hart, Jean-Pierre Flori, Thomas DuBuisson
6# (C) 2012, Jan Engelhardt
7
8PREFIX="/usr/local"
9GMP_DIR="/usr/local"
10MPFR_DIR="/usr/local"
11NTL_DIR="/usr/local"
12GC_DIR="/usr/local"
13BLAS_DIR="/usr/local"
14WANT_NTL=0
15WANT_BLAS=0
16SHARED=1
17STATIC=1
18TLS=1
19PTHREAD=1
20REENTRANT=0
21WANT_GC=0
22WANT_TLS=0
23WANT_CXX=0
24ASSERT=0
25BUILD=
26EXTENSIONS=
27EXT_MODS=
28EXTRA_BUILD=
29FLINT_DLL=0
30FLINT_LIBNAME=
31FLINT_SOLIB=0
32
33# soname version, minor release number and patch number
34
35# Every major version of Flint (1.0, 1.1, 1.2, etc.) gets
36# a new major soname number.
37
38# Every time a release happens where interfaces are added
39# to Flint, the minor soname number gets incremented.
40
41# Every patch that is made that doesn't change the Flint
42# interface updates the patch number.
43
44# However, if backwards incompatible changes are made, both
45# the minor and patch numbers are set to 0. (Hopefully this
46# doesn't happen in practice.)
47
48# flint => soname
49# 2.5.0 => 13.5.0
50# 2.5.1 => 13.5.1
51# 2.5.2 => 13.5.2
52# 2.6.0 => 14.0.0
53
54FLINT_MAJOR=14
55FLINT_MINOR=0
56FLINT_PATCH=0
57
58usage()
59{
60   echo "Usage: ./configure <options> <args>"
61   echo "   where <options> may be"
62   echo "     -h display usage information"
63   echo "   where <args> may be:"
64   echo "     --prefix=<path>      Specify path to installation location (default: /usr/local)"
65   echo "     --with-mpir=<path>   Specify location of MPIR (default: /usr/local)"
66   echo "     --with-gmp=<path>    Specify location of GMP (default: /usr/local)"
67   echo "     --with-mpfr=<path>   Specify location of MPFR (default: /usr/local)"
68   echo "     --with-blas[=<path>] Use BLAS and specify its location (default: /usr/local)"
69   echo "     --without-blas       Do not use BLAS (default)"
70   echo "     --with-ntl[=<path>]  Build NTL interface and specify its location (default: /usr/local)"
71   echo "     --without-ntl        Do not build NTL interface (default)"
72   echo "     --extensions=<path>  Specify location of extension modules"
73   echo "     --build=arch-os      Specify architecture/OS combination rather than use values from uname -m/-s"
74   echo "     --enable-shared      Build a shared library (default)"
75   echo "     --disable-shared     Do not build a shared library"
76   echo "     --enable-static      Build a static library (default)"
77   echo "     --disable-static     Do not build a static library"
78   echo "     --single             Faster [non-reentrant if tls or pthread not used] version of library (default)"
79   echo "     --reentrant          Build fully reentrant [with or without tls, with pthread] version of library"
80   echo "     --with-gc=<path>     GC safe build with path to gc"
81   echo "     --enable-pthread     Use pthread (default)"
82   echo "     --disable-pthread    Do not use pthread"
83   echo "     --enable-tls         Use thread-local storage (default)"
84   echo "     --disable-tls        Do not use thread-local storage"
85   echo "     --enable-assert      Enable use of asserts (use for debug builds only)"
86   echo "     --disable-assert     Disable use of asserts (default)"
87   echo "     --enable-cxx         Enable C++ wrapper tests"
88   echo "     --disable-cxx        Disable C++ wrapper tests (default)"
89   echo "     CC=<name>            Use the C compiler with the given name (default: gcc)"
90   echo "     CXX=<name>           Use the C++ compiler with the given name (default: g++)"
91   echo "     AR=<name>            Use the AR library builder with the given name (default: ar)"
92   echo "     LDCONFIG=<name>      Use the given ldconfig tool"
93   echo "     CFLAGS=<flags>       Pass the given flags to the compiler"
94   echo "     CXXFLAGS=<flags>     Pass the given flags to the C++ compiler"
95   echo "     ABI=[32|64]          Tell the compiler to use given ABI (default: empty)"
96}
97
98absolute_path(){
99   dirlist="$1"
100   retval=""
101   for dir in $dirlist; do
102      case $dir in
103        /*) dir=$dir;;
104        *) dir=$PWD/$dir;;
105      esac
106      retval=$retval" "$dir
107   done
108   echo $retval
109}
110
111#begin config.log
112echo "/* This file is autogenerated by ./configure -- do not edit! */" > config.log
113echo "./configure $@" >> config.log
114
115while [ "$1" != "" ]; do
116   PARAM=`echo $1 | sed 's/=.*//'`
117   VALUE=`echo $1 | sed 's/[^=]*//; s/=//'`
118   case "$PARAM" in
119      -h|--help)
120         usage
121         exit 0
122         ;;
123      --with-mpir|--with-gmp)
124         GMP_DIR=$(absolute_path "$VALUE")
125         ;;
126      --with-mpfr)
127         MPFR_DIR=$(absolute_path "$VALUE")
128         ;;
129      --with-ntl)
130         WANT_NTL=1
131         if [ ! -z "$VALUE" ]; then
132            NTL_DIR=$(absolute_path "$VALUE")
133         fi
134         ;;
135      --without-ntl)
136         WANT_NTL=0
137         ;;
138      --with-blas)
139         WANT_BLAS=1
140         if [ ! -z "$VALUE" ]; then
141            BLAS_DIR=$(absolute_path "$VALUE")
142         fi
143         ;;
144      --without-blas)
145         WANT_BLAS=0
146         ;;
147      --extensions)
148         EXTENSIONS=$(absolute_path "$VALUE")
149         ;;
150      --build)
151         BUILD="$VALUE"
152         ;;
153      --prefix)
154         PREFIX=$(absolute_path "$VALUE")
155         ;;
156      --enable-shared)
157         SHARED=1
158         ;;
159      --disable-shared)
160         SHARED=0
161         ;;
162      --enable-static)
163         STATIC=1
164         ;;
165      --disable-static)
166         STATIC=0
167         ;;
168      --single)
169         REENTRANT=0
170         ;;
171      --reentrant)
172         REENTRANT=1
173         ;;
174      --with-gc)
175         WANT_GC=1
176         if [ ! -z "$VALUE" ]; then
177            GC_DIR="$VALUE"
178         fi
179         ;;
180      --enable-pthread)
181         PTHREAD=1
182         ;;
183      --disable-pthread)
184         PTHREAD=0
185         ;;
186      --enable-tls)
187         TLS=1
188         WANT_TLS=1;;
189      --disable-tls)
190         TLS=0
191         WANT_TLS=2;;
192      --enable-assert)
193         ASSERT=1
194         ;;
195      --disable-assert)
196         ASSERT=0
197         ;;
198      --enable-cxx)
199         WANT_CXX=1
200         ;;
201      --disable-cxx)
202         WANT_CXX=0
203         ;;
204      AR)
205         AR="$VALUE"
206         ;;
207      CC)
208         CC="$VALUE"
209         ;;
210      LDCONFIG)
211         LDCONFIG="$VALUE"
212         ;;
213      CXX)
214         CXX="$VALUE"
215         ;;
216      CFLAGS)
217         CFLAGS="$VALUE"
218         ;;
219      CXXFLAGS)
220         CXXFLAGS="$VALUE"
221         ;;
222      ABI)
223         ABI="$VALUE"
224         ;;
225      *)
226         usage
227         exit 1
228         ;;
229   esac
230   shift
231done
232
233#find dependencies
234
235LIBS="m"
236
237if [ -d "${GMP_DIR}/lib" ]; then
238   GMP_LIB_DIR="${GMP_DIR}/lib"
239   GMP_INC_DIR="${GMP_DIR}/include"
240elif [ -d "${GMP_DIR}/lib64" ]; then
241   GMP_LIB_DIR="${GMP_DIR}/lib64"
242   GMP_INC_DIR="${GMP_DIR}/include"
243elif [ -d "${GMP_DIR}/.libs" ]; then
244   GMP_LIB_DIR="${GMP_DIR}/.libs"
245   GMP_INC_DIR="${GMP_DIR}"
246else
247   echo "Invalid GMP directory"
248   echo "Invalid GMP directory: ${GMP_DIR}" >> config.log
249   exit 1
250fi
251LIB_DIRS="${LIB_DIRS} ${GMP_LIB_DIR}"
252INC_DIRS="${INC_DIRS} ${GMP_INC_DIR}"
253LIBS="${LIBS} gmp"
254
255if [ -d "${MPFR_DIR}/lib" ]; then
256   MPFR_LIB_DIR="${MPFR_DIR}/lib"
257   MPFR_INC_DIR="${MPFR_DIR}/include"
258elif [ -d "${MPFR_DIR}/lib64" ]; then
259   MPFR_LIB_DIR="${MPFR_DIR}/lib64"
260   MPFR_INC_DIR="${MPFR_DIR}/include"
261elif [ -d "${MPFR_DIR}/.libs" ]; then
262   MPFR_LIB_DIR="${MPFR_DIR}/.libs"
263   MPFR_INC_DIR="${MPFR_DIR}"
264elif [ -d "${MPFR_DIR}/src/.libs" ]; then
265   MPFR_LIB_DIR="${MPFR_DIR}/src/.libs"
266   MPFR_INC_DIR="${MPFR_DIR}/src"
267else
268   echo "Invalid MPFR directory"
269   echo "Invalid MPFR directory: ${MPFR_DIR}" >> config.log
270   exit 1
271fi
272LIB_DIRS="${LIB_DIRS} ${MPFR_LIB_DIR}"
273INC_DIRS="${INC_DIRS} ${MPFR_INC_DIR}"
274LIBS="${LIBS} mpfr"
275
276#configure extra libraries
277
278if [ "$WANT_NTL" = "1" ]; then
279   if [ -d "${NTL_DIR}/lib" ]; then
280      NTL_LIB_DIR="${NTL_DIR}/lib"
281      NTL_INC_DIR="${NTL_DIR}/include"
282   elif [ -d "${NTL_DIR}/lib64" ]; then
283      NTL_LIB_DIR="${NTL_DIR}/lib64"
284      NTL_INC_DIR="${NTL_DIR}/include"
285   else
286      echo "Invalid NTL directory"
287      echo "Invalid NTL directory: ${NTL_DIR}" >> config.log
288      exit 1
289   fi
290   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${NTL_INC_DIR}"
291   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${NTL_LIB_DIR}"
292   EXTRA_LIBS="${EXTRA_LIBS} ntl"
293fi
294
295if [ "$WANT_BLAS" = "1" ]; then
296   if [ -d "${BLAS_DIR}" ]; then
297      BLAS_LIB_DIR="${BLAS_DIR}"
298      BLAS_INC_DIR="${BLAS_DIR}"
299   else
300      echo "Invalid BLAS directory"
301      echo "Invalid BLAS directory: ${BLAS_DIR}" >> config.log
302      exit 1
303   fi
304   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${BLAS_INC_DIR}"
305   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${BLAS_LIB_DIR}"
306   EXTRA_LIBS="${EXTRA_LIBS} openblas"
307fi
308CONFIG_BLAS="#define HAVE_BLAS ${WANT_BLAS}"
309
310if [ "$WANT_GC" = "1" ]; then
311   if [ -d "${GC_DIR}" ]; then
312      GC_LIB_DIR="${GC_DIR}/lib"
313      GC_INC_DIR="${GC_DIR}/include"
314   else
315      echo "Invalid GC directory"
316      echo "Invalid GC directory: ${GC_DIR}" >> config.log
317      exit 1
318   fi
319   EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${GC_INC_DIR}"
320   EXTRA_LIB_DIRS="${EXTRA_LIB_DIRS} ${GC_LIB_DIR}"
321   EXTRA_LIBS="${EXTRA_LIBS} gc"
322fi
323CONFIG_GC="#define HAVE_GC ${WANT_GC}"
324
325# defaults for CC, CXX and AR
326
327if [ -z "$CC" ]; then
328   CC=gcc
329fi
330
331if [ -z "$CXX" ]; then
332   CXX=g++
333fi
334
335if [ -z "$AR" ]; then
336   AR=ar
337fi
338
339#handle gc and reentrant flags
340
341if [ "$WANT_GC" = "1" ]; then
342      TLS=0
343      if [ "$WANT_TLS" = "1" ]; then
344          echo "****WARNING**** GC does not support TLS....disabling TLS"
345	  echo "GC does not support TLS....disabling TLS" >> config.log
346      fi
347      cp fmpz/link/fmpz_gc.c fmpz/fmpz.c
348      cp fmpz-conversions-gc.in fmpz-conversions.h
349else
350   if [ "$REENTRANT" = "1" ]; then
351      cp fmpz/link/fmpz_reentrant.c fmpz/fmpz.c
352      cp fmpz-conversions-reentrant.in fmpz-conversions.h
353   else
354      cp fmpz/link/fmpz_single.c fmpz/fmpz.c
355      cp fmpz-conversions-single.in fmpz-conversions.h
356   fi
357fi
358# Architecture handler
359
360KERNEL=`uname`
361
362if [ -z "$BUILD" ]; then
363   ARCH=`uname -m`
364
365   if [ "$(uname | cut -d_ -f1)" = "MSYS" ]; then
366      if [ "$ARCH" = "x86_64" ]; then
367         OS="MINGW64"
368      else
369         OS="MINGW32"
370      fi
371   elif [ "$(uname | cut -d_ -f1)" = "MINGW32" ]; then
372      if [ "$ABI" = "64" ]; then
373         OS="MINGW64"
374      else
375         OS="MINGW32"
376      fi
377   elif [ "$(uname | cut -d_ -f1)" = "MINGW64" ]; then
378      if [ "$ABI" = "32" ]; then
379         OS="MINGW32"
380      else
381         OS="MINGW64"
382      fi
383   elif [ "$(uname | cut -d_ -f1)" = "CYGWIN" ]; then
384      if [ "$ARCH" = "x86_64" ]; then
385         if [ "$ABI" = "32" ]; then
386            OS="CYGWIN32"
387         else
388            OS="CYGWIN64"
389            ABI="64"
390         fi
391      else
392         OS="CYGWIN32"
393      fi
394   else
395      OS=`uname -s`
396   fi
397else
398   ARCH=`echo "$BUILD" | cut -d- -f1`
399   OS=`echo "$BUILD" | cut -d- -f2`
400fi
401
402case "$ARCH" in
403   x86_64 | amd64)
404      MACHINE="x86_64";;
405   x86 | i*86 | pc)
406      MACHINE="x86";;
407   ia64)
408      MACHINE="ia64";;
409   sparc | sun4*)
410      MACHINE="sparc";;
411   sparc64)
412      MACHINE="sparc64";;
413   ppc64 | powerpc64)
414      MACHINE="ppc64";;
415   ppc | powerpc | [P|p]ower*)
416      MACHINE="ppc";;
417   mips64)
418      MACHINE="mips64";;
419   *)
420      MACHINE="unknown";;
421esac
422
423#ABI flag
424if [ "$ABI" = "32" ]; then
425   ABI_FLAG="-m32"
426   case "$MACHINE" in
427      x86_64)
428         MACHINE="x86";;
429      sparc64)
430         MACHINE="sparc";;
431      ppc64)
432         MACHINE="ppc";;
433      *)
434         ;;
435   esac
436elif [ "$ABI" = "64" ]; then
437   ABI_FLAG="-m64"
438   if [ "$MACHINE" = "sparc" ]; then
439      MACHINE="sparc64"
440   fi
441   if [ "$MACHINE" = "x86" ]; then
442      MACHINE="x86_64"
443   fi
444fi
445
446if [ "$MACHINE" = "sparc" ] || [ "$MACHINE" = "sparc64" ]; then
447   if [ "$CC" = "gcc" ]; then
448      CC="gcc -mno-relax"
449   fi
450fi
451
452echo "Configuring...${MACHINE}-${OS}"
453echo "Configuring...${MACHINE}-${OS}" >> config.log
454
455#FLINT shared library
456
457if [ -z "$FLINT_LIB" ]; then
458   case "$OS" in
459      Darwin)
460         FLINT_LIBNAME="libflint.dylib"
461         FLINT_LIB="libflint-$FLINT_MAJOR.dylib"
462         EXTRA_SHARED_FLAGS="-install_name `pwd`/$FLINT_LIB"
463         EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -compatibility_version $FLINT_MAJOR.$FLINT_MINOR"
464         EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -current_version $FLINT_MAJOR.$FLINT_MINOR.$FLINT_PATCH"
465         ;;
466      CYGWIN* | MINGW*)
467         FLINT_LIBNAME="libflint.dll"
468         FLINT_LIB="libflint-$FLINT_MAJOR.dll"
469         EXTRA_SHARED_FLAGS="-static-libgcc"
470         EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -shared"
471         EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -Wl,--export-all-symbols"
472         EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -Wl,-soname,libflint-$FLINT_MAJOR.dll.$FLINT_MINOR.$FLINT_PATCH"
473         FLINT_DLL=1
474         ;;
475      *)
476         FLINT_LIBNAME="libflint.so"
477         FLINT_LIB="libflint.so.$FLINT_MAJOR.$FLINT_MINOR.$FLINT_PATCH"
478         EXTRA_SHARED_FLAGS="-Wl,-soname,libflint.so.$FLINT_MAJOR"
479         FLINT_SOLIB=1
480         ;;
481   esac
482 EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -Wl,-rpath,$GMP_LIB_DIR"
483 EXTRA_SHARED_FLAGS="$EXTRA_SHARED_FLAGS -Wl,-rpath,$MPFR_LIB_DIR"
484fi
485
486# sometimes LDCONFIG is not to be found in the path. Look at some common places.
487case "$OS" in
488   MINGW*|CYGWIN*|Darwin|FreeBSD)
489      LDCONFIG="true";;
490   *)
491      if [ -z "$LDCONFIG" ]; then
492         LDCONFIG="true"
493         if [ "$FLINT_SOLIB" = "1" ]; then
494            if command -v ldconfig > /dev/null; then
495               LDCONFIG="ldconfig"
496            elif [ -x /sbin/ldconfig ]; then
497               LDCONFIG="/sbin/ldconfig"
498            fi
499         fi
500      fi;;
501esac
502
503#extension for executables
504
505if [ -z "$EXEEXT" ]; then
506   case "$OS" in
507      CYGWIN* | MINGW*)
508         EXEEXT=".exe";;
509      *)
510         EXEEXT="";;
511   esac
512fi
513
514#don't build both shared and static lib on MinGW and Cygwin
515
516case "$OS" in
517   CYGWIN* | MINGW*)
518      if [ "$STATIC" = "1" ] && [ "$SHARED" = "1" ]; then
519         echo "Building both static and shared versions of MPIR/GMP on $OS is currently"
520         echo "unsupported, and so is it for MPFR and FLINT."
521         echo "You should pass --disable-shared or --disable-static to configure"
522         echo "depending on the versions of MPIR/GMP and MPFR you built."
523         echo "Both static and shared libraries is not permitted on $OS" >> config.log
524	 exit 1
525      fi
526      ;;
527   *)
528      ;;
529esac
530
531#select fft_tuning parameters
532
533case "$MACHINE" in
534   x86_64 | ia64 | sparc64 | ppc64)
535      cp fft_tuning64.in fft_tuning.h;;
536   *)
537      cp fft_tuning32.in fft_tuning.h;;
538esac
539
540#test for popcnt flag and set needed CFLAGS
541
542mkdir -p build
543rm -f build/test-popcnt > /dev/null 2>&1
544MSG="Testing __builtin_popcountl..."
545printf "%s" "$MSG"
546printf "%s" "$MSG" >> config.log
547echo "int main(int argc, char ** argv) {
548#if defined(_WIN64)
549return __builtin_popcountll(argc) == 100;
550#else
551return __builtin_popcountl(argc) == 100;
552#endif
553}" > build/test-popcnt.c
554$CC build/test-popcnt.c -o ./build/test-popcnt > /dev/null 2>&1
555if [ $? -eq 0 ]; then
556   printf "%s\n" "yes"
557   echo "yes" >> config.log
558   CONFIG_POPCNT_INTRINSICS="#define POPCNT_INTRINSICS"
559
560   if [ "$MACHINE" = "x86_64" ]; then
561      MSG="Testing native popcount..."
562      printf "%s" "$MSG"
563      printf "%s" "$MSG" >> config.log
564      touch build/test-popcnt.c
565      rm build/test-popcnt
566      $CC -mpopcnt build/test-popcnt.c -o ./build/test-popcnt > /dev/null 2>&1
567      build/test-popcnt > /dev/null 2>&1
568      if [ $? -eq 0 ]; then
569         printf "%s\n" "yes"
570         echo "yes" >> config.log
571	 POPCNT_FLAG="-mpopcnt"
572      else
573         printf "%s\n" "no"
574	 echo "no" >> config.log
575      fi
576      rm -f build/test-popcnt{,.c}
577   #in case -mpopcnt is not available, the test program will use an illegal
578   #instruction and that will print out something on stderr when the if
579   #construction is exited, whence the following "2> /dev/null"
580   fi 2> /dev/null
581else
582   rm -f build/test-popcnt.c
583   printf "%s\n" "no"
584   echo "no" >> config.log
585fi
586
587#defaults for CFLAGS
588if [ -z "$CFLAGS" ]; then
589   if [ "$OS" = "MINGW64" ]; then
590      CFLAGS="-std=c99 -O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
591      ANSI_FLAG=""
592   elif [ "$OS" = "CYGWIN64" ]; then
593      CFLAGS="-O2 -funroll-loops -g -D _WIN64 $POPCNT_FLAG $ABI_FLAG"
594      ANSI_FLAG=""
595   elif [ "$MACHINE" = "mips64" ]; then
596      CFLAGS="-O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
597      ANSI_FLAG=""
598   elif test "$KERNEL" = "FreeBSD" -o "$OS" = "OpenBSD"; then
599      CFLAGS="-std=c99 -pedantic -Wall -O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
600      ANSI_FLAG=""
601      CXXFLAGS="-std=c++11 -pedantic -Wall -O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
602   else
603      ANSI_FLAG="-ansi"
604      CFLAGS="-pedantic -Wall -O2 -funroll-loops -g $POPCNT_FLAG $ABI_FLAG"
605   fi
606fi
607
608#this is needed on PPC G5 and does not hurt on other OS Xes
609
610if [ "$KERNEL" = Darwin ]; then
611   CFLAGS="-fno-common $CFLAGS"
612fi
613
614#PIC flag
615
616if [ -z "$PIC_FLAG" ]; then
617   case "$OS" in
618      CYGWIN* | MINGW*)
619         ;;
620      *)
621         PIC_FLAG="-fPIC";;
622   esac
623fi
624
625#test support for thread-local storage
626
627CONFIG_TLS="#define HAVE_TLS 0"
628
629if [ "$TLS" = "1" ]; then
630   mkdir -p build
631   rm -f build/test-tls > /dev/null 2>&1
632   MSG="Testing __thread..."
633   printf "%s" "$MSG"
634   printf "%s" "$MSG" >> config.log
635   echo "__thread int x = 42; int main(int argc, char ** argv) { return x != 42; }" > build/test-tls.c
636   $CC build/test-tls.c -o ./build/test-tls > /dev/null 2>&1
637   if [ $? -eq 0 ]; then
638      build/test-tls > /dev/null 2>&1
639      if [ $? -eq 0 ]; then
640         printf "%s\n" "yes"
641	 echo "yes" >> config.log
642         CONFIG_TLS="#define HAVE_TLS 1"
643      else
644         printf "%s\n" "no"
645	 echo "no" >> config.log
646      fi
647      rm -f build/test-tls{,.c}
648   else
649      rm -f build/test-tls.c
650      printf "%s\n" "no"
651      echo "no" >> config.log
652   #build-tls can segfault on systems where tls is not available
653   fi 2> /dev/null
654fi
655
656#fenv configuration
657
658CONFIG_FENV="#define HAVE_FENV 0"
659
660mkdir -p build
661MSG="Testing fenv..."
662printf "%s" "$MSG"
663printf "%s" "$MSG" >> config.log
664echo "#include <fenv.h>" > build/test-fenv.h
665echo "#ifndef FE_DOWNWARD" >> build/test-fenv.h
666echo "#error FE_DOWNWARD not available" >> build/test-fenv.h
667echo "#endif" >> build/test-fenv.h
668if ($CC -E build/test-fenv.h > /dev/null 2>&1) then
669    printf "%s\n" "yes"
670    echo "yes" >> config.log
671    CONFIG_FENV="#define HAVE_FENV 1"
672else
673    printf "%s\n" "no"
674    echo "no" >> config.log
675fi
676rm -f build/test-fenv.h
677
678#pthread configuration
679
680CONFIG_PTHREAD="#define HAVE_PTHREAD ${PTHREAD}"
681
682#cpu_set_t configuration
683
684CONFIG_CPU_SET_T="#define HAVE_CPU_SET_T 0"
685
686mkdir -p build
687MSG="Testing cpu_set_t..."
688printf "%s" "$MSG"
689printf "%s" "$MSG" >> config.log
690echo "#define _GNU_SOURCE
691#include <sched.h>
692int main(){cpu_set_t s;CPU_ZERO(&s);return 0;}" > build/test-cpu_set_t.c
693$CC build/test-cpu_set_t.c -o ./build/test-cpu_set_t > /dev/null 2>&1
694if [ $? -eq 0 ]; then
695    rm -f build/test-cpu_set_t
696    printf "%s\n" "yes"
697    echo "yes" >> config.log
698    CONFIG_CPU_SET_T="#define HAVE_CPU_SET_T 1"
699else
700    printf "%s\n" "no"
701    echo "no" >> config.log
702fi
703rm -f build/test-cpu_set_t.c
704
705
706#external modules
707
708EXTRA_INC_DIRS="${EXTRA_INC_DIRS} ${EXTENSIONS}"
709
710#include paths
711
712INCS="-I\$(CURDIR) -I\$(CURDIR)/build"
713for INC_DIR in ${INC_DIRS} ${EXTRA_INC_DIRS}; do
714   INCS="${INCS} -I${INC_DIR}"
715done
716
717#library paths
718
719LLIBS="-L\$(CURDIR)"
720for LIB_DIR in ${LIB_DIRS} ${EXTRA_LIB_DIRS}; do
721   LLIBS="${LLIBS} -L${LIB_DIR}"
722done
723
724#linker params
725
726if [ "$PTHREAD" = "1" ]; then
727   lLIBS2="-lpthread ${lLIBS2}"
728fi
729
730
731for LIB in ${EXTRA_LIBS} ${LIBS}; do
732   lLIBS2="-l${LIB} ${lLIBS2}"
733done
734lLIBS="-lflint $lLIBS2"
735LIBS2="$LLIBS $lLIBS2"
736LIBS="$LLIBS $lLIBS"
737
738#cxx
739
740if [ "$WANT_CXX" = "1" ]; then
741   EXTRA_BUILD="$EXTRA_BUILD flintxx"
742fi
743
744if [ -z "$CXXFLAGS" ]; then
745   CXXFLAGS="$CFLAGS"
746fi
747
748#write out flint-config.h
749
750echo "/* This file is autogenerated by ./configure -- do not edit! */" > flint-config.h
751echo "$CONFIG_POPCNT_INTRINSICS" >> flint-config.h
752echo "$CONFIG_BLAS" >> flint-config.h
753echo "$CONFIG_TLS" >> flint-config.h
754echo "$CONFIG_FENV" >> flint-config.h
755echo "$CONFIG_PTHREAD" >> flint-config.h
756echo "$CONFIG_GC" >> flint-config.h
757echo "$CONFIG_CPU_SET_T" >> flint-config.h
758echo "#define FLINT_REENTRANT $REENTRANT" >> flint-config.h
759echo "#define WANT_ASSERT $ASSERT" >> flint-config.h
760if [ "$FLINT_DLL" = "1" ]; then
761   echo "#ifdef FLINT_USE_DLL" >> flint-config.h
762   echo "#define FLINT_DLL __declspec(dllimport)" >> flint-config.h
763   echo "#else" >> flint-config.h
764   echo "#define FLINT_DLL __declspec(dllexport)" >> flint-config.h
765   echo "#endif" >> flint-config.h
766else
767   echo "#define FLINT_DLL" >> flint-config.h
768fi
769
770#write out Makefile
771
772echo "# This file is autogenerated by ./configure -- do not edit!" > Makefile
773echo "" >> Makefile
774echo "SHELL=/bin/sh" >> Makefile
775echo "" >> Makefile
776echo "GMP_LIB_DIR=$GMP_LIB_DIR" >> Makefile
777echo "MPFR_LIB_DIR=$MPFR_LIB_DIR" >> Makefile
778echo "" >> Makefile
779echo "FLINT_STATIC=$STATIC" >> Makefile
780echo "FLINT_SHARED=$SHARED" >> Makefile
781echo "FLINT_LIB=$FLINT_LIB" >> Makefile
782echo "FLINT_LIBNAME=$FLINT_LIBNAME" >> Makefile
783echo "OS=$OS" >> Makefile
784echo "FLINT_SOLIB=$FLINT_SOLIB" >> Makefile
785echo "FLINT_MAJOR=$FLINT_MAJOR" >> Makefile
786echo "EXEEXT=$EXEEXT" >> Makefile
787echo "PREFIX=$PREFIX" >> Makefile
788echo "" >> Makefile
789echo "WANT_NTL=$WANT_NTL" >> Makefile
790echo "" >> Makefile
791echo "INCS=$INCS" >> Makefile
792echo "LIBS=$LIBS" >> Makefile
793echo "LIBS2=$LIBS2" >> Makefile
794echo "" >> Makefile
795echo "CC=$CC" >> Makefile
796echo "CXX=$CXX" >> Makefile
797echo "AR=$AR" >> Makefile
798echo "LDCONFIG=$LDCONFIG" >> Makefile
799echo "" >> Makefile
800echo "CFLAGS=$ANSI_FLAG $CFLAGS" >> Makefile
801echo "CXXFLAGS=$CXXFLAGS" >> Makefile
802echo "ABI_FLAG=$ABI_FLAG" >> Makefile
803echo "PIC_FLAG=$PIC_FLAG" >> Makefile
804echo "EXTRA_SHARED_FLAGS=$EXTRA_SHARED_FLAGS" >> Makefile
805echo "" >> Makefile
806echo "EXTENSIONS=$EXTENSIONS" >> Makefile
807echo "EXTRA_BUILD_DIRS=$EXTRA_BUILD" >> Makefile
808echo "" >> Makefile
809
810
811cat Makefile.in >> Makefile
812
813echo "FLINT was successfully configured."
814echo "FLINT was successfully configured." >> config.log
815