File: configure.ac

package info (click to toggle)
vips 8.7.4-1
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 32,524 kB
  • sloc: ansic: 110,470; cpp: 57,147; python: 6,038; sh: 5,000; xml: 4,047; makefile: 1,130; perl: 40
file content (1509 lines) | stat: -rw-r--r-- 43,416 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
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
# Process this file with autoconf to produce a configure script.

# also update the version number in the m4 macros below

AC_INIT([vips], [8.7.4], [vipsip@jiscmail.ac.uk])
# required for gobject-introspection
AC_PREREQ(2.62)

# gobject-introspection recommends -Wno-portability
# foreign stops complaints about a missing README (we use README.md instead)
# and missing INSTALL (the standard Gnu INSTALL is not very useful)
# subdir-objects lets us have dumy.cc in a subdir
AM_INIT_AUTOMAKE([-Wno-portability foreign subdir-objects])

AC_CONFIG_HEADERS(config.h)
AC_CONFIG_MACRO_DIR([m4])

# user-visible library versioning
m4_define([vips_major_version], [8])
m4_define([vips_minor_version], [7])
m4_define([vips_micro_version], [4])
m4_define([vips_version],
          [vips_major_version.vips_minor_version.vips_micro_version])

VIPS_MAJOR_VERSION=vips_major_version()
VIPS_MINOR_VERSION=vips_minor_version()
VIPS_MICRO_VERSION=vips_micro_version()
VIPS_VERSION=vips_version()
if test "x$SOURCE_DATE_EPOCH" = "x"; then
  VIPS_VERSION_STRING=$VIPS_VERSION-`date -u -r ChangeLog`
else
  VIPS_VERSION_STRING=$VIPS_VERSION-`LC_ALL=C date --utc --date="@$SOURCE_DATE_EPOCH"`
fi

# libtool library versioning ... not user-visible (except as part of the
# library file name) and does not correspond to major/minor/micro above

# rules:
# sources changed: increment revision
# binary interface changed: increment current, reset revision to 0
#   binary interface changes backwards compatible?: increment age
#   binary interface changes not backwards compatible?: reset age to 0

LIBRARY_CURRENT=51
LIBRARY_REVISION=5
LIBRARY_AGE=9

# patched into include/vips/version.h
AC_SUBST(VIPS_VERSION)
AC_SUBST(VIPS_VERSION_STRING)
AC_SUBST(VIPS_MAJOR_VERSION)
AC_SUBST(VIPS_MINOR_VERSION)
AC_SUBST(VIPS_MICRO_VERSION)

# put into library name by libsrc/Makefile.am and libsrcCC/Makefile.am
AC_SUBST(LIBRARY_CURRENT)
AC_SUBST(LIBRARY_REVISION)
AC_SUBST(LIBRARY_AGE)

# init introspection support
GOBJECT_INTROSPECTION_CHECK([1.30.0])

# gir needs a list of source files to scan for introspection
#
# build with a glob and a list of files to exclude from scanning
# see also IGNORE_HFILES in doc/Makefile.am
introspection_sources=$(cd libvips ; find . -name "*.c"; find . -name "*.cpp")
filter_list="deprecated introspect.c dummy.c fuzz "

# contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.
contains() {
  string="$1"
  substring="$2"
  if test x"${string#*$substring}" != x"$string"; then
    return 0    # $substring is in $string
  else
    return 1 	# $substring is not in $string
  fi
}

introspection_sources2=
for name in $introspection_sources; do
  found=0
  for filter in $filter_list; do
    if contains $name ${filter}; then
      found=1
    fi
  done    

  if [[ $found -eq 0 ]]; then
    introspection_sources2="$introspection_sources2 $name"
  fi      
done    
vips_introspection_sources="$introspection_sources2"

# add headers that form the public vips8 API .. don't do a find and exclude,
# we end up excluding almost everything argh
headers="\
	basic.h \
	vips.h \
	object.h \
	image.h \
	error.h \
	foreign.h \
	freqfilt.h \
	interpolate.h \
	header.h \
	histogram.h \
	operation.h \
	enumtypes.h \
	conversion.h \
	arithmetic.h \
	colour.h \
	convolution.h \
	create.h \
	draw.h \
	morphology.h \
	mosaicing.h \
	type.h \
	rect.h \
	resample.h \
	memory.h \
	region.h"

for name in $headers; do
  vips_introspection_sources="$vips_introspection_sources include/vips/$name"
done

AC_SUBST(vips_introspection_sources)

AC_CANONICAL_HOST

AC_DEFINE_UNQUOTED(G_LOG_DOMAIN, "VIPS", [Domain for glib logging messages.])

m4_define([debug_default], [no])
AC_ARG_ENABLE(debug,
  AC_HELP_STRING([--enable-debug=@<:@no/minimum/yes@:>@],
    [turn on debugging @<:@default=debug_default()@:>@]),,
  enable_debug=debug_default())

if test x"$enable_debug" = x"yes"; then
  VIPS_DEBUG_FLAGS="-DDEBUG_FATAL -DDEBUG_LEAK"
else
  VIPS_DEBUG_FLAGS="-DG_DISABLE_CAST_CHECKS"

  if test x"$enable_debug" = x"no"; then
    VIPS_DEBUG_FLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
  fi
fi

# option to disable deprecated code, shaves a bit off the library size
AC_ARG_ENABLE(deprecated,
  AS_HELP_STRING([--enable-deprecated], [build deprecated components (default: yes)]))

VIPS_ENABLE_DEPRECATED=0
if test x"$enable_deprecated" != x"no"; then
  VIPS_ENABLE_DEPRECATED=1
  enable_deprecated=yes
  AM_CONDITIONAL(ENABLE_DEPRECATED, true)
else
  AM_CONDITIONAL(ENABLE_DEPRECATED, false)
fi

# this gets pasted into version.h as a #define
AC_SUBST(VIPS_ENABLE_DEPRECATED)

# we are a C library with some optional C++ components inside it

# on most platforms, but not all, we just include -lstdc++ in the link line 
# for programs

# we ought to write a proper configure test for this :( 

AC_MSG_CHECKING([for needs -lstdc++])
case "$host_os" in
  freebsd*)
    vips_needs_stdcpp=no
    ;;
  *)
    vips_needs_stdcpp=yes
    ;;
esac
AC_MSG_RESULT([$vips_needs_stdcpp])

AC_MSG_CHECKING([for native Win32])
case "$host" in
  *-*-mingw*)
    vips_os_win32=yes
    ;;
  *)
    vips_os_win32=no
    ;;
esac
AC_MSG_RESULT([$vips_os_win32])

if test x"$vips_os_win32" = x"yes"; then
  AC_DEFINE(OS_WIN32,1,[native win32])

  # makes gcc use win native alignment
  VIPS_CFLAGS="-mms-bitfields $VIPS_CFLAGS"
fi

# CImg needs flags changed on win32
if test x"$vips_os_win32" = x"yes"; then
  AM_CONDITIONAL(OS_WIN32, true)
else
  AM_CONDITIONAL(OS_WIN32, false)
fi

