File: configure.ac

package info (click to toggle)
sollya 6.0+ds-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,376 kB
  • ctags: 5,132
  • sloc: ansic: 120,010; yacc: 8,738; lex: 2,494; makefile: 854; cpp: 76
file content (795 lines) | stat: -rw-r--r-- 31,253 bytes parent folder | download
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
#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.
# Skeleton initially generated with autoscan
AC_PREREQ(2.59)
AC_INIT([sollya], [6.0], [sollya-devl@lists.gforge.inria.fr])
AC_CONFIG_MACRO_DIR([m4])  # To please autoconf. See c8fd07aa1d2bd54f8c1b519052849aed1ec39663
AC_CONFIG_AUX_DIR([build-aux]) # Put auxiliary files of autoconf into a specific directory
AC_CONFIG_SRCDIR([sollya-library-wrappers.h]) # Checks that we are really trying to configure Sollya and not something else...
AC_CONFIG_HEADER([config.h])
AM_INIT_AUTOMAKE([1.6 no-define dist-zip dist-bzip2])
AM_MAINTAINER_MODE([]) # Disables automatic call to ./configure after a modification has been made to configure.ac, Makefile.am, etc.
                       # This simplifies the life of Debian maintainers when they apply patches.
                       # The default behavior (automatic call to ./configure when necessary), that is probably desired for every-day developers is achieved by passing the option --enable-maintainer-mode to configure.

m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) # On systems with a recent version of automake, produces a more synthetic output when compiling

# Checks for programs.
AC_PROG_YACC
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_AWK  # Used by ltmain.sh
AC_PROG_SED  # Used in some tests (although we do not currently use its replacement variable $SED)
AM_PROG_CC_C_O  # To please autoconf. See 68da652992422c073b8bd2fe0814cd1cf37ee1fc

AC_LANG_PUSH([C++])
AC_MSG_CHECKING([whether C++ compiler works])
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]], [[exit(0);]])],
               [AC_MSG_RESULT(yes)],
               [AC_MSG_ERROR(no)])
AC_LANG_POP([C++])
AC_PROG_LEX
if test "$missing_dir" = ""; then
   missing_dir="."
fi
if test "$LEX" != flex; then
  LEX="$SHELL $missing_dir/missing flex"
  AC_SUBST(LEX_OUTPUT_ROOT, lex.yy)
  AC_SUBST(LEXLIB, '')
fi
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_MKDIR_P
AC_LIBTOOL_DLOPEN
LT_INIT([dlopen shared])   # AC_PROG_RANLIB is superseeded by LT_INIT
AC_SUBST(LIBTOOL_DEPS)
AC_SUBST(AR_FLAGS, "cr")   # To prevent a warning on some Ubuntu. See fbb8016beff7b45734e53ef8b80d2c306334c248
AC_PATH_PROG([HELP2MAN],[help2man],[no])
AM_CONDITIONAL([HAVE_HELP2MAN], [test "x$HELP2MAN" != "xno"])

#Checking for pdflatex with the required packages
AC_PATH_PROG([PDFLATEX],[pdflatex],[no])
if test "x$PDFLATEX" != "xno"
then
  AC_MSG_CHECKING([that pdflatex comes with the necessary packages])
  rm -rf .tmp_sollya_ac_pdflatex
  mkdir .tmp_sollya_ac_pdflatex
  cd .tmp_sollya_ac_pdflatex
  echo "\documentclass@<:@a4paper@:>@{article}" > conftest.tex
  echo "\usepackage@<:@T1@:>@{fontenc}" >> conftest.tex
  echo "\usepackage@<:@utf8@:>@{inputenc}" >> conftest.tex
  echo "\usepackage@<:@english@:>@{babel}" >> conftest.tex
  echo "\usepackage@<:@naturalnames@:>@{hyperref}" >> conftest.tex
  echo "\usepackage{fullpage}" >> conftest.tex
  echo "\usepackage{xspace}" >> conftest.tex
  echo "\usepackage{amssymb}" >> conftest.tex
  echo "\usepackage{fancyvrb}" >> conftest.tex
  echo "\usepackage{cmap}" >> conftest.tex
  echo "\usepackage{lmodern}" >> conftest.tex
  echo "\usepackage{color}" >> conftest.tex
  echo "\usepackage{tocloft}" >> conftest.tex
  echo "\begin{document}" >> conftest.tex
  echo "Test" >> conftest.tex
  echo "\end{document}" >> conftest.tex
  PDFLATEX_WITH_PACKAGES="no"
  $PDFLATEX -interaction=batchmode conftest.tex 2>&1 1>/dev/null && PDFLATEX_WITH_PACKAGES="$PDFLATEX"
  PDFLATEX="$PDFLATEX_WITH_PACKAGES"
  cd ..
  rm -rf .tmp_sollya_ac_pdflatex
