File: configure.ac

package info (click to toggle)
gnuplot 6.0.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 14,940 kB
  • sloc: ansic: 95,319; cpp: 7,590; makefile: 2,470; javascript: 2,328; sh: 1,531; lisp: 664; perl: 304; pascal: 191; tcl: 88; python: 46
file content (1514 lines) | stat: -rw-r--r-- 51,545 bytes parent folder | download | duplicates (2)
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
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
dnl Process this file with autoconf to produce a configure script.
dnl configure.in for gnuplot on Unix.
dnl
dnl NB: Change version/patchlevel immediately below
dnl     and also in PATCHLEVEL and src/version.c
dnl

AC_INIT(gnuplot, 6.0.2)

AC_CONFIG_SRCDIR(src/graphics.c)
AC_PREREQ([2.69])
AC_CONFIG_HEADERS(config.h:config.hin)

dnl The line below is for use during development
dnl AC_DEFINE(DEVELOPMENT_VERSION,1,[Provide timestamp for gnuplot develoment])
dnl The line below is for packaging a release version
AM_CONDITIONAL([DEVELOPMENT_VERSION], false)

AM_INIT_AUTOMAKE([1.10 subdir-objects])

AM_MAINTAINER_MODE

VERSION_MAJOR="6.0"
PATCHLEVEL="`cat $srcdir/PATCHLEVEL`"
AC_DEFINE_UNQUOTED(VERSION_MAJOR,["$VERSION_MAJOR"],[The main version number])
AC_DEFINE_UNQUOTED(PATCHLEVEL,["$PATCHLEVEL"],[The patch level, a.k.a. micro version number])

dnl configure.in body

dnl Compiler characteristics
dnl Check for the const and inline keywords and ANSI style stringification
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AC_PROG_CPP
AC_PROG_OBJC
AC_C_CONST
AC_C_INLINE
AC_C_STRINGIZE
AC_PROG_LN_S

if test "${build}" != "${host}"
then
  CC=${CC-${host_alias-gcc}}
  CFLAGS=${CFLAGS-"-g -O2"}
  CXX=${CXX-${host_alias-c++}}
  CXXFLAGS=${CXXFLAGS-"-g -O2"}
  CC_FOR_BUILD=${CC_FOR_BUILD-gcc}
else
  # The cross-compilation patch originally had CC_FOR_BUILD = "\$(CC)"
  # but that causes a recursive definition in docs/Makefile. EAM Dec 2009.
  CC_FOR_BUILD="${CC}"
  AC_PROG_CC

  # We must set the default linker to the linker used by gcc for the correct
  # operation of libtool.  If LD is not defined and we are using gcc, try to
  # set the LD default to the ld used by gcc.
  if test -z "$LD"
  then
    if test "$GCC" = yes
    then
      case $build in
      *-*-mingw*)
        gcc_prog_ld=`$CC -print-prog-name=ld 2>&1 | tr -d '\015'` ;;
      *)
        gcc_prog_ld=`$CC -print-prog-name=ld 2>&1` ;;
      esac
      case $gcc_prog_ld in
      # Accept absolute paths.
      [[\\/]* | [A-Za-z]:[\\/]*)]
        LD="$gcc_prog_ld" ;;
      esac
    fi
  fi

  CXX=${CXX-"c++"}
  CFLAGS=${CFLAGS-"-g -O2"}
  CXXFLAGS=${CXXFLAGS-"-g -O2"}
fi
AM_PROG_CC_C_O
AC_SUBST(CC_FOR_BUILD)

dnl large file support
AC_CHECK_TYPES([off_t])
AC_FUNC_FSEEKO
AC_SYS_LARGEFILE

dnl timezone support
AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[
#include <sys/types.h>
#include <time.h>])

dnl explicit call to PKG_PROG_PKG_CONFIG because the first call to
dnl PKG_CHECK_MODULES{,_NOFAIL} may not happen
PKG_PROG_PKG_CONFIG

AC_ARG_WITH(libcerf,dnl
[  --without-libcerf       build without special functions from libcerf (default enabled)],,
  [test -z "${with_libcerf}" && with_libcerf=yes])

if test "${with_libcerf}" = yes ; then
  dnl The libcerf library contains a set of complex-valued special functions
  dnl related to the error function (cerf, erfi, Dawson's integral, Voigt profile).
  dnl If libcerf is installed then we can use them.
  PKG_CHECK_MODULES_NOFAIL([LIBCERF], [libcerf],
      [
      CPPFLAGS="$CPPFLAGS $LIBCERF_CFLAGS"
      LDFLAGS="$LDFLAGS $LIBCERF_LIBS"
      ],
  )
  AC_SEARCH_LIBS([cdawson], [cerf],
      [AC_DEFINE([HAVE_LIBCERF], 1, [define if you have libcerf])
      have_libcerf=yes]
  )
fi

AC_ARG_WITH(amos,dnl
[  --with-amos[=DIR]         location of libamos or libopenspecfun (complex functions)],,
  with_amos=yes)

if test -d "$with_amos"; then
  LIBAMOS_LDFLAGS=-L$with_amos
fi

if test "${with_amos}" != no ; then
  _ldflags="$LDFLAGS"
  LDFLAGS="$LDFLAGS $LIBAMOS_LDFLAGS"
  AC_MSG_CHECKING( for amos libraries using LDFLAGS: $LDFLAGS )

  dnl The Amos routines (D. E. Amos, Sandia National Laboratories) calculate
  dnl Bessel and related functions with complex argument and nonnegative order.
  dnl These routines exist in various library packages including libopenspecfun.
  AC_SEARCH_LIBS([zairy_], [amos openspecfun],
      [AC_DEFINE([HAVE_AMOS], 1, [define if you have a library of Amos special functions])
      have_amoslibrary=yes]
  )
  dnl The Amos routine cexint (Complex exponential integral) is not in the general
  dnl collection of Bessel functions so it may or may not be present in the same
  dnl library as the others.
  AC_SEARCH_LIBS([cexint_], [amos openspecfun],
      [AC_DEFINE([HAVE_CEXINT], 1, [define if you have Amos function cexint])
      have_cexint=yes && LIBS="$LIBS -L/home/local/lib64"]
  )
fi

dnl Various programs
dnl X/Emacs for building .texi version of docs
test x"$EMACS" = xt && EMACS=
AC_CHECK_PROGS(EMACS, emacs xemacs, no)

dnl Allow manual specification of tex
AC_ARG_WITH(latex,[  --without-latex         disable installation of latex support files],[],[with_latex="yes"])
if test "$with_latex" = yes; then
  AC_CHECK_PROGS(PLAINTEX, tex, no)
  AC_CHECK_PROGS(LATEX, latex latex2e, no)
  AC_CHECK_PROGS(PDFLATEX, pdflatex, no)
  test "$PLAINTEX" = "no" -o "$LATEX" = no -o "$PDFLATEX" = "no" && with_latex="no"
else
    PLAINTEX="no"
    LATEX="no"
    PDFLATEX="no"
fi
AM_CONDITIONAL(HAVE_LATEX, test "$with_latex" != no)
AC_CHECK_PROGS(DVIPS, dvips, no)

AC_ARG_WITH(texdir,dnl
  [--with-texdir=DIR       where to install latex style files (default: ask kpsewhich)],
  TEXDIR="$withval",
  TEXDIR="no")
dnl Allow manual specification of kpsewhich
AC_CHECK_PROGS(KPSEWHICH, kpsewhich, no)
AC_CHECK_PROGS(TEXHASH, texhash, true)

dnl we only care about texdir if latex is enabled
if test "$with_latex" = yes; then
  test "$KPSEWHICH" = "no" -a "$TEXDIR" = "no" && AC_MSG_ERROR(dnl
    [texdir is not given and there is no kpsewhich, please tell where to install])
  dnl texdir has priority
  if test "$TEXDIR" = "no"; then
    TEXDIR=`$KPSEWHICH --expand-var '$TEXMFLOCAL'`
    if test "x$TEXDIR" = "x" -o "$TEXDIR" = "\$TEXMFLOCAL"; then
      if test "x$prefix" != "xNONE"; then
        TEXDIR=${prefix}/share/texmf
      else
        TEXDIR=${ac_default_prefix}/share/texmf
      fi
    fi
    TEXDIR=${TEXDIR}/tex/latex/gnuplot
  fi
fi

dnl X Window System files.
AC_SUBST(LIBRARIES_FOR_X)
AC_PATH_XTRA

dnl Needed for LynxOS until AC_PATH_XTRA is fixed
if test "$ac_cv_func_gethostbyname" = no; then
  if test "$ac_cv_lib_nsl_gethostbyname" = no; then
    AC_CHECK_LIB(bsd, gethostbyname, X_EXTRA_LIBS="$X_EXTRA_LIBS -lbsd")
  fi
fi

if test "$no_x" != yes; then
  CPPFLAGS="$CPPFLAGS $X_CFLAGS"
  LIBRARIES_FOR_X="$X_LIBS -lX11 $X_EXTRA_LIBS"
  AC_DEFINE(X11,1,[ Define if you are using the X11 window system. ])
  AC_ARG_WITH(x-dcop,dnl
  [--with-x-dcop           gnuplot_x11 can use KDE3/DCOP for space-raises-console],
  AC_DEFINE(USE_KDE3_DCOP,1,[ Define if gnuplot_x11 can use KDE3 DCOP to raise konsole]))
fi
AM_CONDITIONAL(BUILD_GNUPLOT_X11, test "$no_x" != yes)

dnl Operating systems.
dnl Check for MSDOS and djgpp, Apple MacOsX, BeOS
GP_MSDOS
GP_APPLE
GP_BEOS
GP_ALPHA

dnl _instead_ of -lm ...
AC_CHECK_FUNC(sin,,[AC_CHECK_LIB(m,sin)])

dnl Header files. ANSI first
dnl AC_HEADER_STDC
AC_CHECK_HEADERS(dirent.h errno.h float.h langinfo.h limits.h locale.h math.h \
  stdlib.h string.h time.h sys/time.h sys/types.h \
  sys/bsdtypes.h sys/ioctl.h sys/param.h sys/select.h sys/socket.h \
  sys/stat.h sys/systeminfo.h sys/timeb.h sys/utsname.h \
  libc.h malloc.h poll.h sgtty.h termios.h values.h dirent.h \
  inttypes.h \
  dlfcn.h dl.h
)

AC_HEADER_STDBOOL

if test "$ac_cv_header_sys_stat_h" = yes; then
  AC_HEADER_STAT
fi

AC_HEADER_SYS_WAIT

dnl Check for external functions plugin infrastructure
AC_ARG_ENABLE(plugins,dnl
[  --disable-plugins       disable support for importing external functions],,)

if test "$enable_plugins" != no; then
  if test "$ac_cv_header_dl_h" = yes; then
    AC_SEARCH_LIBS(shl_load, dld,
      [AC_DEFINE(HAVE_EXTERNAL_FUNCTIONS,1,[ Define if external function plugins are to be supported. ])
       have_external_functions=yes
      ])
  fi
  if test "$ac_cv_header_dlfcn_h" = yes; then
    AC_SEARCH_LIBS(dlopen, dl,
      [AC_DEFINE(HAVE_EXTERNAL_FUNCTIONS,1,[ Define if external function plugins are to be supported. ])
       have_external_functions=yes
      ])
  fi
fi
AM_CONDITIONAL(BUILD_PLUGIN, test "$have_external_functions" = yes)

dnl check if unistd actually declares anything.
AC_MSG_CHECKING(for unistd.h)
AC_EGREP_HEADER(execv, unistd.h,
  [AC_DEFINE(HAVE_UNISTD_H) AC_MSG_RESULT(yes)],
   AC_MSG_RESULT(no))

dnl check if errno.h header declares errno
AC_MSG_CHECKING(if errno variable is declared)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif]], [[errno=0]])],[AC_MSG_RESULT(yes)],[AC_DEFINE(EXTERN_ERRNO,1,[ Define if <errno.h> declares errno. ])
   AC_MSG_RESULT(no)])