# Cygwin/mingw need binary open to avoid CR/LF madness
# ... should be a better way to test for this
AC_MSG_CHECKING([for binary open needed])
case "$host_os" in
  cygwin* | mingw*)
    vips_binary_open=yes
    ;;
  *)
    vips_binary_open=no
    ;;
esac
AC_MSG_RESULT([$vips_binary_open])
if test x"$vips_binary_open" = x"yes"; then
  AC_DEFINE(BINARY_OPEN,1,[define to open non-text files in binary mode])
fi

AC_MSG_CHECKING([for Mac OS X])
case "$host" in
  *-*-darwin*)
    vips_os_darwin=yes
    ;;
  *)
    vips_os_darwin=no
    ;;
esac
AC_MSG_RESULT([$vips_os_darwin])

if test x"$vips_os_darwin" = x"yes"; then
  AC_DEFINE(VIPS_OS_DARWIN,1,[native Mac OS X])
fi

# set the default directory for ICC profiles
if test x"$vips_os_darwin" = x"yes"; then
  profile_dir="/Library/ColorSync/Profiles"
elif test x"$vips_os_win32" = x"yes"; then
  # need double escapes since this will get pasted into a #define in a C
  # header ... the C:\Windows is usually overrwritten with the result of
  # GetWindowsDirectoryW()
  profile_dir="C:\\\\Windows\\\\System32\\\\spool\\\\drivers\\\\color"
else
  profile_dir="/usr/share/color/icc"
fi
AC_DEFINE_UNQUOTED(VIPS_ICC_DIR,"$profile_dir",[default directory for ICC profiles])

# we want largefile support, if possible
AC_SYS_LARGEFILE

# Checks for programs.
AC_PROG_AWK
AC_PROG_CC
AC_PROG_CC_STDC
AC_PROG_CXX
AC_PROG_RANLIB
AC_PROG_INSTALL
AC_PROG_LN_S
AM_WITH_DMALLOC

# we need a fully expanded version of $libdir
# without this we get something like
#    define VIPS_LIBDIR ${exec_prefix}/lib
# argh
test x"$prefix" = x"NONE" && prefix=$ac_default_prefix
test x"$exec_prefix" = x"NONE" && exec_prefix='${prefix}'

# set $expanded_value to the fully-expanded value of the argument
expand () {
	eval expanded_value=$1

	if test x"$expanded_value" != x"$1"; then
		expand "$expanded_value"
	fi
}

expand $libdir
VIPS_LIBDIR=$expanded_value

# this gets pasted into version.h as a #define
VIPS_EXEEXT=$EXEEXT
AC_SUBST(VIPS_EXEEXT)

# vips.c/im_guess_prefix.c need to know the exe suffix and (as a fallback)
# the configure-time install prefix
AC_DEFINE_UNQUOTED(VIPS_PREFIX,"$prefix",[configure-time install prefix])
AC_DEFINE_UNQUOTED(VIPS_LIBDIR,"$VIPS_LIBDIR",[configure-time library directory])

# i18n
# we need to name our .mo with major.minor so we can have multiple versions
# installed in parallel on Debian
expand vips$VIPS_MAJOR_VERSION.$VIPS_MINOR_VERSION
GETTEXT_PACKAGE=$expanded_value

AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",
        [The prefix for our gettext translation domains.])
# the 'malkovich' one is there for testing only, remove for release
#ALL_LINGUAS="en_GB de malkovich"
ALL_LINGUAS="en_GB de"
AM_GLIB_GNU_GETTEXT

# we need to disable some features on some known-bad gcc versions
# these will be "" for clang etc. 
#
# I couldn't get this to work, mysterious! do it ourselves
# 
# AX_CHECK_COMPILE_FLAG([-dumpversion],
#   [ax_gcc_version_option=yes],
#   [ax_gcc_version_option=no]
# )
AC_MSG_CHECKING([for gcc version])
GCC_VERSION=""
version=$($CC -dumpversion)
if test $? = 0; then 
  GCC_VERSION=$version
  AC_MSG_RESULT([$GCC_VERSION])
else
  AC_MSG_RESULT([-dumpversion not supported])
fi

GCC_VERSION_MAJOR=$(echo $GCC_VERSION | cut -d'.' -f1)
GCC_VERSION_MINOR=$(echo $GCC_VERSION | cut -d'.' -f2)
GCC_VERSION_PATCH=$(echo $GCC_VERSION | cut -d'.' -f3)

# Checks for libraries.

# build list of pkg-config packages we used here
PACKAGES_USED=""

# build list of extra libs we need here
# the main one is jpeg: it does not have a .pc file, so when we make vips.pc
# we need to put -ljpeg into libs ourselves
EXTRA_LIBS_USED=""

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([errno.h math.h fcntl.h limits.h stdlib.h string.h sys/file.h sys/ioctl.h sys/param.h sys/time.h sys/mman.h sys/types.h sys/stat.h unistd.h io.h direct.h windows.h])

# uncomment to change which libs we build
# AC_DISABLE_SHARED
# AC_DISABLE_STATIC
AC_LIBTOOL_WIN32_DLL
AC_CHECK_TOOL(DLLWRAP, dllwrap)
AC_CHECK_TOOL(DLLTOOL, dlltool)
AC_CHECK_TOOL(OBJDUMP, objdump)
AC_CHECK_TOOL(RANLIB, ranlib)
AC_CHECK_TOOL(STRIP, strip)
AC_CHECK_TOOL(AR, ar)
AC_CHECK_TOOL(AS, as)
AC_CHECK_TOOL(LD, ld)
AC_PROVIDE([AC_LIBTOOL_WIN32_DLL])
AC_PROG_LIBTOOL

# Checks for typedefs, structures, and compiler characteristics.
AC_C_RESTRICT
AX_GCC_VAR_ATTRIBUTE(vector_size)
AC_C_CONST
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T

# g++/gcc 4.x and 5.x have rather broken vector support ... 5.4.1 seems to
# work, but 5.4.0 fails to even compile
AC_MSG_CHECKING([for gcc with working vector support])
if test x"$GCC_VERSION_MAJOR" != x"4" -a x"$GCC_VERSION_MAJOR" != x"5"; then
  AC_MSG_RESULT([yes])
else
  ax_cv_have_var_attribute_vector_size=no
  AC_MSG_RESULT([no])
fi

# we need to be able to shuffle vectors in C++
if test x"$ax_cv_have_var_attribute_vector_size" = x"yes"; then
  AC_MSG_CHECKING([for C++ vector shuffle])
  AC_LANG_PUSH([C++])
  AC_TRY_COMPILE([
    typedef float v4f __attribute__((vector_size(4 * sizeof(float))));
  ],[
    v4f f; f[3] = 99;
  ],[
    AC_MSG_RESULT([yes])
    have_vector_shuffle=yes
  ], [
    AC_MSG_RESULT([no])
    have_vector_shuffle=no
  ])
  AC_LANG_POP([C++])

  if test x"$have_vector_shuffle" = x"yes"; then
    AC_DEFINE_UNQUOTED(HAVE_VECTOR_SHUFFLE, 1,
      [define if your C++ can shuffle vectors])
  fi