fi
if test "x$PDFLATEX" != "xno"
then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi
AM_CONDITIONAL([HAVE_PDFLATEX], [test "x$PDFLATEX" != "xno"])



#Check whether flex and bison support interactive and pure parsers
AC_ARG_ENABLE(strict-lexer-parser-check,
              [[  --enable-strict-lexer-parser-check enables strict compatibility checking for building the lexer and parser files]],
              [STRICTFLEXBISONTESTING="1"],
              [STRICTFLEXBISONTESTING=""])

AC_MSG_CHECKING([flex supports interactive and pure lexers])
if test `echo -e "%{\n%}\n\n%option always-interactive\n%option reentrant\n%option prefix=\"coucou\"\n%option bison-bridge\n%option nounput\n\n%%\n"test" { }\n%%\n" > conftest.l ; $LEX conftest.l > /dev/null 2> /dev/null ; echo $?; rm -f lex.coucou.c` -eq 0
then
  AC_MSG_RESULT(yes)
else
  if test "x$STRICTFLEXBISONTESTING" = "x"
  then
    AC_MSG_RESULT([flex version unable to compile the lexer from the grammar files])
  else
    AC_MSG_ERROR(no)
  fi
fi

AC_MSG_CHECKING([bison supports interactive and pure parsers])
if test `echo -e "%{\n#define YYERROR_VERBOSE 1\n#define YYPARSE_PARAM scanner\n#define YYLEX_PARAM scanner\n%}\n\n%defines\n%name-prefix \"internyy\"\n%pure-parser\n\n%%\nstart: \".\"\n{ }\n;\n\n" > conftest.y ; $YACC conftest.y > /dev/null 2> /dev/null ; echo $?; rm -f y.tab.*` -eq 0
then
  AC_MSG_RESULT(yes)
else
  if test "x$STRICTFLEXBISONTESTING" = "x"; then
    AC_MSG_RESULT([bison version unable to compile the parser from the grammar files])
  else
    AC_MSG_ERROR(no)
  fi
fi

# withs...
SO_LIB_PATH=""
FPLLLVERSIONSTRING=""

AC_ARG_WITH(gmp-include,
            [  --with-gmp-include=DIR  GMP include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
             fi])
AC_ARG_WITH(gmp-lib,
            [  --with-gmp-lib=DIR      GMP lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_LDFLAGS="$AM_LDFLAGS -L$withval"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval"
             fi
            ])
AC_ARG_WITH(gmp,
            [  --with-gmp=DIR          GMP install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval/lib"
             fi
            ])


AC_ARG_WITH(mpfr-include,
            [  --with-mpfr-include=DIR  MPFR include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
	     fi])
AC_ARG_WITH(mpfr-lib,
            [  --with-mpfr-lib=DIR      MPFR lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_LDFLAGS="$AM_LDFLAGS -L$withval"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval"
	     fi
            ])
AC_ARG_WITH(mpfr,
            [  --with-mpfr=DIR          MPFR install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval/lib"
	     fi
            ])


AC_ARG_WITH(fplll-include,
            [  --with-fplll-include=DIR  fplll include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
               FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING--with-fplll-include given as '$withval', "
	     fi
            ])