dnl Types.
AC_TYPE_SIZE_T
AC_MSG_CHECKING(for time_t in time.h)
AC_EGREP_HEADER(time_t,time.h,
  [AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_TIME_T_IN_TIME_H,1,
             [ Define if time_t is declared in time.h. ])])
 

dnl Functions. Standard first, then others

dnl ANSI/ISO and their predecessors
dnl sunos 4 has on_exit() in place of atexit()
dnl gamma is called lgamma linux
dnl we prefer lgamma over gamma, see specfun.c
dnl math lib is already available, see operating systems part
AC_CHECK_FUNCS(atexit memcpy memmove memset \
  on_exit bcopy bzero \
  setvbuf strerror strchr strrchr strstr \
  index rindex \
  erf erfc gamma lgamma tgamma \
  getcwd poll pclose popen fdopen select sleep stpcpy \
  strcspn strdup strndup strnlen strcasecmp stricmp strncasecmp strnicmp \
  sysinfo tcgetattr vfprintf doprnt uname usleep \
  cbrt jn
)

dnl HBB 20030624: see if signgam is declared by math.h
AC_CHECK_DECLS([signgam],,,
[#if HAVE_MATH_H
#include <math.h>
#endif
])

dnl check for C99 complex types
dnl and minimal set of complex math functions
AC_CHECK_HEADERS(complex.h)
AC_CHECK_FUNCS(csqrt cexp cabs clog)
dnl check for C99 floating point exception handling
AC_CHECK_HEADERS(fenv.h)

dnl check, if we have sigsetjmp and siglongjmp.
dnl a trivial AC_CHECK_FUNCS(sigsetjmp) won't do
dnl because sigsetjmp() might be a macro declared
dnl in <setjmp.h>. (joze)
AC_MSG_CHECKING(for sigsetjmp)
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <setjmp.h>]], [[jmp_buf env; sigsetjmp(env, 1);]])],[AC_MSG_RESULT(yes)
   AC_DEFINE(HAVE_SIGSETJMP,1,
             [ Define if we have sigsetjmp(). ])],[AC_MSG_RESULT(no)])

if test "$ac_cv_func_pclose" = yes -a "$ac_cv_func_popen" = yes ; then
  AC_DEFINE(PIPES,1,[ Define if you do have the popen and pclose functions. ])
fi

AC_MSG_CHECKING(if malloc(0) returns 0)
AC_RUN_IFELSE([AC_LANG_PROGRAM([[#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
]],
[[if(malloc(0)==0) return 1;]])],
[malloc_zero_returns_zero=no],
[malloc_zero_returns_zero=yes],
[malloc_zero_returns_zero=yes])
AC_MSG_RESULT([$malloc_zero_returns_zero])
AS_IF([test x$malloc_zero_returns_zero = xyes],
      [AC_DEFINE([MALLOC_ZERO_RETURNS_ZERO],[1],[Define to 1 if malloc(0)==0])])

dnl Argument types of select()
AC_FUNC_SELECT_ARGTYPES

dnl On SVR3.
dnl FIXME AC_DEFINE(CRIPPLED_SELECT)

dnl .gih help file location
eval gp_datadir=$datadir
if test "$gp_datadir" = NONE/share; then
  datadir="/usr/local/share"
fi
pkgdatadir="$datadir/$PACKAGE"
AC_ARG_WITH(gihdir,dnl
[  --with-gihdir=DIR       location of .gih help text file
                          (default PREFIX/share/PACKAGE/VERSION)],
  GIHDIR="$withval",
  GIHDIR="$pkgdatadir/$VERSION_MAJOR")

dnl Use builtin readline or GNU readline or NetBSD editline
AC_ARG_WITH(readline,dnl
[  --with-readline=builtin  use the built-in readline
  --with-readline=gnu      use the GNU readline library (default if present)
  --with-readline=bsd      use the NetBSD editline library
  --with-readline=DIR      specify the location of readline/editline
  --without-readline       same as --with-readline=builtin], ,
  test -z "$with_readline" && with_readline=gnu)

AS_IF([test "x${with_readline}" = "xno"], with_readline="builtin", )

dnl Gnuplot history
AC_ARG_ENABLE(history-file,dnl
[  --disable-history-file  do not use history file],,
  test -z "$enable_history_file" && enable_history_file=yes)