fi

# we also need to be able to mix vector and scalar arithmetic
if test x"$have_vector_shuffle" = x"yes"; then
  AC_MSG_CHECKING([for C++ vector arithmetic])
  AC_LANG_PUSH([C++])
  AC_TRY_COMPILE([
    typedef float v4f __attribute__((vector_size(4 * sizeof(float))));
  ],[
    v4f f = {1, 2, 3, 4}; f *= 12.0; 
    v4f g = {5, 6, 7, 8}; f = g > 0 ? g : -1 * g;
  ],[
    AC_MSG_RESULT([yes])
    have_vector_arith=yes
  ], [
    AC_MSG_RESULT([no])
    have_vector_arith=no
  ])
  AC_LANG_POP([C++])
fi

# gcc 7.2 seems to work, but then gets confused by signed constants in 
# templates
if test x"$have_vector_arith" = x"yes"; then
  AC_MSG_CHECKING([for C++ signed constants in vector templates])
  AC_LANG_PUSH([C++])
  AC_TRY_COMPILE([
    typedef float v4f __attribute__((vector_size(4 * sizeof(float))));
    template <typename T>
    static void
    h( v4f B )
    {
        v4f f;
        f = -1 * B;
    }
  ],[
  ],[
    AC_MSG_RESULT([yes])
  ], [
    AC_MSG_RESULT([no])
    have_vector_arith=no
  ])
  AC_LANG_POP([C++])

  if test x"$have_vector_arith" = x"yes"; then
    AC_DEFINE_UNQUOTED(HAVE_VECTOR_ARITH, 1,
      [define if your C++ can mix vector and scalar arithmetic])
  fi
fi

# Checks for library functions.
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([getcwd gettimeofday getwd memset munmap putenv realpath strcasecmp strchr strcspn strdup strerror strrchr strspn vsnprintf realpath mkstemp mktemp random rand sysconf atexit])
AC_CHECK_LIB(m,cbrt,[AC_DEFINE(HAVE_CBRT,1,[have cbrt() in libm.])])
AC_CHECK_LIB(m,hypot,[AC_DEFINE(HAVE_HYPOT,1,[have hypot() in libm.])])
AC_CHECK_LIB(m,atan2,[AC_DEFINE(HAVE_ATAN2,1,[have atan2() in libm.])])

# have to have these
# need glib 2.6 for GOption
PKG_CHECK_MODULES(REQUIRED, glib-2.0 >= 2.6 gmodule-2.0 gobject-2.0)
PACKAGES_USED="$PACKAGES_USED glib-2.0 gmodule-2.0 gobject-2.0"

# from 2.14 we have g_option_context_get_help()
PKG_CHECK_MODULES(CONTEXT_GET_HELP, glib-2.0 >= 2.14,
  [AC_DEFINE(HAVE_CONTEXT_GET_HELP,1,
	    [define if your glib has g_option_context_get_help().]
   )
  ],
  [:
  ]
)

# from 2.28 we have a monotonic timer
PKG_CHECK_MODULES(MONOTONIC, glib-2.0 >= 2.28,
  [AC_DEFINE(HAVE_MONOTONIC_TIME,1,
	    [define if your glib has g_get_monotonic_time().]
   )
  ],
  [:
  ]
)

# from 2.32 there are a new set of thread functions, annoyingly
PKG_CHECK_MODULES(THREADS, glib-2.0 >= 2.32,
  [AC_DEFINE(HAVE_MUTEX_INIT,1,[define if your glib has g_mutex_init().])
   AC_DEFINE(HAVE_COND_INIT,1,[define if your glib has g_cond_init().])
   AC_DEFINE(HAVE_THREAD_NEW,1,[define if your glib has g_thread_new().])
   AC_DEFINE(HAVE_PRIVATE_INIT,1,[define if your glib has G_PRIVATE_INIT().])
   AC_DEFINE(HAVE_VALUE_GET_SCHAR,1,
	     [define if your glib has g_value_get_schar().]
   )
  ],
  [# the old threading system ... we need to link against gthread
   PKG_CHECK_MODULES(GTHREAD, gthread-2.0)
   PACKAGES_USED="$PACKAGES_USED gthread-2.0"
  ]
)

# from 2.36 the type system inits itself
PKG_CHECK_MODULES(TYPE_INIT, glib-2.0 < 2.36,
  [AC_DEFINE(HAVE_TYPE_INIT,1,[define if your glib needs g_type_init().])
  ],
  [:
  ]
)

# from 2.40, on win32 we have g_win32_get_command_line() 
PKG_CHECK_MODULES(WIN32_GET_COMMAND_LINE, glib-2.0 >= 2.40,
  [if test x"$vips_os_win32" = x"yes"; then
     AC_DEFINE(HAVE_G_WIN32_GET_COMMAND_LINE,1,[define if your glib has g_win32_get_command_line().])
     have_g_win32_get_command_line=yes
   fi
  ],
  [:
  ]
)

# from 2.40, have g_str_to_ascii()
PKG_CHECK_MODULES(STR_TO_ASCII, glib-2.0 >= 2.40,
  [AC_DEFINE(HAVE_G_STR_TO_ASCII,1,[define if your glib has g_str_to_ascii().])
  ],
  [:
  ]
)

# from 2.48 we have g_uint_checked_mul() etc.
PKG_CHECK_MODULES(HAVE_CHECKED_MUL, glib-2.0 >= 2.48,
  [AC_DEFINE(HAVE_CHECKED_MUL,1,[define if your glib has checked multiply.])
  ],
  [:
  ]
)

# check for gtk-doc
GTK_DOC_CHECK([1.14],[--flavour no-tmpl])

# we need expat ... we'd love to use expat.pc, but sadly this is only available
# for recent linuxes, so we have to use the old and horrible expat.m4
AM_WITH_EXPAT
if test x"$expat_found" = x"no"; then
  exit 1
fi

# enable vips7 C++ binding ... this defaults off, the vips8 C++ binding
# defaults on
AC_ARG_ENABLE([cpp7],
  AS_HELP_STRING([--enable-cpp7],
    [enable deprecated vips7 C++ binding (default: no)]),
  [enable_cpp7=$enableval
   AM_CONDITIONAL(ENABLE_CPP7, true)
  ], 
  [enable_cpp7="no (default)"
   AM_CONDITIONAL(ENABLE_CPP7, false)
  ]
)

# optional supporting libraries

AC_ARG_WITH([gsf], 
  AS_HELP_STRING([--without-gsf], [build without libgsf-1 (default: test)]))

# libgsf-1 1.14.21 crashes 
# .27 is known to work well
# .26 seems OK but has not been tested much
# not sure about 22-25
if test x"$with_gsf" != x"no"; then
  PKG_CHECK_MODULES(GSF, libgsf-1 >= 1.14.26,
    [AC_DEFINE(HAVE_GSF,1,[define if you have libgsf-1 installed.])
     with_gsf=yes
     PACKAGES_USED="$PACKAGES_USED libgsf-1"
    ],
    [AC_MSG_WARN([libgsf-1 not found; disabling dzsave support]) 
     with_gsf=no
    ]
  )

  # zip64 and deflate-level came in .31
  PKG_CHECK_MODULES(GSF_ZIP64, libgsf-1 >= 1.14.31,
    [AC_DEFINE(HAVE_GSF_ZIP64,1,[define if your libgsf supports zip64.])
     AC_DEFINE(HAVE_GSF_DEFLATE_LEVEL,1,
	       [define if your libgsf supports deflate-level.])
    ],
    [:
    ]
  )