AC_ARG_WITH(fplll-lib,
            [  --with-fplll-lib=DIR      fplll lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_LDFLAGS="$AM_LDFLAGS -L$withval"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval"
               FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING--with-fplll-lib given as '$withval', "
	     fi
            ])
AC_ARG_WITH(fplll,
            [  --with-fplll=DIR          fplll install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval/lib"
               FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING--with-fplll given as '$withval', "
	     fi
            ])


AC_ARG_WITH(z-include,
            [  --with-z-include=DIR  z include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
	     fi])
AC_ARG_WITH(z-lib,
            [  --with-z-lib=DIR      z lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_LDFLAGS="$AM_LDFLAGS -L$withval"
	     fi])
AC_ARG_WITH(z,
            [  --with-z=DIR          z install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
	     fi
            ])


AC_ARG_WITH(iconv-include,
            [  --with-iconv-include=DIR  iconv include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
	     fi])
AC_ARG_WITH(iconv-lib,
            [  --with-iconv-lib=DIR      iconv lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_LDFLAGS="$AM_LDFLAGS -L$withval"
	     fi])
AC_ARG_WITH(iconv,
            [  --with-iconv=DIR          iconv install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
             fi
	    ])


AC_ARG_WITH(mpfi-include,
            [  --with-mpfi-include=DIR  MPFI include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_CPPFLAGS="$AM_CPPFLAGS -I$withval"
	     fi])
AC_ARG_WITH(mpfi-lib,
            [  --with-mpfi-lib=DIR      MPFI lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_LDFLAGS="$AM_LDFLAGS -L$withval"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval"
	     fi
            ])
AC_ARG_WITH(mpfi,
            [  --with-mpfi=DIR          MPFI install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval/lib"
	     fi
            ])


XML2INCLUDEGIVEN=""
XML2LIBGIVEN=""
AC_ARG_WITH(xml2-include,
            [  --with-xml2-include=DIR  XML2 include directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
	       AM_CPPFLAGS="$AM_CPPFLAGS -I$withval -I$withval/libxml2"
               XML2INCLUDEGIVEN=1
	     fi
            ])
AC_ARG_WITH(xml2-lib,
            [  --with-xml2-lib=DIR      XML2 lib directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_LDFLAGS="$AM_LDFLAGS -L$withval"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval"
               XML2LIBGIVEN=1
	     fi
            ])
AC_ARG_WITH(xml2,
            [  --with-xml2=DIR          XML2 install directory ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               AM_CPPFLAGS="$AM_CPPFLAGS -I$withval/include -I$withval/include/libxml2"
               AM_LDFLAGS="$AM_LDFLAGS -L$withval/lib"
               SO_LIB_PATH="${SO_LIB_PATH:+$SO_LIB_PATH:}$withval/lib"
               XML2INCLUDEGIVEN=1
               XML2LIBGIVEN=1
	     fi
            ])


#Add xml2 include and lib
XML2CONFIGGIVEN=""
AC_ARG_WITH(xml2-config,
            [  --with-xml2-config=executable XML2 config tool ],
            [if test "x$withval" != "xyes" -a "x$withval" != "x"
             then
               XML2CONFIG="$withval"
               XML2CONFIGGIVEN=1
	     fi
            ])

if test "x$XML2CONFIGGIVEN" = "x"
then
  AC_CHECK_PROG(XML2CONFIG, xml2-config, [xml2-config], [false])
fi

if test "x$XML2INCLUDEGIVEN" = "x"
then
  AM_CPPFLAGS="$AM_CPPFLAGS "`$XML2CONFIG --cflags`
fi

if test "x$XML2LIBGIVEN" = "x"
then
  XML2LIBS=`$XML2CONFIG --libs --static`
  XML2LIBSPURE=`$XML2CONFIG --libs | $SED -e 's/^-l//g;s/[[:blank:]]-l//g;'`
  AC_SEARCH_LIBS([xmlTextReaderIsEmptyElement], [$XML2LIBSPURE], [], [], [$XML2LIBS])
fi