dnl GNU readline and the required terminal library
if test "$with_readline" != no; then
  _libs="$LIBS"
  if test "$with_readline" != builtin; then

    dnl check for terminal library
    dnl this is a very cool solution from octave's configure.in
    gp_tcap=""
    for termlib in ncurses curses termcap terminfo termlib; do
      AC_CHECK_LIB(${termlib}, tputs, [gp_tcap="$gp_tcap -l$termlib"])
      case "$gp_tcap" in
        *-l${termlib}*)
          break
        ;;
      esac
    done

    dnl explicit path to readline/editline
    if test "$with_readline" != gnu -a "$with_readline" != bsd; then
      if test -d $with_readline/include; then
        CPPFLAGS="$CPPFLAGS -I$with_readline/include"
      fi
      if test -d $with_readline/lib; then
        LDFLAGS="$LDFLAGS -L$with_readline/lib"
      fi
      dnl Could be either libedit or readline!
      if test ! -d $with_readline/include/readline; then
        if test -d $with_readline/include/editline; then
          AC_MSG_WARN([$with_readline contains libedit, not readline!])
          with_readline=bsd
        else
          AC_MSG_ERROR([No readline found in $with_readline])
        fi
      fi
    fi

    if test "$with_readline" = bsd; then

      AC_CHECK_LIB(edit, readline,
        [TERMLIBS="-ledit $TERMLIBS"],
	 [AC_MSG_WARN([Could not find BSD editline library ])
	  with_readline=builtin],)

      if test "$ac_cv_lib_edit_readline" = yes; then
        AC_DEFINE(HAVE_LIBEDITLINE,1,
                [ Define if you are using the BSD editline library. ])
        AC_CHECK_HEADERS(editline/readline.h,,
          AC_MSG_WARN([found BSD editline library but not readline.h please add path to readline.h to CPPFLAGS in Makefile]))

        if test "$enable_history_file" = yes; then
            AC_DEFINE(GNUPLOT_HISTORY,1,
                      [ Define if you want to use a gnuplot history file. ])
        fi
      fi

    else # !bsd

    AC_CHECK_LIB(readline, remove_history,
      [TERMLIBS="-lreadline $gp_tcap $TERMLIBS"],,[${gp_tcap}])
    if test "$ac_cv_lib_readline_remove_history" = no; then
      dnl OSX keeps history functions in a separate library
      AC_CHECK_LIB(history, remove_history,
        [TERMLIBS="-lreadline -lhistory $gp_tcap $TERMLIBS"],
        [ AC_MSG_WARN([GNU readline not found - falling back to builtin readline])
          with_readline=builtin ]
        ,[${gp_tcap}])
    fi

    dnl Work around some functions missing from the OSX readline library.
    dnl Would it be better to simply switch to with_readline=bsd in this case?
    AC_SEARCH_LIBS(rl_ding, readline, ,
	AC_DEFINE(MISSING_RL_DING,1,[ Define if your libreadline has no rl_ding]),
        [${TERMLIBS}])
    AC_SEARCH_LIBS(rl_forced_update_display, readline, ,
	AC_DEFINE(MISSING_RL_FORCED_UPDATE_DISPLAY,1,[ Define if your libreadline has no rl_force_update_display]),
        [${TERMLIBS}])
    AC_SEARCH_LIBS(rl_reset_after_signal, readline,
	AC_DEFINE(HAVE_READLINE_RESET,1,[ Define if your libreadline has rl_reset_after_signal]),
	,
        [${TERMLIBS}])
    AC_SEARCH_LIBS(_rl_signal_handler, readline,
	AC_DEFINE(HAVE_READLINE_SIGNAL_HANDLER,1,[ Define if your libreadline has _rl_signal_handler]),
	,
        [${TERMLIBS}])
    AC_SEARCH_LIBS(rl_pending_signal, readline,
	AC_DEFINE(HAVE_READLINE_PENDING_SIGNAL,1,[ Define if your libreadline has rl_pending_signal]),
	,
        [${TERMLIBS}])
    # Warning: rl_complete_with_tilde_expansion is an int, not a function.
    # I.e., it is not callable.  AC_CHECK_LIB seems to work anyhow, but...
    AC_SEARCH_LIBS(rl_complete_with_tilde_expansion, readline, , 
	AC_DEFINE(MISSING_RL_TILDE_EXPANSION,1,[ Define if your libreadline has no rl_complete_with_tilde_expansion]),
        [${TERMLIBS}])

    if [test "$ac_cv_lib_readline_remove_history" != no || test "$ac_cv_lib_history_remove_history" != no]; then
      if test "$with_readline" = bsd; then
          AC_DEFINE(HAVE_LIBEDITLINE,1,
                [ Define if you are using the BSD editline library. ])
      else
          AC_DEFINE(HAVE_LIBREADLINE,1,
                [ Define if you are using the GNU readline library. ])
      fi
      AC_CHECK_HEADERS(readline/readline.h,,
        AC_MSG_WARN([found GNU readline library but not readline.h
please add path to readline.h to CPPFLAGS in Makefile]))
      AC_CHECK_HEADERS(readline/history.h,,
        AC_MSG_WARN([found GNU readline library but not history.h
please add path to history.h to CPPFLAGS in Makefile]))

      if test "$enable_history_file" = yes; then
          AC_DEFINE(GNUPLOT_HISTORY,1,
                    [ Define if you want to use a gnuplot history file. ])
      fi

    fi # ! ac_cv_lib_readline_readline = no

   fi # ! with_readline = bsd

  fi # ! with_readline != builtin 

  if test "$with_readline" = builtin; then
    AC_CHECK_FUNCS(wcwidth)
    AC_CHECK_HEADERS(wchar.h,,
        AC_MSG_WARN([please add path to wchar.h to CPPFLAGS in Makefile]))
    AC_DEFINE(READLINE,1,
              [ Define if you want to use the included readline function. ])
    if test "$enable_history_file" = yes; then
       AC_DEFINE(GNUPLOT_HISTORY,1,
                [ Define if you want to use a gnuplot history file. ])
    fi
  fi

  LIBS="$_libs"
fi
dnl end readline

dnl the "qsort" provided by macOS is not stable (items that evaluate equal are not
dnl guaranteed to retain their original ordering).
dnl This option allows you to replace it with mergesort, if found,
dnl or add code in gnuplot to make the sort stable with respect to pm3d depthorder
AC_CHECK_FUNCS(mergesort, have_stable_sort=yes)
AC_CHECK_FUNCS(gnu_get_libc_version, have_stable_sort=yes)
AC_ARG_ENABLE(stable-sort, dnl
[  --enable-stable-sort    guarantee that pm3d depth-sorting retains object order],
  [AC_DEFINE(WITH_STABLE_SORT,1,
             [ Define if qsort on your O/S is unstable and that bothers you. ])
  ]
  ,)