fi

AC_ARG_WITH([fftw], 
  AS_HELP_STRING([--without-fftw], [build without fftw (default: test)]))

if test x"$with_fftw" != x"no"; then
  PKG_CHECK_MODULES(FFTW, fftw3,
    [AC_DEFINE(HAVE_FFTW,1,[define if you have fftw3 installed.])
     with_fftw=yes
     PACKAGES_USED="$PACKAGES_USED fftw3"
    ],
    [AC_MSG_WARN([fftw not found; disabling fftw support]) 
     with_fftw=no
    ]
  )
fi

# ImageMagick 
AC_ARG_WITH([magick], 
  AS_HELP_STRING([--without-magick], [build without libMagic (default: test)]))

AC_ARG_WITH([magickpackage], 
  AS_HELP_STRING([--with-magickpackage], 
    [magickpackage to use (default: MagickCore; try GraphicsMagick to build against gm instead)]))

# set the default magick package ... very old imagemagicks called it
# ImageMagick
if test x"$with_magickpackage" = x""; then
  PKG_CHECK_MODULES(MAGICK_WAND, MagickCore,
    [with_magickpackage=MagickCore
    ],
    [PKG_CHECK_MODULES(IMAGE_MAGICK, ImageMagick,
       [with_magickpackage=ImageMagick
       ],
       [AC_MSG_WARN([neither MagickCore nor ImageMagick found; disabling Magick support])
        with_magick=no
       ]
     )
    ]
  )
fi

# we have a separate loader for magick7 with fewer ifdef
# options; only test for features on the magick6 case

magick_version=
if test x"$with_magick" != x"no"; then
  PKG_CHECK_MODULES(MAGICK, $with_magickpackage >= 7.0,  
    [AC_DEFINE(HAVE_MAGICK7,1,[define if you have libMagick7 installed.])
     with_magick=yes
     magick7=yes
     magick_version=magick7
     PACKAGES_USED="$PACKAGES_USED $with_magickpackage"
    ],
    [PKG_CHECK_MODULES(MAGICK, $with_magickpackage,  
       [AC_DEFINE(HAVE_MAGICK6,1,[define if you have libMagick6 installed.])
        with_magick=yes
        magick6=yes
        magick_version=magick6
        PACKAGES_USED="$PACKAGES_USED $with_magickpackage"
       ],
       [AC_MSG_WARN([$with_magickpackage not found; disabling Magick support])
        with_magick=no
       ]
     )
    ]  
  )
else
  with_magick=no
  magick6=no
  magick_version=none
  with_magickpackage=none
fi