# Save user flags and set flags given by configure for the rest of the tests
USER_CFLAGS="$CFLAGS"
USER_CXXFLAGS="$CXXFLAGS"
USER_CPPFLAGS="$CPPFLAGS"
USER_LDFLAGS="$LDFLAGS"
CFLAGS="$AM_CFLAGS $USER_CFLAGS"
CXXFLAGS="$AM_CXXFLAGS $USER_CXXFLAGS"
CPPFLAGS="$AM_CPPFLAGS $USER_CPPFLAGS"
LDFLAGS="$AM_LDFLAGS $USER_LDFLAGS"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$SO_LIB_PATH"

# Checks for libraries.
dlopen_ok="yes"
AC_CHECK_LIB([c], [dlopen], [], [dlopen_ok="no"])
if test "x${dlopen_ok}y" = "xnoy" ; then
  AC_CHECK_LIB([dl], [dlopen], [], AC_MSG_ERROR([libdl unusable]))
fi
AC_CHECK_LIB([gmp], [__gmpz_init], [true], AC_MSG_ERROR([libgmp unusable]))
AC_CHECK_LIB([gmp], [__gmpz_fac_ui], [true], AC_MSG_ERROR([libgmp version too old]))
AC_CHECK_LIB([gmp], [__gmpz_bin_uiui], [true], AC_MSG_ERROR([libgmp version too old]))
AC_CHECK_LIB([gmp], [__gmpz_export], [], AC_MSG_ERROR([libgmp version too old])) # This one adds -lgmp in case of success
AC_CHECK_LIB([mpfr], [mpfr_init], [true], AC_MSG_ERROR([libmpfr unusable]))
AC_CHECK_LIB([mpfr], [mpfr_set_z_2exp], [true], AC_MSG_ERROR([libmpfr version too old]))
AC_CHECK_LIB([mpfr], [mpfr_erfc], [], AC_MSG_ERROR([libmpfr version too old])) # This one adds -lmpfr in case of success
AC_CHECK_LIB([mpfi], [mpfi_init], [], AC_MSG_ERROR([libmpfi unusable]))
####AC_CHECK_LIB([z], [gzdopen], [], [])
####AC_CHECK_LIB([iconv], [libiconv_open], [], []) # This for providing a statically linked program under Cygwin. See e0d7171f9daf0027e075723d21fb40a864578cd5
AC_CHECK_LIB([m],[cos])
AC_CHECK_LIB([xml2], [xmlTextReaderIsEmptyElement], [], AC_MSG_ERROR([libxml2 unusable]))

# Check that dynamic libraries are available at runtime
AC_MSG_CHECKING([if libgmp is found at runtime])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <gmp.h>]],
                               [[mpz_t a; mpz_init(a); mpz_clear(a); return 0;]])],
	      [AC_MSG_RESULT(yes)],
              [AC_MSG_WARN([libgmp is found at compile time but not at run time. Checking /etc/ld.so.conf and running ldconfig could fix the problem.])])


AC_MSG_CHECKING([if libmpfr is found at runtime])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <mpfr.h>]],
                               [[mpfr_t a; mpfr_init2(a, 53); mpfr_clear(a); return 0;]])],
	      [AC_MSG_RESULT(yes)],
              [AC_MSG_WARN([libmpfr is found at compile time but not at run time. Checking /etc/ld.so.conf and running ldconfig could fix the problem.])])


AC_MSG_CHECKING([if libmpfi is found at runtime])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <mpfi.h>]],
                               [[mpfi_t a; mpfi_init(a); mpfi_clear(a); return 0;]])],
	      [AC_MSG_RESULT(yes)],
              [AC_MSG_ERROR([libmpfi is found at compile time but not at run time. Checking /etc/ld.so.conf and running ldconfig could fix the problem.])])


AC_MSG_CHECKING([if libxml2 is found at runtime])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <libxml/xmlreader.h>]],
                               [[xmlCleanupParser(); return 0;]])],
	      [AC_MSG_RESULT(yes)],
              [AC_MSG_WARN([libxml2 is found at compile time but not at run time. Checking /etc/ld.so.conf and running ldconfig could fix the problem.])])



#Special check for fplll
AC_LANG_PUSH([C++])