dnl check presence of z library
dnl TODO: path to zlib includes; -lz -lm specified multiple times
dnl       we don't do anything about missing png/gd includes either
AC_CHECK_LIB(z,deflate,
  [TERMLIBS="$TERMLIBS -lz"
   AC_DEFINE(HAVE_LIBZ,1,[ Define if you have zlib. ])
   AC_CHECK_HEADER(zlib.h,,
     [AC_MSG_WARN([found z library but not zlib.h
please add path to zlib.h to CPPFLAGS in Makefile])])],
  AC_MSG_WARN([zlib is required - see http://www.gzip.org/zlib/]))

dnl check presence of gd library
dnl we don't check for libfreetype and libjpeg locations - if gd requires
dnl them, the gdlib-config script or the gdlibc.pc contains all the required information
AC_ARG_WITH(gd,dnl
[  --with-gd[=DIR]           (DIR is location of include/gd.h and lib/libgd.so)],,
  with_gd=yes)

if test -d "$with_gd"; then
  libgd_LDFLAGS=-L$with_gd/lib
  libgd_CFLAGS=-I$with_gd/include
  libgd_LIBS=-lgd
  AC_MSG_WARN(([Looking for $with_gd/include/gd.h and $with_gd/lib/libgd.so]))

elif test "$with_gd" != no; then
  PKG_CHECK_MODULES_NOFAIL(libgd, [gdlib])
  # If pkg-config did return libgd configuration then
  # libgd_{CFLAGS,LDFLAGS,LIBS} is set
fi

if test "$with_gd" != no; then
  # Verify that libgd works, but backup the previous compilation variables to
  # be able to revert in the case that libgd is not functional
  _cppflags="$CPPFLAGS"
  _ldflags="$LDFLAGS"
  _libs="$LIBS"
  CPPFLAGS="$CPPFLAGS $libgd_CFLAGS"
  LDFLAGS="$LDFLAGS $libgd_LDFLAGS"
  LIBS="$LIBS $libgd_LIBS"

  AC_CHECK_LIB(gd,gdImageCreateTrueColor,
    [dnl found gd library
     AC_DEFINE(HAVE_LIBGD,1,[ Define if you have gd library. ])
     AC_CHECK_HEADERS(gd.h,,
       AC_MSG_WARN([please add path to gd.h to CPPFLAGS in Makefile]))

     dnl gif support in libgd
     AC_CHECK_LIB(gd,gdImageGif,
       [AC_DEFINE(HAVE_GD_GIF,1,[ Define if libgd supports gif. ])])
     AC_CHECK_LIB(gd,gdImageGifAnimBegin,
       [AC_DEFINE(GIF_ANIMATION,1,[ Define if libgd supports animated gifs. ])])

     dnl jpeg support in libgd
     AC_CHECK_LIB(gd,gdImageJpeg,
       [AC_DEFINE(HAVE_GD_JPEG,1,[ Define if libgd supports jpeg. ])])

     dnl freetype support in libgd
     AC_CHECK_LIB(gd,gdImageStringFT,
       AC_DEFINE(HAVE_GD_TTF,1,
           [ Define if libgd supports TrueType fonts through libfreetype. ]))

     dnl png support in libgd
     AC_CHECK_LIB(gd,gdImagePng,
       [AC_DEFINE(HAVE_GD_PNG,1,[ Define if libgd supports png. ])])

    ],[dnl gd library not found
       AC_MSG_WARN([libgd not found or too old, version >= 2.0 is required])
       with_gd=no
    ])

  dnl piece it all together
  if test "$with_gd" = no; then
    CPPFLAGS="$_cppflags"
    LDFLAGS="$_ldflags"
    LIBS="$_libs"
  else
    LIBS="$_libs"
    TERMLIBS="$TERMLIBS -lgd $libgd_LIBS"
  fi

fi
dnl end gd

dnl The iconv library can be used to switch character encodings.
dnl So far this is only used by gd.trm and emf.trm.
AC_SEARCH_LIBS([iconv_open], [iconv],
  [AC_CHECK_HEADER([iconv.h],
    [AC_DEFINE([HAVE_ICONV], 1, [define if you have libiconv and iconv.h])]
  )]
)

dnl check presence of lua/TikZ support
AC_ARG_WITH(lua,dnl
[  --without-lua           disable lua/TikZ terminal (default enabled)],,
  [test -z "${with_lua}" && with_lua=yes])

dnl Some distributions allow for parallel installation of different
dnl lua versions.  We test for that in order of pereference.
if test "${with_lua}" = yes ; then
  LUA=lua
  PKG_CHECK_MODULES([LUA], [lua], LUAFOUND=yes,
    [PKG_CHECK_MODULES([LUA], [lua5.3], LUA=lua5.3, 
      [PKG_CHECK_MODULES([LUA], [lua5.2], LUA=lua5.2, 
        [PKG_CHECK_MODULES([LUA], [lua5.1], LUA=lua5.1, 
          [LUAFOUND=no])])])])
  if test $pkg_failed != no; then
    AC_MSG_WARN([Could not find support for lua using pkg-config.])
    with_lua=no
  fi

  if test "$with_lua" != no; then
    TERMLIBS="$TERMLIBS $LUA_LIBS"
    CPPFLAGS="$CPPFLAGS $LUA_CFLAGS"
  else
    dnl if pkg-config didn't work, we migh still find it manually
    AC_SEARCH_LIBS(luaL_openlibs, lua lua5.3 lua5.2 lua5.1,
       with_lua=yes, with_lua=no)
  fi
  if test "$with_lua" = yes; then
     AC_DEFINE(HAVE_LUA,1, [ Define if you want the lua/TikZ terminal. ])
     AC_CHECK_HEADERS(lua.h,,
       AC_MSG_WARN([please add path to lua.h to CPPFLAGS in Makefile]))
  fi
  AC_SUBST(LUA)
fi
AM_CONDITIONAL(BUILD_LUA, test "${with_lua}" = yes)
dnl end lua

dnl check presence of caca library
AC_ARG_WITH(caca,dnl
[  --with-caca[=DIR]         where to find the caca library],,
  with_caca=no)

if test "$with_caca" != no; then
  if test -d "$with_caca"; then
    dnl path to libcaca was specified manually
    caca_CPPFLAGS="-I$with_caca/include"
    caca_LDFLAGS="-L$with_caca/lib -Wl,-rpath -Wl,$with_caca/lib"
    caca_LIBS="-lcaca"
    with_caca=yes
  else
    dnl try to use pkg-config first
    PKG_CHECK_MODULES(caca, [caca], [with_caca=yes], [with_caca=no])
    if test $pkg_failed != no; then
      dnl try to locate libcaca using its config tool
      AC_PATH_PROG([CACA_CONFIG], [caca-config])
      if test -n "$CACA_CONFIG"; then
        caca_CPPFLAGS=`$CACA_CONFIG --cflags`
        caca_LDFLAGS=`$CACA_CONFIG --ldflags`
        caca_LIBS=`$CACA_CONFIG --libs`
        with_caca=yes
      else
        dnl libcaca was not found
        AC_MSG_WARN([libcaca not found or too old, version >= 0.99.beta15 is required])
        with_caca=no
      fi
    fi
  fi

  dnl test usability
  _cppflags="$CPPFLAGS"
  _ldflags="$LDFLAGS"
  CPPFLAGS="$caca_CPPFLAGS $CPPFLAGS"
  LDFLAGS="$caca_LDFLAGS $LDFLAGS"
  AC_CHECK_LIB(caca,caca_get_version,
    [dnl found caca library, test for version >= 0.99.beta15 (libcucul merged back)
     AC_CHECK_LIB([caca],[caca_export_canvas_to_memory],,
       [AC_DEFINE(USE_CACA_EXPORT_MEMORY,1,[ Define if your libcaca does not have caca_export_canvas_to_memory but the old caca_export_memory])],[])
     AC_CHECK_DECL([CACA_DEPRECATED],
       [AC_DEFINE(HAVE_LIBCACA,1,[ Define if you have the caca library. ])],
       [AC_MSG_WARN([libcaca header not found or too old, version >= 0.99.beta15 is required])
        with_caca=no],
       [[#include <caca.h>]])
    ],
    [dnl caca library not found
       AC_MSG_WARN([libcaca not found or too old, version >= 0.99.beta15 is required])
       with_caca=no
    ])

  dnl piece it all together
  if test "$with_caca" = no; then
    CPPFLAGS="$_cppflags"
    LDFLAGS="$_ldflags"
  else
    TERMLIBS="$TERMLIBS $caca_LIBS"
  fi
fi
dnl end caca

dnl Process rest of with and enable options

dnl without-extra-coordinate may leave a hole in "struct coordinate"
AC_ARG_WITH(extra-coordinate,dnl
[  --without-extra-coordinate    leave possible hole in struct coordinate],,)
if test "$with_extra_coordinate" != no; then
     AC_DEFINE(WITH_EXTRA_COORDINATE,1,
               [ Define to make use of otherwise empty space in struct coordinate ])
fi

dnl EXPERIMENTAL support for concave hulls via Delaunay triangulation and chi-shapes
AC_ARG_ENABLE(chi-shapes,dnl
[  --disable-chi-shapes    no support for Delaunay triangulation or chi-shapes],,)
if test "$enable_chi_shapes" != no; then
    AC_DEFINE(WITH_CHI_SHAPES,1,
              [ Define to support Delaunay triangulation and chi-shapes ])
fi

dnl enable multi-byte font support in x11 terminal
AC_ARG_ENABLE(x11-mbfonts,dnl
[  --disable-x11-mbfonts   disable multi-byte font support for x11 ],,
  test -z "$enable_x11_mbfonts" && enable_x11_mbfonts=yes)
  if test "$enable_x11_mbfonts" = yes; then

    _ldflags="$LDFLAGS"
    LDFLAGS="$LDFLAGS $LIBRARIES_FOR_X"

    AC_MSG_CHECKING([for multi-byte support in x11])
    AC_CHECK_LIB(X11, XmbDrawString,
      AC_DEFINE(USE_X11_MULTIBYTE,1,[ Define to enable multi-byte font support for x11 ]),
      enable_x11_mbfonts=no )
    
    LDFLAGS="$_ldflags"
  
  fi

dnl x11_external
AC_ARG_ENABLE(x11_external,dnl
[  --disable-x11-external  disable drawing to windows belonging to external apps],,
  test -z "$enable_x11_external" && enable_x11_external=yes)

if test "$enable_x11_external" = yes; then
  AC_DEFINE(EXTERNAL_X11_WINDOW,1,[ Define if you want to supply pre-existing X11 windows. ])
fi

dnl disable the "space raises console" behaviour
AC_ARG_ENABLE(raise-console,dnl
[  --disable-raise-console spacebar in plot window does not raise console],,
  test -z "$enable_raise_console" && enable_raise_console=yes)
  if test "$enable_raise_console" != yes; then
      AC_DEFINE(DISABLE_SPACE_RAISES_CONSOLE,1,
                [ Define to treat spacebar like any other keystroke. ])
  fi


dnl  wxWidgets terminal

dnl wxWidgets terminal needs C++
dnl These tests cannot be called conditionally.
dnl These tests are non-fatal on autoconf 2.58 and 2.59,
dnl but it may change in future versions, so we redefine AC_MSG_ERROR.
dnl Even if there is no C++ compiler on the system,
dnl autoconf will set CXX as g++ : this must be reverted.

m4_pushdef([AC_MSG_ERROR],[cxxerror=yes])
AC_PROG_CXX
m4_popdef([AC_MSG_ERROR])

if test "x${cxxerror}" != "xyes"; then
  AC_LANG_PUSH([C++])
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <iostream>]],
	[[const char hw[] = "Hello, World\n"; std::cout << hw;]])],
	[cxxerror=no
	AC_PROG_CXXCPP],
	[cxxerror=yes
	CXX=$CC])
  AC_LANG_POP([C++])
fi

AC_ARG_ENABLE(wxwidgets,dnl
[  --disable-wxwidgets     wxWidgets terminal (default enabled)],,
  [test -z "${enable_wxwidgets}" && enable_wxwidgets=yes])

if test "${enable_wxwidgets}" = yes ; then
  dnl variable used to determine if all checks pass
  enable_wxwidgets_ok=yes

  dnl Check for the C++ compiler
  if test "x${cxxerror}" = "xyes"; then
    AC_MSG_WARN([No C++ compiler found. The wxWidgets terminal will not be compiled.])
      enable_wxwidgets_ok=no
  fi

  dnl The user can specify another path for wx-config
  WXWIDGETS_PATH="${PATH}"
  AC_ARG_WITH(wx,dnl
  [--with-wx=DIR           Where to find wx-config, the wxWidgets configuration program
    (default search in $PATH)],
    [ if test "${with_wx}" != "no" ; then
	WXWIDGETS_PATH="${with_wx}:${PATH}"
     fi ])

  dnl Look for wx-config in the path
  AC_PATH_PROG(WX_CONFIG, wx-config, no, ${WXWIDGETS_PATH})
  if test "${WX_CONFIG}" = "no"; then
    AC_MSG_WARN([wxWidgets can't be found. You can try --with-wx=DIR to give the right path to wx-config. The wxWidgets terminal will not be compiled.])
    enable_wxwidgets_ok=no
  else

    dnl Ckeck for wxWidgets version
    WXWIDGETS_VERSION=`${WX_CONFIG} --release`
    if expr 2.6 \> ${WXWIDGETS_VERSION} >/dev/null; then
      AC_MSG_WARN([Your development package for wxWidgets is too old, you need at least version 2.6. The wxWidgets terminal will not be compiled.])
      enable_wxwidgets_ok=no
    fi
    if expr ${WXWIDGETS_VERSION} \> 2.8 >/dev/null; then
      AC_DEFINE(WX_NEEDS_XINITTHREADS, 1, [wxWidgets >= 2.9 wants calling program to invoke XInit()])
    fi

    dnl Make sure we're using more than the 'base' wxWidgets. Those 
    if expr `${WX_CONFIG} --basename` : '.*base' >/dev/null; then
      AC_MSG_WARN([You only have the 'base' flavor of wxWidgets. A full wxWidgets library is required. On Debian/Ubuntu, please make sure that you have a 'libwx...-dev' package other than just 'libwxbase...-dev' installed. The wxWidgets terminal will not be compiled.])
      enable_wxwidgets_ok=no
    fi
  fi

  dnl Check for Cairo
  PKG_CHECK_MODULES_NOFAIL(CAIROPANGO, [cairo >= 0.9.0 pango >= 1.22 pangocairo >= 1.10])
  if test $pkg_failed != no; then
    AC_MSG_WARN([The wxWidgets terminal will not be compiled.])
    enable_wxwidgets_ok=no
  fi
fi

if test "${enable_wxwidgets_ok}" = yes ; then
  WX_CXXFLAGS="`$WX_CONFIG --cxxflags | sed 's/-fno-exceptions//'` $CAIROPANGO_CFLAGS"
  WX_LIBS="`$WX_CONFIG --libs` $CAIROPANGO_LIBS $LIBRARIES_FOR_X"

  dnl Check for fork(), used for the 'persist' effect
  AC_FUNC_FORK

  dnl Check if wxWidgets uses gtk on this platform
  WX_TOOLKIT="`$WX_CONFIG --query-toolkit`"
  if test "${WX_TOOLKIT}" = gtk2 ; then
    PKG_CHECK_MODULES(GTK, [gtk+-2.0], have_gtk=yes, have_gtk=no)
    want_gtk=yes
  elif test "${WX_TOOLKIT}" = gtk3 ; then
    PKG_CHECK_MODULES(GTK, [gtk+-3.0], have_gtk=yes, have_gtk=no)
    want_gtk=yes
  fi
  if  test "${have_gtk}" = yes ; then
    AC_DEFINE(HAVE_GTK, 1, [define if your wxWidgets uses the gtk toolkit])
    WX_CXXFLAGS="$WX_CXXFLAGS $GTK_CFLAGS"
    WX_LIBS="$WX_LIBS $GTK_LIBS"
  fi

  dnl Default to single-threaded
  AC_ARG_WITH(wx-multithreaded, dnl
  [--with-wx-multithreaded  use multithreaded wxgtk (known problems, not recommended)],
  , WX_CXXFLAGS="$WX_CXXFLAGS -DWXT_MONOTHREADED"
  )

  CPPFLAGS="$CPPFLAGS $CAIROPANGO_CFLAGS"
  CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS"
  AC_SUBST(WX_LIBS)
  AC_DEFINE(WXWIDGETS, 1, [ Define if you want the wxwidgets terminal. ])
fi

AM_CONDITIONAL(BUILD_WXWIDGETS, test "${enable_wxwidgets_ok}" = yes)

dnl  End wxWidgets terminal

dnl  Allow to disable terminals requiring bitmap support.
AC_ARG_WITH(bitmap_terminals,dnl
[  --with-bitmap-terminals  dot-matrix printers and pbm])
AS_IF([test "x${with_bitmap_terminals}" = "xyes"],,
  AC_DEFINE(NO_BITMAP_SUPPORT,1,
          [ Define to disable terminals that depend on code in bitmap.c ]))
AM_CONDITIONAL(BUILD_BITMAP, test "${with_bitmap_terminals}" = yes)

dnl  Allow to disable support for tektronix terminal emulators
AC_ARG_WITH(tektronix,dnl
[  --without-tektronix      tektronix terminal emulators (default enabled)])
AS_IF([test "x${with_tektronix}" != "xno"],
  AC_DEFINE(WITH_TEKTRONIX,1,
          [ Define to include support for tektronix terminal emulators ],))

dnl  Allow to include gpic terminal
AC_ARG_WITH(gpic,dnl
[  --with-gpic              gpic terminal])
AS_IF([test "x${with_gpic}" = "xyes"],
  AC_DEFINE(HAVE_GPIC,1,
          [ Define to include support for gpic terminal ],))

dnl  Allow to include tgif terminal
AC_ARG_WITH(tgif,dnl
[  --with-tgif              tgif terminal])
AS_IF([test "x${with_tgif}" = "xyes"],
  AC_DEFINE(HAVE_TGIF,1,
          [ Define to include support for tgif terminal ],))

dnl  Allow to include metafont terminal
AC_ARG_WITH(metafont,dnl
[  --with-metafont          metafont terminal])
AS_IF([test "x${with_metafont}" = "xyes"],
  AC_DEFINE(HAVE_METAFONT,1,
          [ Define to include support for metafont terminal ],))

dnl  Allow to include metapost terminal
AC_ARG_WITH(metapost,dnl
[  --with-metapost          metapost terminal])
AS_IF([test "x${with_metapost}" = "xyes"],
  AC_DEFINE(HAVE_METAPOST,1,
          [ Define to include support for metapost terminal ],))

dnl ReGIS terminal
AC_ARG_WITH(regis,dnl
[  --with-regis             ReGIS terminal])
AS_IF([test "x${with_regis}" = "xyes"],
  AC_DEFINE(HAVE_REGIS,1,
          [ Define to include support for ReGIS terminal ],))

AC_ARG_WITH(cairo,dnl
[  --without-cairo          cairo-based terminals (default enabled)],,
  [test -z "${with_cairo}" && with_cairo=yes])

if test "${with_cairo}" = yes ; then
  dnl cairo terminals
  PKG_CHECK_MODULES_NOFAIL(CAIROPDF,dnl
       [cairo >= 1.2 cairo-pdf >= 1.2 pango >= 1.22 pangocairo >= 1.10 glib-2.0 >= 2.28])
  if test $pkg_failed != no; then
    AC_MSG_WARN([The cairo terminals will not be compiled.])
    with_cairo=no
  else
    AC_DEFINE(HAVE_CAIROPDF,1, [ Define if you want the cairo-based terminals. ])
    CPPFLAGS="$CPPFLAGS $CAIROPDF_CFLAGS"
    LIBS="$LIBS $CAIROPDF_LIBS"
    with_cairo=yes
    PKG_CHECK_MODULES(CAIROEPS, [cairo >= 1.6.0],
        AC_DEFINE([HAVE_CAIROEPS], 1, [libcairo support for eps (cairo >= 1.6)]),
        AC_MSG_WARN([Your version of cairo is too old to support epscairo output]))
  fi
fi

build_gpcairo=no
if test "${enable_wxwidgets_ok}" = yes; then
  build_gpcairo=yes
fi
if test "${with_cairo}" = yes; then
  build_gpcairo=yes
fi

AM_CONDITIONAL(BUILD_GPCAIRO, test "${build_gpcairo}" = yes)

dnl webp terminal
if test "${with_cairo}" = yes; then
  with_webp=yes
  PKG_CHECK_MODULES_NOFAIL(WEBP, [libwebp libwebpmux],
      [
      CPPFLAGS="$CPPFLAGS $WEBP_CFLAGS"
      TERMLIBS="$TERMLIBS $WEBP_LIBS"
      AC_DEFINE(HAVE_WEBP,1, [ Define to build the webp terminal. ])
      ],
      with_webp=no
  )
fi

dnl Enable polar mode gridded surface plots
AC_ARG_ENABLE(polar-grid,dnl
[  --enable-polar-grid     include support for gridded polar surface plots],
  [if test "$enableval" != no; then
    AC_DEFINE(USE_POLAR_GRID,1,
               [ Define to support polar gridded surface plots])
   fi],
    AC_DEFINE(USE_POLAR_GRID,1,
               [ Define to support polar gridded surface plots])
  )

dnl Enable subsystem to generate statistical summary of file contents
AC_ARG_ENABLE(stats,dnl
[  --disable-stats         Omit calculation of statistical summary of data],
  [if test "$enableval" != no; then
    AC_DEFINE(USE_STATS,1,
               [ Define to add support for generating a statistical summary of data])
   fi],
    AC_DEFINE(USE_STATS,1,
               [ Define to add support for generating a statistical summary of data])
   )

dnl Enable subsystem to set watchpoints that trigger during 2D plotting
AC_ARG_ENABLE(watchpoints,dnl
[  --enable-watchpoints    include support for setting watchpoints in 2D plots],
  [if test "$enableval" != no; then
    AC_DEFINE(USE_WATCHPOINTS,1,
               [ Define to support setting watchpoints in 2D plots])
   fi],
    AC_DEFINE(USE_WATCHPOINTS,1,
               [ Define to support setting watchpoints in 2D plots])
   )

dnl Enable callable blocks of gnuplot code treated as functions
AC_ARG_ENABLE(function-blocks,dnl
[  --enable-function-blocks include support for defining a function as a here document],
  [if test "$enableval" != no; then
    AC_DEFINE(USE_FUNCTIONBLOCKS, 1,
               [ Define to support defining a function as a here document])
   fi],
    AC_DEFINE(USE_FUNCTIONBLOCKS, 1,
               [ Define to support defining a function as a here document])
   )

dnl Enable parsing of deprecated syntax
AC_ARG_ENABLE(backward-compatibility,dnl
[  --enable-backward-compatibility       enable some deprecated syntax ],
  [if test "$enableval" = yes; then
    AC_DEFINE(BACKWARD_COMPATIBILITY,1,
               [ Define to allow use of some deprecated syntax. ])
  fi])

dnl Qt terminal

AC_ARG_WITH(qt,dnl
[  --with-qt [=qt4 =qt5 =no]  Qt terminal (default autodetect)],
  [if test "x${with_qt}" != "xno"; then
     enable_qt=yes;
   fi],
  enable_qt=yes)

if test "${enable_qt}" = yes ; then
  dnl variable used to determine if all checks pass
  enable_qt_ok=yes

  dnl Check for the C++ compiler
  if test "x${cxxerror}" = "xyes"; then
    AC_MSG_WARN([No C++ compiler found. The Qt terminal will not be compiled.])
      enable_qt_ok=no
  fi

  dnl Qt4 only by special request
  if test "x${with_qt}" = "xqt4"; then
    try_qt4=yes
  else
    try_qt4=no
  fi

  if test "x${with_qt}" != "xqt4"; then
    pkg_failed="not_tried"
    if test "x${with_qt}" != "xqt5"; then
      AC_MSG_CHECKING([Checking for Qt6 support libraries])
      PKG_CHECK_MODULES_NOFAIL(QT, [Qt6Core Qt6Gui Qt6Network Qt6Svg Qt6PrintSupport Qt6Widgets Qt6Core5Compat])
    fi
    if test $pkg_failed = no; then
      QT6LOC=`$PKG_CONFIG --variable=libexecdir Qt6Core`
      if test "x${QT6LOC}" != "x"; then
          UIC=${QT6LOC}/uic
          MOC=${QT6LOC}/moc
          RCC=${QT6LOC}/rcc
      elif test "x${UIC}" = "x"; then
          UIC=uic-qt6
          MOC=moc-qt6
          RCC=rcc-qt6
      fi
      QT6BIN=`$PKG_CONFIG --variable=bindir Qt6Core`
      if test "x${QT6BIN}" != "x"; then
          LRELEASE=${QT6BIN}/lrelease
      elif test "x${LRELEASE}" = "x"; then
          LRELEASE=lrelease-qt6
      fi

      CXXFLAGS="$CXXFLAGS -fPIC"
      AC_MSG_RESULT([The Qt terminal will use Qt6.])
      QTVER="6"
    else
      AC_MSG_CHECKING([Checking for Qt5 support libraries])
      PKG_CHECK_MODULES_NOFAIL(QT, [Qt5Core Qt5Gui Qt5Network Qt5Svg Qt5PrintSupport])
      if test $pkg_failed = no; then
        QT5LOC=`$PKG_CONFIG --variable=host_bins Qt5Core`
        if test "x${QT5LOC}" != "x"; then
          UIC=${QT5LOC}/uic
          MOC=${QT5LOC}/moc
          RCC=${QT5LOC}/rcc
          LRELEASE=${QT5LOC}/lrelease
        fi
        CXXFLAGS="$CXXFLAGS -fPIC"
        AC_MSG_RESULT([The Qt terminal will use Qt5.])
        QTVER="5"
      fi
    fi 
  fi

  dnl Explicit request for qt4 
  if test ${try_qt4} = yes; then
    AC_MSG_CHECKING([Checking for Qt4 support])
    PKG_CHECK_MODULES_NOFAIL(QT, [QtCore >= 4.5 QtGui >= 4.5 QtNetwork >= 4.5 QtSvg >= 4.5])
    if test $pkg_failed != no; then
      enable_qt_ok=no
      AC_MSG_RESULT([The Qt terminal will not be compiled.])
    else
      QT4LOC=`$PKG_CONFIG --variable=exec_prefix QtCore`
      UIC=`$PKG_CONFIG --variable=uic_location QtCore`
      MOC=`$PKG_CONFIG --variable=moc_location QtCore`
      RCC=`$PKG_CONFIG --variable=rcc_location QtCore`
      LRELEASE=`$PKG_CONFIG --variable=lrelease_location QtCore`
      AC_MSG_RESULT([The Qt terminal will use Qt4.])
      QTVER="4"
    fi
  fi
fi

if test "${enable_qt_ok}" = yes ; then
  dnl Check for fork()
  AC_FUNC_FORK

  CPPFLAGS="$CPPFLAGS $QT_CFLAGS"
  CXXFLAGS="$CXXFLAGS $QT_CXXFLAGS"

  if test x"$MOC" = x; then
    MOC=moc
  fi
  if test x"$UIC" = x; then
    UIC=uic
  fi
  if test x"$RCC" = x ; then
    if test x"$QT4LOC" != x ; then
        RCC=$QT4LOC/bin/rcc
    else
        RCC=rcc
    fi
  fi
  if test x"$LRELEASE" = x ; then
    if test x"$QT4LOC" != x ; then
        LRELEASE=$QT4LOC/bin/lrelease
    else
        LRELEASE=lrelease
    fi
  fi
  AC_SUBST(RCC)
  AC_SUBST(MOC)
  AC_SUBST(UIC)
  AC_SUBST(QT_LIBS)
  AC_SUBST(LRELEASE)
  AC_DEFINE(QTTERM,1, [ Define if you want the Qt terminal. ])
  AC_DEFINE_UNQUOTED(QTVER,$QTVER,[ only used for docs])
fi
AM_CONDITIONAL(BUILD_QT, test "${enable_qt_ok}" = yes)

dnl build mouse support if any mouse-requiring terminal is selected
if test "${enable_qt_ok}" = yes \
  || test "${enable_wxwidgets_ok}" = yes \
  || test "$GGI_SUPPORT" = yes \
  || test "$no_x" != yes; then
    enable_mouse=yes;
fi

if test "$enable_mouse" = yes; then
  AC_DEFINE(USE_MOUSE,1,
            [ Define if you have interactive terminals that use mouse support. ])
  AC_DEFINE(PIPE_IPC,1,
            [ Unix-type of Interprocess Communication is required for mouse support. ])
fi

dnl translation tools
AM_CONDITIONAL(HAVE_LRELEASE, test "${LRELEASE}" != no)

AC_ARG_VAR(DIST_CONTACT,[Contact address for modified and binary distributed gnuplot versions])
if test -n "${DIST_CONTACT}"; then
  AC_DEFINE_UNQUOTED([DIST_CONTACT],["$DIST_CONTACT"],[Contact address for modified and binary distributed gnuplot versions])
fi

dnl Substitute variables
AC_SUBST(PACKAGE)
AC_SUBST(VERSION_MAJOR)
AC_SUBST(VERSION)
AC_SUBST(PATCHLEVEL)
AC_SUBST(GIHDIR)
AC_SUBST(TEXDIR)
AC_SUBST(TERMLIBS)
AC_SUBST(TERMXLIBS)
dnl AC_SUBST(TUTORIAL)

dnl Write Makefiles and configuration header
AC_CONFIG_FILES([Makefile
           config/Makefile
           demo/Makefile
           demo/plugin/Makefile
           docs/Makefile
           m4/Makefile
           man/Makefile
           man/ja/Makefile
           share/Makefile
           share/LaTeX/Makefile
           src/Makefile
           src/wxterminal/Makefile
           src/qtterminal/Makefile
           term/Makefile
           ])
AC_CONFIG_COMMANDS([default],[test -z "$CONFIG_HEADERS" || echo timestamp >stamp-h],[])
AC_OUTPUT

dnl Report configuration
dnl Rationale:
dnl - if something is disabled by default, show arguments to use to enable.
dnl - if something has particular dependencies, show them all when they are
dnl missing (the detailed output will give more details anyway).
dnl The goal is to give sensible and easily accessible information to users
dnl and packagers.

AC_MSG_RESULT([])
AC_MSG_RESULT([** Configuration summary for $PACKAGE $VERSION:])
AC_MSG_RESULT([])

AC_MSG_RESULT([gnuplot will be compiled with the following terminals:])
AC_MSG_RESULT([])

AC_MSG_RESULT([  Standalone terminals: yes (included by default)])
AC_MSG_RESULT([    canvas cgm context dumb dxf emf epslatex])
AC_MSG_RESULT([    fig hpgl pcl5 postscript])
AC_MSG_RESULT([    pict2e pslatex pstex pstricks svg texdraw tkcanvas])
AC_MSG_RESULT([])

if test "$with_bitmap_terminals" = yes; then
  AC_MSG_RESULT([  Dot-matrix terminals: yes ( --without-bitmap-terminals to disable)])
else
  AC_MSG_RESULT([  Dot-matrix terminals: no (use --with-bitmap-terminals to enable)])
  AC_MSG_RESULT([  These would include, if enabled])
fi
AC_MSG_RESULT([    printers: epson nec okidata tandy seiko dpu414 ])
AC_MSG_RESULT([              hp500c hpdj hpljii hppj starc])
AC_MSG_RESULT([    other:    block pbm ])
AC_MSG_RESULT([])

if test "$with_tektronix" = no; then
  AC_MSG_RESULT([  Tektronix terminal emulators: no ( --with-tektronix to enable)])
else
  AC_MSG_RESULT([  Tektronix terminal emulators: yes ( --without-tektronix to disable)])
fi
AC_MSG_RESULT([    tek410x tek40 vttek xterm kc_tek40 km_tek40 selanar bitgraph])
AC_MSG_RESULT([    sixeltek (not needed for sixel graphics output to vt100-series emulators)])

AC_MSG_RESULT([])
AC_MSG_RESULT([  Platform-specific, legacy, or specialized terminals omitted by default:])

if test "$with_gpic" = yes; then
  AC_MSG_RESULT([    gpic      : yes])
else
  AC_MSG_RESULT([    gpic      :  no   (use --with-gpic to enable)])
fi

if test "$with_tgif" = yes; then
  AC_MSG_RESULT([    tgif      : yes])
else
  AC_MSG_RESULT([    tgif      :  no   (use --with-tgif to enable)])
fi

if test "$with_metafont" = yes; then
  AC_MSG_RESULT([    metafont  : yes])
else
  AC_MSG_RESULT([    metafont  :  no   (use --with-metafont to enable)])
fi

if test "$with_metapost" = yes; then
  AC_MSG_RESULT([    metapost  : yes])
else
  AC_MSG_RESULT([    metapost  :  no   (use --with-metapost to enable)])
fi

if test "$with_regis" = yes; then
  AC_MSG_RESULT([    ReGIS     : yes])
else
  AC_MSG_RESULT([    ReGIS     :  no   (use --with-regis to enable)])
fi

if test "$is_msdos" = yes; then
  AC_MSG_RESULT([    svga (djgpp): yes])
fi

if test "$with_caca" = yes; then
  AC_MSG_RESULT([    caca      : yes   (EXPERIMENTAL)])
else
  AC_MSG_RESULT([    caca      :  no   (use --with-caca to enable)])
fi

if test "$gnuplot_framework_AquaTerm" = yes; then
  AC_MSG_RESULT([    aqua      : yes   (macOS only)])
else
  AC_MSG_RESULT([    aqua      :  no   (macOS only)])
fi

AC_MSG_RESULT([])
AC_MSG_RESULT([  Other terminals that can be enabled but have no ./configure option:])
AC_MSG_RESULT([    eepic, emtex, hp2623a, hp2648, imagen, kyocera, latex, mif, tpic ])
AC_MSG_RESULT([    qms, pm (makefile.os2), be (BeOS), svga (MSDOS/djgpp), windows])

dnl These are the most common interactive terminal options
AC_MSG_RESULT([])
if test "$no_x" != yes; then
  if test "$enable_x11_mbfonts" = yes; then
    AC_MSG_RESULT([  x11 (X Window System): yes  (multi-byte fonts OK)])
  else
    AC_MSG_RESULT([  x11 (X Window System): yes  (multi-byte fonts not supported)])
  fi

  if test "$enable_x11_external" = yes; then
    AC_MSG_RESULT([                               (enable plotting to windows opened by external apps) ])
  else
    AC_MSG_RESULT([                               (disable plotting to windows opened by external apps) ])
  fi

  if test "$with_x_dcop" = yes; then
    AC_MSG_RESULT([    (gnuplot_x11 can use KDE3/DCOP to raise konsole) ])
  fi
else
  AC_MSG_RESULT([  x11 (X Window System) :   no (requires X libraries)])
fi

if test "$ac_cv_lib_gd_gdImageJpeg" = yes && 
   test "$ac_cv_lib_gd_gdImagePng" = yes && 
   test "$ac_cv_lib_gd_gdImageGif" = yes; then
    if test "$ac_cv_lib_gd_gdImageGifAnimBegin" = yes; then
      AC_MSG_RESULT([  libgd-based png jpeg gif sixel: yes (with animated gif)])
    else
      AC_MSG_RESULT([  libgd-based png jpeg gif sixel: yes (no animated gif)])
    fi
else
    AC_MSG_RESULT([  libgd-based png jpeg gif sixel: no (requires libgd,  see config.log) ])
fi

if test "$with_cairo" = yes; then
  AC_MSG_RESULT([  cairo-based pdf png  : yes ])
else
  AC_MSG_RESULT([  cairo-based terminals: no (requires cairo>=1.2, pango>=1.22, glib>=2.28)])
fi

if test "$with_webp" = yes; then
  AC_MSG_RESULT([  webp                 : yes ])
else
  AC_MSG_RESULT([  webp                 : no (requires cairo, pango, libwebp, libwebpmux)])
fi

if test "$with_lua" = yes; then
  AC_MSG_RESULT([  lua/TikZ             : yes ])
else
  AC_MSG_RESULT([  lua/TikZ             : no ])
fi

if test "$enable_wxwidgets_ok" = yes; then
  if test "$with_wx_multithreaded" = yes; then
    AC_MSG_RESULT([  wxt                  : yes (multithreaded)])
  else
    AC_MSG_RESULT([  wxt                  : yes ])
  fi
else
  AC_MSG_RESULT([  wxt                  : no (requires C++, wxWidgets>2.6, cairo>0.9, pango>1.22)])
fi

if test "$enable_qt_ok" = yes; then
  if test "$QTVER" = 4; then
      AC_MSG_RESULT([  Qt                   : yes (qt4)])
  elif test "$QTVER" = 5; then
      AC_MSG_RESULT([  Qt                   : yes (qt5)])
  elif test "$QTVER" = 6; then
      AC_MSG_RESULT([  Qt                   : yes (qt6)])
  else
      AC_MSG_RESULT([  Qt                   : no (requires C++, Qt5 or Qt6 support libraries)])
  fi
else
  AC_MSG_RESULT([  Qt                   : no (use --with-qt or --with-qt=qt4 or --with-qt=qt5 to enable])
fi

AC_MSG_RESULT([])
AC_MSG_RESULT([gnuplot will be compiled with the following configurable features:])
AC_MSG_RESULT([])

if test "$with_readline" = no; then
  AC_MSG_RESULT([  No readline support (use --with-readline=gnu or --with-readline=builtin)])
fi

  if test "$with_readline" = bsd; then
    if test -n "$gp_tcap"; then
      AC_MSG_RESULT([  Readline library: BSD editline with $gp_tcap])
    else
      AC_MSG_RESULT([  Readline library: BSD editline library])
    fi
  else if test "$with_readline" != builtin; then
    if test -n "$gp_tcap"; then
      AC_MSG_RESULT([  Readline library: GNU readline library with $gp_tcap])
    else
      AC_MSG_RESULT([  Readline library: GNU readline library])
    fi
    if test "$ac_cv_lib_readline_rl_forced_update_display" = no; then
      AC_MSG_RESULT([                    missing some features (OSX version?)])
    fi
  else
    AC_MSG_RESULT([  Readline library: builtin minimal (use --with-readline=gnu for GNU readline)])
  fi
fi

if test "$enable_history_file" = yes; then
  AC_MSG_RESULT([  Command-line history file:                       yes])
else
  AC_MSG_RESULT([  Command-line history file:                       no])
fi

if test "${enable_stable_sort}" = yes; then
  AC_MSG_RESULT([  Add code to ensure pm3d depth sorting is stable: yes])
elif test "${have_stable_sort}" = yes; then
  AC_MSG_RESULT([  Add code to ensure pm3d depth sorting is stable: no (not needed)])
else
  AC_MSG_RESULT([  Add code to ensure pm3d depth sorting is stable: no])
fi

if test "$enable_mouse" = yes; then
  AC_MSG_RESULT([  Mouse support in interactive terminals:          yes])
else
  AC_MSG_RESULT([  Mouse support in interactive terminals:          no])
fi

if test "$enable_raise_console" = yes; then
  AC_MSG_RESULT([  Typing <space> in plot window raises console:    yes])
else
  AC_MSG_RESULT([  Typing <space> in plot window raises console:    no])
fi

if test "$have_libcerf" = yes; then
  AC_MSG_RESULT([  cerf() and other special functions from libcerf: yes])
else
  AC_MSG_RESULT([  cerf() and other special functions: no (libcerf not found)])
fi

if test "$have_amoslibrary" = yes; then
  AC_MSG_RESULT([  Complex Airy and Bessel functions:               yes])
else
  AC_MSG_RESULT([  Complex Airy and Bessel functions:               no (requires libopenspec or libamos])
fi
if test "$have_cexint" = yes; then
  AC_MSG_RESULT([  Complex exponential integral cexint (libamos):   yes])
else
  AC_MSG_RESULT([  Complex exponential integral cexint (libamos):   no])
fi

if test "$have_external_functions" = yes; then
  AC_MSG_RESULT([  plugin support for loading external functions:   yes ])
else
  AC_MSG_RESULT([  plugin support for loading external functions:   no ])
fi

if test "$enable_backward_compatibility" = yes; then
  AC_MSG_RESULT([  Allow deprecated syntax:                         yes])
else
  AC_MSG_RESULT([  Allow deprecated syntax:                         no ])
fi

if test "$enable_stats" != no; then
  AC_MSG_RESULT([  Statistical summary of data ("stats" command):   yes])
else
  AC_MSG_RESULT([  Statistical summary of data ("stats" command):   no (--enable-stats to enable)])
fi

if test "$enable_watchpoints" != no; then
  AC_MSG_RESULT([  Support watchpoints during 2D plotting:          yes])
else
  AC_MSG_RESULT([  Support watchpoints during 2D plotting:          no (--enable-watchpoints to enable)])
fi

if test "$enable_polar_grid" != no; then
  AC_MSG_RESULT([  Support for polar gridded surfaces:              yes])
else
  AC_MSG_RESULT([  Support for polar gridded surfaces:              no (--enable-polar-grid to enable)])
fi

if test "$enable_function_blocks" != no; then
  AC_MSG_RESULT([  Support function blocks:                         yes])
else
  AC_MSG_RESULT([  Support function blocks:                         no (--enable-function-blocks to enable)])
fi

if test "$enable_chi_shapes" != no; then
  AC_MSG_RESULT([  Support concave hulls:                           yes])
else
  AC_MSG_RESULT([  Support concave hulls:                           no (--enable-chi-shapes to enable)])
fi

AC_MSG_RESULT([])
AC_MSG_RESULT([gnuplot will install the following additional materials:])
AC_MSG_RESULT([])

if test "$with_latex" != no; then
  AC_MSG_RESULT([  TeX files will be installed in $TEXDIR])
  AC_MSG_RESULT([                               (use --with-texdir=DIR to change)])
else
  AC_MSG_RESULT([  TeX files will not be installed])
fi
AC_MSG_RESULT([  PostScript prologue files: $GIHDIR/PostScript/])
AC_MSG_RESULT([  Help file: $GIHDIR/gnuplot.gih])

AC_MSG_RESULT([])

dnl end config report

dnl end configure.in