if test x"$magick6" = x"yes"; then
  # we SetImageOption to disable some DICOM read processing, but that's only
  # in more recent imagemagicks and not in graphicsmagick
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(SetImageOption,
    AC_DEFINE(HAVE_SETIMAGEOPTION,1,[define if your magick has SetImageOption.])
  )
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # newer ImageMagicks use MagickCoreGenesis instead of InitializeMagick argh
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(MagickCoreGenesis,
    AC_DEFINE(HAVE_MAGICKCOREGENESIS,1,
	      [define if your magick has MagickCoreGenesis.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # newer ImageMagicks use ResetImagePropertyIterator instead of
  # ResetImageAttributeIterator argh
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(ResetImagePropertyIterator,
    AC_DEFINE(HAVE_RESETIMAGEPROPERTYITERATOR,1,
	      [define if your magick has ResetImagePropertyIterator.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # so ... do we have ResetImageAttributeIterator()? GM does not
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(ResetImageAttributeIterator,
    AC_DEFINE(HAVE_RESETIMAGEATTRIBUTEITERATOR,1,
	      [define if your magick has ResetImageAttributeIterator.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # more recent magicks have GetVirtualPixels rather than GetImagePixels
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(GetVirtualPixels,
    AC_DEFINE(HAVE_GETVIRTUALPIXELS,1,
	      [define if your magick has GetVirtualPixels.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # do we have number_scenes in image_info ... imagemagick uses this
  save_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS $MAGICK_CFLAGS"
  AC_CHECK_MEMBER([struct _ImageInfo.number_scenes],
    AC_DEFINE(HAVE_NUMBER_SCENES,1,
	      [define if your magick has ImageInfo.number_scenes.]),
    [],
    [#include <magick/api.h>])
  CFLAGS="$save_CFLAGS"
fi

if test x"$magick6" = x"yes"; then
  # more recent magick6s have AcquireImage rather than AllocateImage argh
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(AcquireImage,
    AC_DEFINE(HAVE_ACQUIREIMAGE,1,
	      [define if your magick has AcquireImage.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # more recent magick6s have SetImageExtent 
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(SetImageExtent,
    AC_DEFINE(HAVE_SETIMAGEEXTENT,1,
	      [define if your magick has SetImageExtent.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # GM uses SetImageAttribute(), IM uses SetImageProperty()
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(SetImageProperty,
    AC_DEFINE(HAVE_SETIMAGEPROPERTY,1,
	      [define if your magick has SetImageProperty.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # GM is missing InheritException
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(InheritException,
    AC_DEFINE(HAVE_INHERITEXCEPTION,1,
	      [define if your magick has InheritException.]))
  LIBS="$save_LIBS"
fi

if test x"$magick6" = x"yes"; then
  # GM is missing AcquireExceptionInfo
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(AcquireExceptionInfo,
    AC_DEFINE(HAVE_ACQUIREEXCEPTIONINFO,1,
	      [define if your magick has AcquireExceptionInfo.]))
  LIBS="$save_LIBS"
fi

# have flags to turn load and save off independently ... some people will want
# save but not load, for example
AC_ARG_ENABLE([magickload], 
  AS_HELP_STRING([--disable-magickload], 
		 [disable libMagic load (default: enabled)]))

AC_ARG_ENABLE([magicksave], 
  AS_HELP_STRING([--disable-magicksave], 
		 [disable libMagic save (default: enabled)]))

if test x"$enable_magicksave" != x"yes"; then
  # we need ImportImagePixels ... GM is missing this sadly
  save_LIBS="$LIBS"
  LIBS="$LIBS $MAGICK_LIBS"
  AC_CHECK_FUNCS(ImportImagePixels,[
     AC_DEFINE(HAVE_IMPORTIMAGEPIXELS,1,
	       [define if you have ImportImagePixels.])
   ],[
     AC_MSG_WARN([ImportImagePixels not found; disabling magicksave])
     enable_magicksave=no
   ]
  )
  LIBS="$save_LIBS"
fi

if test x"$with_magick" != x"no"; then
  if test x"$enable_magickload" != x"no"; then
    AC_DEFINE(ENABLE_MAGICKLOAD,1,[define to enable load with libMagick])
    enable_magickload=yes
  fi

  if test x"$enable_magicksave" != x"no"; then
    AC_DEFINE(ENABLE_MAGICKSAVE,1,[define to enable save with libMagick])
    enable_magicksave=yes
  fi
else
  enable_magickload=no
  enable_magicksave=no
fi

# orc
AC_ARG_WITH([orc], 
  AS_HELP_STRING([--without-orc], [build without orc (default: test)]))

if test x"$with_orc" != x"no"; then
  # we use loadpw etc.
  PKG_CHECK_MODULES(ORC, orc-0.4 >= 0.4.11,
    [AC_DEFINE(HAVE_ORC,1,[define if you have orc-0.4.11 or later installed.])
     with_orc=yes
     PACKAGES_USED="$PACKAGES_USED orc-0.4"
     save_LIBS="$LIBS"
     LIBS="$LIBS $ORC_LIBS"
     AC_CHECK_FUNCS(orc_program_get_error,
       AC_DEFINE(HAVE_ORC_PROGRAM_GET_ERROR,1,
	      [define if your orc has orc_program_get_error.]))
     LIBS="$save_LIBS"
    ],
    [AC_MSG_WARN([orc-0.4.11 or later not found; disabling orc support])
     with_orc=no
    ]
  )
fi

# lcms ... refuse to use lcms1
AC_ARG_WITH([lcms], 
  AS_HELP_STRING([--without-lcms], [build without lcms (default: test)]))

if test x"$with_lcms" != x"no"; then
  PKG_CHECK_MODULES(LCMS, lcms2,
    [AC_DEFINE(HAVE_LCMS2,1,[define if you have lcms2 installed.])
     with_lcms="yes (lcms2)"
     PACKAGES_USED="$PACKAGES_USED lcms2"
    ],
    [AC_MSG_WARN([lcms2 not found; disabling ICC profile support])
     with_lcms=no
    ]
  )
fi

# OpenEXR
AC_ARG_WITH([OpenEXR], 
  AS_HELP_STRING([--without-OpenEXR], [build without OpenEXR (default: test)]))

# require 1.2.2 since 1.2.1 has a broken ImfCloseTiledInputFile()
if test x"$with_OpenEXR" != x"no"; then
  PKG_CHECK_MODULES(OPENEXR, OpenEXR >= 1.2.2,
    [AC_DEFINE(HAVE_OPENEXR,1,[define if you have OpenEXR >=1.2.2 installed.])
     with_OpenEXR=yes
     PACKAGES_USED="$PACKAGES_USED OpenEXR"
    ],
    [AC_MSG_WARN([OpenEXR not found; disabling OpenEXR support])
     with_OpenEXR=no
    ]
  )
fi

# nifti
AC_ARG_WITH([nifti],
  AS_HELP_STRING([--without-nifti], [build without nifti (default: test)]))

if test x"$with_nifti" != x"no"; then
  FIND_NIFTI([
     with_nifti=yes
    ],[
     with_nifti=no
    ]
  )
fi

# pdfium
AC_ARG_WITH([pdfium],
  AS_HELP_STRING([--without-pdfium], [build without pdfium (default: test)]))

if test x"$with_pdfium" != x"no"; then
  FIND_PDFIUM([
     if test x"$with_poppler" != x"no"; then
       AC_MSG_WARN([PDFium found, disabling poppler])
       with_poppler=no
     fi
     with_pdfium=yes
    ],[
     with_pdfium=no
    ]
  )
fi

# poppler
AC_ARG_WITH([poppler],
  AS_HELP_STRING([--without-poppler], [build without poppler (default: test)]))

if test x"$with_poppler" != x"no"; then
  PKG_CHECK_MODULES(POPPLER, [poppler-glib >= 0.16.0 cairo >= 1.2],
    [AC_DEFINE(HAVE_POPPLER,1,[define if you have poppler-glib >= 0.16.0 and cairo >= 1.2 installed.])
     with_poppler=yes
     PACKAGES_USED="$PACKAGES_USED poppler-glib cairo"
    ],
    [AC_MSG_WARN([poppler-glib >= 0.16.0 or cairo >= 1.2 not found; disabling PDF load via poppler])
     with_poppler=no
    ]
  )
fi

# librsvg
AC_ARG_WITH([rsvg],
  AS_HELP_STRING([--without-rsvg], [build without rsvg (default: test)]))

if test x"$with_rsvg" != x"no"; then
  PKG_CHECK_MODULES(RSVG, [librsvg-2.0 >= 2.34 cairo >= 1.2],
    [AC_DEFINE(HAVE_RSVG,1,[define if you have librsvg-2.0 >= 2.34.0 and cairo >= 1.2 installed.])
     with_rsvg=yes
     PACKAGES_USED="$PACKAGES_USED librsvg-2.0 cairo"
    ],
    [AC_MSG_WARN([librsvg-2.0 >= 2.34.0 or cairo >= 1.2 not found; disabling SVG load via rsvg])
     with_rsvg=no
    ]
  )
fi

# zlib
# some platforms, like macosx, are missing the .pc files for zlib, so
# we fall back to FIND_ZLIB
AC_ARG_WITH([zlib], 
  AS_HELP_STRING([--without-zlib], [build without zlib (default: test)]))

if test x"$with_zlib" != x"no"; then
  PKG_CHECK_MODULES(ZLIB, zlib >= 0.4,
    [AC_DEFINE(HAVE_ZLIB,1,[define if you have zlib installed.])
     with_zlib=yes
     PACKAGES_USED="$PACKAGES_USED zlib"
    ],
    [FIND_ZLIB(
       [with_zlib="yes (found by search)"
       ], 
       [AC_MSG_WARN([zlib not found; disabling SVGZ buffer support])
        with_zlib=no
       ]
     )
    ]
  )
fi

# OpenSlide
AC_ARG_WITH([openslide],
  AS_HELP_STRING([--without-openslide], 
    [build without OpenSlide (default: test)])
)

if test x"$with_openslide" != x"no"; then
  PKG_CHECK_MODULES(OPENSLIDE, [openslide >= 3.4.0],
    [AC_DEFINE(HAVE_OPENSLIDE_3_4,1,[define if you have OpenSlide >= 3.4.0 installed.])
     AC_DEFINE(HAVE_OPENSLIDE,1,[define if you have OpenSlide >= 3.3.0 installed.])
     with_openslide=yes
     PACKAGES_USED="$PACKAGES_USED openslide"
    ],
    [AC_MSG_NOTICE([OpenSlide >= 3.4.0 not found; checking for >= 3.3.0])
     PKG_CHECK_MODULES(OPENSLIDE, [openslide >= 3.3.0],
       [AC_DEFINE(HAVE_OPENSLIDE,1,[define if you have OpenSlide >= 3.3.0 installed.])
        with_openslide=yes
        PACKAGES_USED="$PACKAGES_USED openslide"
       ],
       [AC_MSG_WARN([OpenSlide >= 3.3.0 not found; disabling virtual slide support])
        with_openslide=no
       ]
     )
    ]
  )
fi

# matio
AC_ARG_WITH([matio], 
  AS_HELP_STRING([--without-matio], [build without matio (default: test)]))

if test x"$with_matio" != x"no"; then
  PKG_CHECK_MODULES(MATIO, matio,
    [AC_DEFINE(HAVE_MATIO,1,[define if you have matio installed.])
     with_matio=yes
     PACKAGES_USED="$PACKAGES_USED matio"
    ],
    [AC_MSG_WARN([matio not found; disabling matio support])
     with_matio=no
    ]
  )
fi

# not external libraries, but have options to disable them, helps to
# reduce attack surface

AC_ARG_WITH([ppm], 
  AS_HELP_STRING([--without-ppm], [build without ppm (default: with)]))

if test x"$with_ppm" != x"no"; then
  AC_DEFINE(HAVE_PPM,1,[define to build ppm support.])
  with_ppm=yes
fi

AC_ARG_WITH([analyze], 
  AS_HELP_STRING([--without-analyze], [build without analyze (default: with)]))

if test x"$with_analyze" != x"no"; then
  AC_DEFINE(HAVE_ANALYZE,1,[define to build analyze support.])
  with_analyze=yes
fi

AC_ARG_WITH([radiance], 
  AS_HELP_STRING([--without-radiance], [build without radiance (default: with)]))

if test x"$with_radiance" != x"no"; then
  AC_DEFINE(HAVE_RADIANCE,1,[define to build radiance support.])
  with_radiance=yes
fi

# cfitsio
AC_ARG_WITH([cfitsio], 
  AS_HELP_STRING([--without-cfitsio], [build without cfitsio (default: test)]))

if test x"$with_cfitsio" != x"no"; then
  PKG_CHECK_MODULES(CFITSIO, cfitsio,
    [AC_DEFINE(HAVE_CFITSIO,1,[define if you have cfitsio installed.])
     with_cfitsio=yes
     PACKAGES_USED="$PACKAGES_USED cfitsio"
    ],
    [AC_MSG_WARN([cfitsio not found; disabling cfitsio support])
     with_cfitsio=no
    ]
  )
fi

# libwebp
# some platforms, like ubuntu 12.04, are missing the .pc files for libwebp, so
# we fall back to FIND_LIBWEBP
AC_ARG_WITH([libwebp], 
  AS_HELP_STRING([--without-libwebp], [build without libwebp (default: test)]))

if test x"$with_libwebp" != x"no"; then
  PKG_CHECK_MODULES(LIBWEBP, libwebp >= 0.1.3,
    [AC_DEFINE(HAVE_LIBWEBP,1,[define if you have libwebp installed.])
     with_libwebp=yes
     PACKAGES_USED="$PACKAGES_USED libwebp"
    ],
    [FIND_LIBWEBP(
       [with_libwebp="yes (found by search)"
       ], 
       [AC_MSG_WARN([libwebp not found; disabling WEBP support])
        with_libwebp=no
       ]
     )
    ]
  )
fi

# webp has the stuff for pulling out ICC profile etc in a separate library
# 
# we can build with libwebpmux back to 0.3, but it's not until libwebp 0.5 that
# we can read that metadata back successfully ... insist on 0.5 so that tests
# can work smoothly
if test x"$with_libwebp" != x"no"; then
  PKG_CHECK_MODULES(LIBWEBPMUX, libwebpmux >= 0.5.0,
    [AC_DEFINE(HAVE_LIBWEBPMUX,1,[define if you have libwebpmux installed.])
     with_libwebpmux=yes
     PACKAGES_USED="$PACKAGES_USED libwebpmux"
    ],
    [AC_MSG_WARN([libwebpmux not found; disabling webp metadata support])
     with_libwebpmux=no
    ]
  )
fi

# pangoft2
AC_ARG_WITH([pangoft2], 
  AS_HELP_STRING([--without-pangoft2], 
    [build without pangoft2 (default: test)]))

if test x"$with_pangoft2" != x"no"; then
  PKG_CHECK_MODULES(PANGOFT2, pangoft2,
    [AC_DEFINE(HAVE_PANGOFT2,1,[define if you have pangoft2 installed.])
     with_pangoft2=yes
     PACKAGES_USED="$PACKAGES_USED pangoft2"
    ],
    [AC_MSG_WARN([pangoft2 not found; disabling pangoft2 support])
     with_pangoft2=no
    ]
  )
fi

# install vips8 python
AC_ARG_ENABLE([pyvips8],
  AS_HELP_STRING([--enable-pyvips8],
    [install vips8 Python overrides (default: no)]),
  [enable_pyvips8=$enableval
  ], 
  [enable_pyvips8="no (default)"
  ]
)

if test x"$enable_pyvips8" = x"auto"; then
  PKG_CHECK_EXISTS([pygobject-3.0 >= 3.13.0],
    [enable_pyvips8=yes
    ],
    [AC_MSG_WARN([pygobject-3.0 not found; disabling vips8 python support])
     enable_pyvips8=no
    ]
  )
fi

if test x"$enable_pyvips8" = x"yes"; then
  JD_PATH_PYTHON(2.7,,
    [enable_pyvips8=no
     AC_MSG_WARN([Python not found; disabling vips8 Python binding])
    ]
  )
fi

if test x"$enable_pyvips8" = x"yes"; then
  PKG_CHECK_MODULES(PYGOBJECT, [pygobject-3.0 >= 3.13.0])
fi

AM_CONDITIONAL(ENABLE_PYVIPS8, test x"$enable_pyvips8" = x"yes")

# look for TIFF with pkg-config ... fall back to our tester
# pkgconfig support for libtiff starts with libtiff-4
AC_ARG_WITH([tiff], 
  AS_HELP_STRING([--without-tiff], [build without libtiff (default: test)]))

if test x"$with_tiff" != x"no"; then
  PKG_CHECK_MODULES(TIFF, libtiff-4,
    [AC_DEFINE(HAVE_TIFF,1,[define if you have libtiff installed.])
     with_tiff="yes (pkg-config libtiff-4)"
     PACKAGES_USED="$PACKAGES_USED libtiff-4"
    ],
    [FIND_TIFF(
       with_tiff="yes (found by search)",
       [AC_MSG_WARN([libtiff not found; disabling TIFF support])
        with_tiff=no
       ]
     )
    ]
  )
fi

# giflib
FIND_GIFLIB(
  [with_giflib="yes (found by search)"
  ], 
  [AC_MSG_WARN([giflib not found; disabling direct GIF support])
   with_giflib=no
  ]
)

# look for PNG with pkg-config ... fall back to our tester
AC_ARG_WITH([png], 
  AS_HELP_STRING([--without-png], [build without libpng (default: test)]))

if test x"$with_png" != x"no"; then
  PKG_CHECK_MODULES(PNG, libpng >= 1.2.9, 
    [AC_DEFINE(HAVE_PNG,1,[define if you have libpng installed.])
     with_png="yes (pkg-config libpng >= 1.2.9)"
     PACKAGES_USED="$PACKAGES_USED libpng"
    ],
    [FIND_PNG(
       [with_png="yes (found by search)"
       ],
       [AC_MSG_WARN([libpng not found; disabling PNG support])
        with_png=no
       ]
     )
    ]
  )
fi

# look for libimagequant with pkg-config (only if libpng is enabled)
AC_ARG_WITH([imagequant],
  AS_HELP_STRING([--without-imagequant], [build without imagequant (default: test)]))

if test x"$with_imagequant" != x"no" && test x"$with_png" != x"no"; then
  PKG_CHECK_MODULES(IMAGEQUANT, imagequant,
    [AC_DEFINE(HAVE_IMAGEQUANT,1,[define if you have imagequant installed.])
     with_imagequant=yes
     PACKAGES_USED="$PACKAGES_USED imagequant"
    ],
    [AC_MSG_WARN([libimagequant not found; disabling 8bpp PNG support])
     with_imagequant=no
    ]
  )
else
  with_imagequant=no
fi

# look for libjpeg with pkg-config ... fall back to our tester
AC_ARG_WITH([jpeg], 
  AS_HELP_STRING([--without-jpeg], [build without libjpeg (default: test)]))

if test x"$with_jpeg" != x"no"; then
  PKG_CHECK_MODULES(JPEG, libjpeg,
    [AC_DEFINE(HAVE_JPEG,1,[define if you have libjpeg installed.])
     with_jpeg="yes (pkg-config)"
     PACKAGES_USED="$PACKAGES_USED libjpeg"
    ],
    [FIND_JPEG(
       [with_jpeg="yes (found by search)"
	EXTRA_LIBS_USED="$EXTRA_LIBS_USED -ljpeg"
       ],
       [AC_MSG_WARN([libjpeg not found; disabling JPEG support])
        with_jpeg=no
       ]
     )
    ]
  )
fi

# features like trellis quant are exposed as extension parameters ...
# mozjpeg 3.2 and later have #define JPEG_C_PARAM_SUPPORTED, but we must 
# work with earlier versions
if test x"$with_jpeg" != x"no"; then
  save_LIBS="$LIBS"
  save_CFLAGS="$CFLAGS"
  LIBS="$JPEG_LIBS $LIBS"
  CFLAGS="$JPEG_INCLUDES $CFLAGS"
  AC_CHECK_FUNCS(jpeg_c_bool_param_supported,
    AC_DEFINE(HAVE_JPEG_EXT_PARAMS,1,
	      [define if your libjpeg has extension parameters.]))
  LIBS="$save_LIBS"
  CFLAGS="$save_CFLAGS"
fi

# libexif
AC_ARG_WITH([libexif], 
  AS_HELP_STRING([--without-libexif], [build without libexif (default: test)]))

if test x"$with_libexif" != x"no"; then
  PKG_CHECK_MODULES(EXIF, libexif >= 0.6,
    [AC_DEFINE(HAVE_EXIF,1,[define if you have libexif >= 0.6 installed.])
     with_libexif=yes
     PACKAGES_USED="$PACKAGES_USED libexif"
    ],
    [AC_MSG_WARN([libexif >= 0.6 not found; disabling exif support])
     with_libexif=no
    ]
  )
fi

# some libexif packages need include <libexif/poop.h>, some just <poop.h>
# how annoying
if test x"$with_libexif" != x"no"; then
  # cppflags not cflags because we want the preproc to see the -I as well
  save_CPPFLAGS="$CPPFLAGS"
  CPPFLAGS="$EXIF_CFLAGS $CPPFLAGS"
  AC_CHECK_HEADER(exif-data.h,
    AC_DEFINE(UNTAGGED_EXIF,1,[libexif includes don't need libexif prefix]))
  CPPFLAGS="$save_CPPFLAGS"
fi

# make vips7 (swig-based) py binding
AC_ARG_ENABLE([pyvips7],
  AS_HELP_STRING([--enable-pyvips7], [build vips7 Python binding (default: no)]),
  [enable_pyvips7=$enableval
  ], 
  [enable_pyvips7="no (default)"
  ]
)

if test x"$enable_pyvips7" = x"yes"; then
  if test x"$enable_cxx" = x"no"; then
    # if C++ is off, we can't do Python
    enable_pyvips7=no
    AC_MSG_WARN([C++ is off, disabling vips7 Python binding])
  fi
fi

if test x"$enable_pyvips7" = x"yes"; then
  JD_PATH_PYTHON(2.7,,
    [enable_pyvips7=no
     AC_MSG_WARN([Python >= 2.7 not found; disabling vips7 Python binding])
    ]
  )
fi

if test x"$enable_pyvips7" = x"yes"; then
  # The SWIG bindings don't compile on python3 (see issue #334).
  AM_PYTHON_CHECK_VERSION([$PYTHON], [3.0],
    [enable_pyvips7=no
     AC_MSG_WARN([Python >= 3.0 found; disabling vips7 Python binding])
    ]
  )
fi

if test x"$enable_pyvips7" = x"yes"; then
  AM_CHECK_PYTHON_HEADERS(,
    [enable_pyvips7=no
     AC_MSG_WARN([Python headers not found; disabling vips7 Python binding])
    ]
  )
fi

# we don't check for swig: we include the generated bindings in the
# distribution

if test x"$enable_pyvips7" = x"yes"; then
  AM_CONDITIONAL(HAVE_PYTHON, true)
else
  AM_CONDITIONAL(HAVE_PYTHON, false)
fi

# Gather all up for VIPS_CFLAGS, VIPS_INCLUDES, VIPS_LIBS 
# sort includes to get longer, more specific dirs first
# helps, for example, selecting graphicsmagick over imagemagick
VIPS_CFLAGS=`for i in $VIPS_CFLAGS $GTHREAD_CFLAGS $REQUIRED_CFLAGS $EXPAT_CFLAGS $ZLIB_CFLAGS $PANGOFT2_CFLAGS $GSF_CFLAGS $FFTW_CFLAGS $MAGICK_CFLAGS $JPEG_CFLAGS $PNG_CFLAGS $IMAGEQUANT_CFLAGS $EXIF_CFLAGS $MATIO_CFLAGS $CFITSIO_CFLAGS $LIBWEBP_CFLAGS $LIBWEBPMUX_CFLAGS $GIFLIB_INCLUDES $RSVG_CFLAGS $PDFIUM_INCLUDES $POPPLER_CFLAGS $OPENEXR_CFLAGS $OPENSLIDE_CFLAGS $ORC_CFLAGS $TIFF_CFLAGS $LCMS_CFLAGS 
do 
	echo $i 
done | sort -ru`
VIPS_CFLAGS=`echo $VIPS_CFLAGS`
VIPS_CFLAGS="$VIPS_DEBUG_FLAGS $VIPS_CFLAGS"
VIPS_INCLUDES="$ZLIB_INCLUDES $PNG_INCLUDES $TIFF_INCLUDES $JPEG_INCLUDES $NIFTI_INCLUDES" 
VIPS_LIBS="$ZLIB_LIBS $MAGICK_LIBS $PNG_LIBS $IMAGEQUANT_LIBS $TIFF_LIBS $JPEG_LIBS $GTHREAD_LIBS $REQUIRED_LIBS $EXPAT_LIBS $PANGOFT2_LIBS $GSF_LIBS $FFTW_LIBS $ORC_LIBS $LCMS_LIBS $GIFLIB_LIBS $RSVG_LIBS $NIFTI_LIBS $PDFIUM_LIBS $POPPLER_LIBS $OPENEXR_LIBS $OPENSLIDE_LIBS $CFITSIO_LIBS $LIBWEBP_LIBS $LIBWEBPMUX_LIBS $MATIO_LIBS $EXIF_LIBS -lm"

AC_SUBST(VIPS_LIBDIR)

AC_SUBST(VIPS_CFLAGS)
AC_SUBST(VIPS_INCLUDES)
AC_SUBST(VIPS_LIBS)
AC_SUBST(PACKAGES_USED)
AC_SUBST(EXTRA_LIBS_USED)

# needed by test/variables.sh.in
# :( what's a better way to do this, argh
TOP_SRCDIR=$ac_pwd
AC_SUBST(TOP_SRCDIR)

AC_OUTPUT([
	vips.pc
	vipsCC.pc
	vips-cpp.pc
	Makefile 
	libvips/include/vips/version.h 
	libvips/include/Makefile 
	libvips/include/vips/Makefile 
	libvips/Makefile 
	libvips/arithmetic/Makefile 
	libvips/colour/Makefile 
	libvips/conversion/Makefile 
	libvips/convolution/Makefile 
	libvips/deprecated/Makefile 
	libvips/foreign/Makefile 
	libvips/freqfilt/Makefile 
	libvips/histogram/Makefile 
	libvips/draw/Makefile 
	libvips/iofuncs/Makefile 
	libvips/morphology/Makefile 
	libvips/mosaicing/Makefile 
	libvips/create/Makefile 
	libvips/resample/Makefile 
	libvipsCC/include/Makefile 
	libvipsCC/include/vips/Makefile 
	libvipsCC/Makefile 
	cplusplus/include/Makefile 
	cplusplus/include/vips/Makefile 
	cplusplus/Makefile 
	tools/Makefile 
	tools/batch_crop 
	tools/batch_image_convert 
	tools/batch_rubber_sheet 
	tools/light_correct 
	tools/shrink_width 
	python/Makefile 
	python/packages/Makefile
	python/packages/gi/Makefile 
	python/packages/gi/overrides/Makefile 
	test/Makefile 
	test/variables.sh
	test/test-suite/Makefile
	test/test-suite/helpers/Makefile
	swig/Makefile 
	swig/vipsCC/Makefile 
	man/Makefile
	doc/Makefile
	doc/libvips-docs.xml
	po/Makefile.in
])

AC_MSG_RESULT([dnl
* build options
native win32:				$vips_os_win32
native OS X:				$vips_os_darwin
open files in binary mode: 		$vips_binary_open
enable debug:				$enable_debug
enable deprecated library components:	$enable_deprecated
enable docs with gtkdoc:		$enable_gtk_doc
gobject introspection: 			$found_introspection
enable vips7 C++ API: 			$enable_cpp7
enable vips7 Python binding:		$enable_pyvips7
enable vips8 Python overrides:		$enable_pyvips8
  (requires pygobject-3.13.0 or later)
enable radiance support: 		$with_radiance
enable analyze support: 		$with_analyze
enable PPM support: 			$with_ppm

* optional dependencies
use fftw3 for FFT: 			$with_fftw
Magick package: 			$with_magickpackage
Magick API version: 			$magick_version
load with libMagick: 			$enable_magickload
save with libMagick: 			$enable_magicksave
accelerate loops with orc: 		$with_orc
  (requires orc-0.4.11 or later)
ICC profile support with lcms: 		$with_lcms
file import with niftiio: 		$with_nifti
file import with OpenEXR: 		$with_OpenEXR
file import with OpenSlide:		$with_openslide
  (requires openslide-3.3.0 or later)
file import with matio: 		$with_matio
PDF import with PDFium 			$with_pdfium
PDF import with poppler-glib: 		$with_poppler
  (requires poppler-glib 0.16.0 or later)
SVG import with librsvg-2.0: 		$with_rsvg
  (requires librsvg-2.0 2.34.0 or later)
zlib: 					$with_zlib
file import with cfitsio: 		$with_cfitsio
file import/export with libwebp:	$with_libwebp
  (requires libwebp-0.1.3 or later)
support webp metadata:			$with_libwebpmux
  (requires libwebpmux-0.5 or later)
text rendering with pangoft2: 		$with_pangoft2
file import/export with libpng: 	$with_png
  (requires libpng-1.2.9 or later)
support 8bpp PNG quantisation:		$with_imagequant
  (requires libimagequant)
file import/export with libtiff:	$with_tiff
file import/export with giflib:		$with_giflib
file import/export with libjpeg:	$with_jpeg
image pyramid export:			$with_gsf
  (requires libgsf-1 1.14.26 or later)
use libexif to load/save JPEG metadata: $with_libexif
])

if test x"$found_introspection" = x"yes" -a "$VIPS_LIBDIR/girepository-1.0" != "$INTROSPECTION_TYPELIBDIR"; then
  case "$VIPS_LIBDIR" in
    /usr/local/Cellar/vips/*)
      ;; # ignore for homebrew
    *)
      AC_MSG_RESULT([dnl
Vips-8.0.typelib will be installed to $VIPS_LIBDIR/girepository-1.0, but 
your system repository seems to be $INTROSPECTION_TYPELIBDIR. 
You may need to add this directory to your typelib path, for example:

	export GI_TYPELIB_PATH="$VIPS_LIBDIR/girepository-1.0"
      ])
      ;;
  esac
fi

if test x"$enable_pyvips8" = x"yes"; then
  expand $pyexecdir
  VIPS_PYEXECDIR=$expanded_value
  case "$VIPS_PYEXECDIR" in
    /usr/local/Cellar/vips/*)
      ;; # ingnore for homebrew
    *)
      syspygipath=`$PYTHON -c "
import sys
sys.path.append('$VIPS_PYEXECDIR')
try: import gi; print(gi._overridesdir)
except: pass"`
      if test x"$syspygipath" = x""; then
        AC_MSG_RESULT([dnl
Your python gi module could not be loaded.

You should change your PYTHONPATH environment
variable to include the pygobject3 gi module
and re-run configure to check if the Vips.py
overrides are installed in the correct location.
        ])
      elif test x"$VIPS_PYEXECDIR/gi/overrides" != x"$syspygipath"; then
        AC_MSG_RESULT([dnl
The vips Python overrides file will be installed to 
$VIPS_PYEXECDIR/gi/overrides/Vips.py, but your
system gi overrides seem to be $syspygipath.
You may need to copy this file, for example:

	cp $VIPS_PYEXECDIR/gi/overrides/Vips.* $syspygipath
        ])
      fi
      ;;
  esac
fi

if test x"$vips_os_win32" = x"yes"; then
  if test x"$have_g_win32_get_command_line" != x"yes"; then
    AC_MSG_RESULT([dnl
Your glib is too old, vips will not support unicode command-line arguments.
    ])
  fi
fi