#Check for -std=c++11 or -std=gnu++11
CXXFLAGS="$AM_CXXFLAGS -std=c++11 $USER_CXXFLAGS"
AC_MSG_CHECKING([for -std=c++11 or -std=gnu++11 support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
                  [
                     AC_MSG_RESULT(yes)
                     STDCXX11="-std=c++11"
                  ],
                  [
		     CXXFLAGS="$AM_CXXFLAGS -std=gnu++11 $USER_CXXFLAGS"
		     AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
                     		       [
                                          AC_MSG_RESULT(yes)
					  STDCXX11="-std=gnu++11"
				       ],
				       [
				          AC_MSG_RESULT(no)
					  STDCXX11=""
				       ])
		  ])

# We currently have 4 parameters that can take two values and depending on the version of fplll and g++, a given combination of them might work or not:
#  - include <fplll.h> or <fplll/fplll.h>
#  - link with -lfplll flag or not
#  - use -std=c+11 or not
#  - use the old or new API of fplll
# It seems reasonable to filter the 16 possible cases by noticing that the the necessity of including the -std option is quite recent, whereas the include <fplll/fplll.h> actually corresponds to fairly old versions of fplll. Also, the compilation with -lfplll is required for quite a while now.
# We first assume a relatively recent vers of fplll: trying include <fplll.h> and linking with -lfplll, we explore the 4 remaining possibilities.
# If none of these possibilities worked, we assume a fairly old version of fplll: trying the old API and without the -std option, we explore the 3 remaining possibilitie.
# If nothing worked of these 7 possibilities, we give up.

FPLLL_PROGV3=`printf "\
  ZZ_mat<mpz_t> *M; Z_NR<mpz_t>  zval; mpz_t mpzval; wrapper *LLLwrapper; int i,j;\n\
  mpz_init(mpzval);\n\
  M = new ZZ_mat<mpz_t>(3, 3);\n\
  for(i=0;i<=2;i++) {\n\
    for(j=0;j<=2;j++) {\n\
      mpz_set_ui(mpzval, (i+1)*(j+2));\n\
      zval.set(mpzval);\n\
      M->Set(i,j,zval);\n\
    }\n\
  }\n\
  LLLwrapper = new wrapper(M);\n\
  LLLwrapper->LLL();\
"`
FPLLL_PROG=`printf "\
  ZZ_mat<mpz_t> *M; Z_NR<mpz_t>  zval; mpz_t mpzval; int i,j;\n\
  mpz_init(mpzval);\n\
  M = new ZZ_mat<mpz_t>(3, 3);\n\
  for(i=0;i<=2;i++) {\n\
    for(j=0;j<=2;j++) {\n\
      mpz_set_ui(mpzval, (i+1)*(j+2));\n\
      zval = mpzval;\n\
      (*M)@<:@i@:>@@<:@j@:>@ = zval;\n\
    }\n\
  }\n\
  lll_reduction(*M);\
"`

FPLLL_NORMAL_HEADER=`printf "\
  #include <stdlib.h>\n\
  #include <fplll.h>\n\
  #include <gmp.h>\
"`

FPLLL_SPECIAL_HEADER=`printf "\
  #include <stdlib.h>\n\
  #include <fplll/fplll.h>\n\
  #include <gmp.h>\
"`

FPLLLSPECIALINCLUDE="no"
FPLLLISREALLIB="no"
FPLLLCXX11="no"
FPLLLMODERNAPI="no"

AC_MSG_CHECKING([for a suitable installation of fplll])
OLD_LIBS="$LIBS";

LIBS="-lfplll $LIBS";
CXXFLAGS="$AM_CXXFLAGS $STDCXX11 $USER_CXXFLAGS"
AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_NORMAL_HEADER]], [[$FPLLL_PROG]])],
               [
                  FPLLLSPECIALINCLUDE="no"
                  FPLLLISREALLIB="yes"
                  FPLLLCXX11="yes"
                  FPLLLMODERNAPI="yes"
		  AC_MSG_RESULT(yes)
               ],
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_NORMAL_HEADER]], [[$FPLLL_PROGV3]])],
                  [
                     FPLLLSPECIALINCLUDE="no"
                     FPLLLISREALLIB="yes"
                     FPLLLCXX11="yes"
                     FPLLLMODERNAPI="no"
		     AC_MSG_RESULT(yes)
		  ],
    [CXXFLAGS="$AM_CXXFLAGS $USER_CXXFLAGS"
     AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_NORMAL_HEADER]], [[$FPLLL_PROGV3]])],
                                     [
                                        FPLLLSPECIALINCLUDE="no"
                                        FPLLLISREALLIB="yes"
                                        FPLLLCXX11="no"
                                        FPLLLMODERNAPI="no"
                                        AC_MSG_RESULT(yes)
                                     ],
      [AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_NORMAL_HEADER]], [[$FPLLL_PROG]])],
                                       [
                                          FPLLLSPECIALINCLUDE="no"
                                          FPLLLISREALLIB="yes"
                                          FPLLLCXX11="no"
                                          FPLLLMODERNAPI="yes"
                                          AC_MSG_RESULT(yes)
                                       ],
        [AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_SPECIAL_HEADER]], [[$FPLLL_PROGV3]])],
                                         [
                                            FPLLLSPECIALINCLUDE="yes"
                                            FPLLLISREALLIB="yes"
                                            FPLLLCXX11="no"
                                            FPLLLMODERNAPI="no"
                                            AC_MSG_RESULT(yes)
                                         ],
          [LIBS="$OLD_LIBS"
	   AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_SPECIAL_HEADER]], [[$FPLLL_PROGV3]])],
                                           [
                                              FPLLLSPECIALINCLUDE="yes"
                                              FPLLLISREALLIB="no"
                                              FPLLLCXX11="no"
                                              FPLLLMODERNAPI="no"
                                              AC_MSG_RESULT(yes)
                                           ],
            [AC_LINK_IFELSE([AC_LANG_PROGRAM([[$FPLLL_NORMAL_HEADER]], [[$FPLLL_PROGV3]])],
                                             [
                                                FPLLLSPECIALINCLUDE="no"
                                                FPLLLISREALLIB="no"
                                                FPLLLCXX11="no"
                                                FPLLLMODERNAPI="no"
                                                AC_MSG_RESULT(yes)
                                             ],
                                             [AC_MSG_RESULT(no)]
            )]
          )]
        )]
      )]
    )]
  )]
)

if test "x${FPLLLSPECIALINCLUDE}y" = "xyesy"
then
  FPLLL_GOOD_HEADER="$FPLLL_SPECIAL_HEADER"
  AC_DEFINE([HAVE_SPECIAL_FPLLL_INCLUDE],[1],[Define for determining a special version of FPLLL])
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""fplll.h lies inside a subdirectory of the include directory (Debian-like), "
else
  FPLLL_GOOD_HEADER="$FPLLL_NORMAL_HEADER"
  AC_DEFINE([HAVE_SPECIAL_FPLLL_INCLUDE],[0],[Define for determining a special version of FPLLL])
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""fplll.h lies directly in the include directory, "
fi


if test "x${FPLLLISREALLIB}y" = "xyesy"
then
  LIBS="-lfplll $OLD_LIBS"
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""linkage with -lfplll is compatible, "
else
  LIBS="$OLD_LIBS"
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""linkage with -lfplll is not compatible, "
fi

if test "x${FPLLLCXX11}y" = "xyesy"
then
  AM_CXXFLAGS="$AM_CXXFLAGS $STDCXX11"
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""-std option is passed (""$STDCXX11""), "
else
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""no -std option is passed, "
fi
CXXFLAGS="$AM_CXXFLAGS $USER_CXXFLAGS"

if test "x${FPLLLMODERNAPI}y" = "xyesy"
then
  FPLLL_GOOD_PROG="$FPLLL_PROG"
  AC_DEFINE([HAVE_FPLLL_OLD_API],[0],[Define for determining what API to use with FPLLL])
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""using standard API."
else
  FPLLL_GOOD_PROG="$FPLLL_PROGV3"
  AC_DEFINE([HAVE_FPLLL_OLD_API],[1],[Define for determining what API to use with FPLLL])
  FPLLLVERSIONSTRING="$FPLLLVERSIONSTRING""using the FPLLL_V3_COMPAT API."
fi

AC_DEFINE_UNQUOTED([HAVE_FPLLL_VERSION_STRING],["$FPLLLVERSIONSTRING"],[Define a kind of a version string for FPLLL])
AC_LANG_POP([C++])

# Testing if -lstdc++ works both with the C compiler and the C++ compiler.
# We add it only if it works with both.
ADD_LSTDC="yes"
OLD_LIBS="$LIBS"; LIBS="$LIBS -lstdc++"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
                  [],
                  [ADD_LSTDC="no"])
AC_LANG_PUSH([C++])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
                  [],
                  [ADD_LSTDC="no"])
AC_LANG_POP([C++])
if test "x${ADD_LSTDC}y" = "xnoy"
then
  LIBS="$OLD_LIBS"
fi

AC_LANG_PUSH([C++])
# Checking that libfplll is found at runtime
AC_MSG_CHECKING([if libfplll is found at runtime])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #undef malloc
                                  #undef realloc
                                  $FPLLL_GOOD_HEADER]],
                               [[$FPLLL_GOOD_PROG]])
              ],
              [AC_MSG_RESULT(yes)],
              [AC_MSG_WARN([libfplll is found at compile time but not at run time. Checking /etc/ld.so.conf and running ldconfig could fix the problem.])])

AC_LANG_POP([C++])



#Check for -Wl,-export-dynamic etc.
CFLAGS="$AM_CFLAGS -fPIC -Werror $USER_CFLAGS"
AC_MSG_CHECKING([for -fPIC support])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
                  [
                     AC_MSG_RESULT(yes)
                     AM_CFLAGS="$AM_CFLAGS -fPIC"
		     CFLAGS="$AM_CFLAGS $USER_CFLAGS"
                  ],
                  [
                     AC_MSG_RESULT(no)
                     CFLAGS="$AM_CFLAGS $USER_CFLAGS"
                  ])

LDFLAGS="$AM_LDFLAGS -Wl,--export-dynamic $USER_LDFLAGS"
AC_MSG_CHECKING([for --export-dynamic support])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
                               [[exit(0);]]
                              )],
              [
                 AC_MSG_RESULT(yes)
                 AM_LDFLAGS="$AM_LDFLAGS -Wl,--export-dynamic"
              ],
              [
                 AC_MSG_RESULT(no)
                 LDFLAGS="$AM_LDFLAGS $USER_LDFLAGS"
              ])


LDFLAGS="$AM_LDFLAGS -Xlinker --allow-multiple-definition $USER_LDFLAGS"
AC_MSG_CHECKING([for -Xlinker --allow-multiple-definition support])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
                               [[exit(0);]]
                              )],
              [
                 AC_MSG_RESULT(yes)
                 AM_LDFLAGS="$AM_LDFLAGS -Xlinker --allow-multiple-definition"
              ],
              [
                 AC_MSG_RESULT(no)
                 LDFLAGS="$AM_LDFLAGS $USER_LDFLAGS"
              ])


AC_MSG_CHECKING([if compiler activates FTZ by default])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdint.h>]],
                               [[
                                 union {
                                   uint64_t i;
                                   double d;
                                 } xct, yct;
                                 volatile double x, y;
                                 xct.i = 0x1f20000000000000ull;
                                 x = xct.d;
                                 y = x * x;
                                 yct.d = y;
                                 if (yct.i == 0x0000000000000000ull) return 1;]]
                              )],
              [AC_MSG_RESULT(no)],
              [
                 AC_MSG_RESULT(yes)
                 AC_MSG_CHECKING([if compiler supports -fp-model precise flag])
                 CFLAGS="$AM_CFLAGS -fp-model precise $USER_CFLAGS"
                 AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
                                                [[exit(0);]]
                                               )],
                               [
                                  AC_MSG_RESULT(yes)
                                  AM_CFLAGS="$AM_CFLAGS -fp-model precise"
                               ],
                               [
                                  AC_MSG_RESULT(no)
                                  CFLAGS="$AM_CFLAGS $USER_CFLAGS"
                               ])
              ])

# Checks for linker script support:
gl_LD_VERSION_SCRIPT

# Checks for header files.
AC_FUNC_ALLOCA
AC_HEADER_STDC
AC_HEADER_SYS_WAIT

# If we do not have these ones, we consider that we cannot work properly.
# As for termios.h we might do something even if it is missing (e.g., build the
# library and provide the tool able to read files but not working
# interactively). The current position is: we do not.
AC_CHECK_HEADERS([inttypes.h stddef.h stdint.h stdlib.h string.h termios.h unistd.h limits.h wchar.h], [ ], AC_MSG_ERROR([Necessary header is missing]))
# If we do not have these ones, we can survive, protecting corresponding calls by a #ifdef HAVE_....
AC_CHECK_HEADERS([sys/ioctl.h sys/time.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_HEADER_STDBOOL
AC_TYPE_INT8_T
AC_TYPE_INT16_T
AC_TYPE_INT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT8_T
AC_TYPE_UINT16_T
AC_TYPE_UINT32_T
AC_TYPE_UINT64_T
AC_HEADER_TIME
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_TYPE_SSIZE_T
AC_C_VOLATILE
AC_C_INLINE
AC_CHECK_TYPES([ptrdiff_t])

# Checks for library functions.
AC_FUNC_FORK
AC_PROG_GCC_TRADITIONAL  # To support very old versions of gcc
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_FUNC_MALLOC
AC_FUNC_REALLOC

# If we do not have these functions we should survive because they shall be reimplemented in Sollya if necessaray if they are not provided by the system. In any case a test #ifdef HAVE_ shall protect any call to a function listed here.
AC_CHECK_FUNCS(gettimeofday memmove memset strchr strerror strrchr strtol dup2 strstr dladdr clock_gettime time sigaction sigaddset sigemptyset sigprocmask)

AC_MSG_CHECKING([if the system allows %n in a writable segment])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#define _BSD_SOURCE
				 #define _DEFAULT_SOURCE
                                 #include <stdio.h>
                                 #include <stdlib.h>]],
                               [[ char *str;
                                  int count;
                                  str = malloc(20*sizeof(char));
                                  sprintf(str, "%%n");
                                  printf(str, &count);
                                  free(str);
                                  return 0;]]
                              )],
	      [ AC_MSG_RESULT(yes) ],
              [
                AC_MSG_RESULT(no)
		AC_DEFINE([SYSTEM_DOES_NOT_ALLOW_COMPLETE_PRINTF],[1],[The system does not allow %n in malloced strings])
              ])


AC_MSG_CHECKING([if the Dl_info type is usable])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#define _GNU_SOURCE 1
                                 #define _DARWIN_C_SOURCE 1
                                 #include <dlfcn.h>
			         #include <stdlib.h>]],
                               [[ Dl_info myInfo;
                                  if (dladdr(main, &myInfo) != 0) return 0;
                                  exit(1);]]
                              )],
              [
                 AC_MSG_RESULT(yes)
                 AC_DEFINE([HAVE_DL_INFO_TYPE],[1],[Enabling Dl_info type usage])
              ],
              AC_MSG_RESULT(no))


AC_CHECK_TYPES([mp_bitcnt_t], [], [], [[#include <gmp.h>]])

CPPFLAGS="$USER_CPPFLAGS"
CFLAGS="$USER_CFLAGS"
LDFLAGS="$USER_LDFLAGS"


# The following two lines are supposed to fix bug #17197.
AM_CPPFLAGS="-I\${abs_top_srcdir} $AM_CPPFLAGS"

AC_SUBST(AM_CPPFLAGS)
AC_SUBST(AM_CFLAGS)
AC_SUBST(AM_LDFLAGS)
AC_CONFIG_FILES([Makefile doc/Makefile tests-tool/Makefile tests-lib/Makefile])
AC_OUTPUT