summaryrefslogtreecommitdiff
path: root/gs/base/configure.ac
blob: 19c37d6b0d51ad2e7def099aa73a9975d206181e (plain)
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
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
dnl  Copyright (C) 2001-2007 Artifex Software, Inc.
dnl  All Rights Reserved.

dnl  This software is provided AS-IS with no warranty, either express or
dnl  implied.

dnl  This software is distributed under license and may not be copied, modified
dnl  or distributed except as expressly authorized under the terms of that
dnl  license.  Refer to licensing information at http://www.artifex.com/
dnl  or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
dnl  San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.

dnl $Id$

dnl Process this file with autoconf to produce a configure script

dnl ------------------------------------------------
dnl Initialization and Versioning
dnl ------------------------------------------------

AC_INIT
AC_PREREQ(2.52)
AC_CONFIG_SRCDIR(psi/gs.c)

dnl Inherit compiler flags from the environment...
CFLAGS="${CFLAGS:=}"
CPPFLAGS="${CPPFLAGS:=}"
CXXFLAGS="${CXXFLAGS:=}"
LDFLAGS="${LDFLAGS:=}"

dnl --------------------------------------------------
dnl Local utilities
dnl --------------------------------------------------

dnl GS_SPLIT_LIBS( LIBS, LINKLINE )
dnl Split a unix-style link line into a list of 
dnl bare library names. For example, the line
dnl '-L/usr/X11R6/lib -lX11 -lXt' splits into
dnl LIB='X11 Xt'
dnl
AC_DEFUN([GS_SPLIT_LIBS], [
# the makefile wants a list of just the library names 
for gs_item in $2; do
  gs_stripped_item=`echo "$gs_item" | sed -e 's/^-l//'`
  if test "x$gs_stripped_item" != "x$gs_item"; then
    $1="$[$1] $gs_stripped_item"
  fi
done
])

dnl GS_SPLIT_LIBPATHS( LIBPATHS, LINKLINE )
dnl Split a unix-style link line into a list of
dnl bare search path entries. For example,
dnl '-L/usr/X11R6/lib -lX11 -L/opt/lib -lXt'
dnl splits to LIBPATHS='/usr/X11R6/lib /opt/lib'
dnl
AC_DEFUN([GS_SPLIT_LIBPATHS], [
for gs_item in $2; do
  gs_stripped_item=`echo "$gs_item" | sed -e 's/-L//'`
  if test "x$gs_stripped_item" != "x$gs_item"; then
    $1="$[$1] $gs_stripped_item"
  fi
done
])

dnl --------------------------------------------------  
dnl Check for programs
dnl --------------------------------------------------  

dnl AC_PROG_CC likes to add '-g -O2' to CFLAGS. however,
dnl we ignore those flags and construct our own.
save_cflags=$CFLAGS
AC_PROG_CC
AC_PROG_CPP
CFLAGS=$save_cflags

AC_PROG_SED
dnl See if it is GNU sed or else.
dnl - need more work to tell SED features.
SED_EXTENDED_REGEX_OPT=-nre
sed_variant=`sed --version 2>&1`
sed_variant=`echo $sed_variant|sed -e 's/ .*//'`
if test "$sed_variant" != GNU ; then
SED_EXTENDED_REGEX_OPT=-nEe
fi
AC_SUBST(SED_EXTENDED_REGEX_OPT)

AC_PROG_RANLIB
#AC_PROG_INSTALL

dnl pkg-config is used for several tests now...
AC_PATH_PROG(PKGCONFIG, pkg-config)

dnl --------------------------------------------------  
dnl Allow excluding the contributed drivers
dnl --------------------------------------------------  

AC_ARG_ENABLE([contrib], AC_HELP_STRING([--disable-contrib],
    [Do not include contributed drivers]))
CONTRIBINCLUDE="include contrib/contrib.mak"
INSTALL_CONTRIB="install-contrib-extras"
if test x$enable_contrib = xno; then
    CONTRIBINCLUDE=""
    INSTALL_CONTRIB=""
    CFLAGS="$CFLAGS -DNOCONTRIB"
fi
AC_SUBST(CONTRIBINCLUDE)
AC_SUBST(INSTALL_CONTRIB)

dnl --------------------------------------------------
dnl Set build flags based on environment
dnl --------------------------------------------------

#AC_CANONICAL_HOST

CC_OPT_FLAGS_TO_TRY="-O"
SET_DT_SONAME="-soname="

case `uname` in
	Linux*|GNU*)
        if test $ac_cv_prog_gcc = yes; then
            CC_OPT_FLAGS_TO_TRY="-O2"
            CC_DBG_FLAGS_TO_TRY="-g -O0"
        fi
	;;
	*BSD)
        if test $ac_cv_prog_gcc = yes; then
	    CC_OPT_FLAGS_TO_TRY="-O2"
            CC_DBG_FLAGS_TO_TRY="-g -O0"
	fi
	;;
	Darwin*)
        if test $ac_cv_prog_gcc = yes; then
	    CC_OPT_FLAGS_TO_TRY="-O2"
            CC_DBG_FLAGS_TO_TRY="-g -O0"
	fi
	;;
	SunOS)
	CC_OPT_FLAGS_TO_TRY="-O2"
	# the trailing space is required!
        if test $ac_cv_prog_gcc = no; then
	    SET_DT_SONAME="-h "
	fi
        CC_DBG_FLAGS_TO_TRY="-g -O0"
	;;
esac

AC_SUBST(SET_DT_SONAME)


if test $ac_cv_prog_gcc = yes; then
    cflags_to_try="-Wall -Wstrict-prototypes -Wundef \
-Wmissing-declarations -Wmissing-prototypes -Wwrite-strings \
-Wno-strict-aliasing -Wdeclaration-after-statement \
-fno-builtin -fno-common"
    optflags_to_try="$CC_OPT_FLAGS_TO_TRY"
    dbgflags_to_try="$CC_DBG_FLAGS_TO_TRY"
else
    cflags_to_try=
    optflags_to_try="$CC_OPT_FLAGS_TO_TRY"
    dbgflags_to_try="$CC_DBG_FLAGS_TO_TRY"
fi

# debug configurarion is available by default with "make debug"
#AC_ARG_ENABLE([debug], AC_HELP_STRING([--enable-debug],
#    [turn on debugging]))
#if test x$enable_debug = xyes; then
#    optflags_to_try="-g"
#    CFLAGS="-DDEBUG $CFLAGS"
#fi

AC_MSG_CHECKING([supported compiler flags])
old_cflags=$CFLAGS
echo
for flag in $optflags_to_try; do
    CFLAGS="$CFLAGS $flag"
    AC_TRY_COMPILE(, [return 0;], [
	echo "   $flag"
	OPT_CFLAGS="$OPT_CFLAGS $flag"
    ])
    CFLAGS=$old_cflags
done
for flag in $cflags_to_try; do
	CFLAGS="$CFLAGS $flag"
	AC_TRY_COMPILE(, [return 0;], [
		echo "   $flag"
		GCFLAGS="$GCFLAGS $flag"
	])
	CFLAGS=$old_cflags
done
old_cflags=$CFLAGS
echo
for flag in $dbgflags_to_try; do
    CFLAGS="$CFLAGS $flag"
    AC_TRY_COMPILE(, [return 0;], [
	echo "   $flag"
	DBG_CFLAGS="$DBG_CFLAGS $flag"
    ])
    CFLAGS=$old_cflags
done

AC_MSG_RESULT([ ...done.])

dnl --------------------------------------------------
dnl Check for headers
dnl --------------------------------------------------

AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([errno.h fcntl.h limits.h malloc.h memory.h stdlib.h string.h strings.h sys/ioctl.h sys/param.h sys/time.h syslog.h unistd.h])

dnl --------------------------------------------------
dnl Check for *BSD and apply BSD Make workaround
dnl - BSD Make treats obj special and cd into it first.
dnl --------------------------------------------------

OBJDIR_BSDMAKE_WORKAROUND=obj

case `uname` in
	*BSD)
	OBJDIR_BSDMAKEWORKAOROUND="notobj"
	;;
esac
AC_SUBST(OBJDIR_BSDMAKE_WORKAROUND)

# for gdev3b1.c (AT&T terminal interface)
AC_CHECK_HEADER([sys/window.h])

dnl --------------------------------------------------
dnl Check for typedefs, structures, etc
dnl --------------------------------------------------

AC_C_CONST
AC_C_INLINE
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_STRUCT_ST_BLOCKS
AC_HEADER_TIME
AC_STRUCT_TM

dnl see if we're on a system that puts the *int*_t types 
dnl from stdint.h in sys/types.h
if test "x$ac_cv_header_stdint_h" != xyes; then
    AC_CHECK_TYPES([int8_t, int16_t, int32_t, uint8_t, uint16_t, uint32_t],,,[#include <sys/types.h>])
    if test "$ac_cv_type_uint8_t" = yes; then
        AC_DEFINE([SYS_TYPES_HAS_STDINT_TYPES])
	GCFLAGS="$GCFLAGS -DSYS_TYPES_HAS_STDINT_TYPES"
    fi
fi

dnl we aren't interested in all of DEFS, so manually insert
dnl the flags we care about
if test "$ac_cv_c_const" != yes; then
	GCFLAGS="$GCFLAGS -Dconst="
fi
if test "x$ac_cv_header_stdint_h" = xyes; then
	GCFLAGS="$GCFLAGS -DHAVE_STDINT_H"
fi

dnl try to find a 64 bit type for devicen color index
uint64_type="none"
 AC_CHECK_SIZEOF(unsigned long int)
 if test $ac_cv_sizeof_unsigned_long_int = 8; then
	uint64_type="unsigned long int"
 else
  AC_CHECK_SIZEOF(unsigned long long)
  if test $ac_cv_sizeof_unsigned_long_long = 8; then
	uint64_type="unsigned long long"
  else
   AC_CHECK_SIZEOF(unsigned __int64)
   if test $ac_cv_sizeof_unsigned___int64 = 8; then
	uint64_type="unsigned __int64"
   else
    AC_CHECK_SIZEOF(u_int64_t)
    if test $ac_cv_sizeof_u_int64_t = 8; then
	uint64_type="u_int64_t"
    fi
   fi
  fi
 fi
dnl we don't need to do anything if a 64-bit type wasn't found
dnl the code falls back to a (probably 32-bit) default
if test "$uint64_type" != "none"; then
	GCFLAGS="$GCFLAGS -DGX_COLOR_INDEX_TYPE=\"$uint64_type\""
fi

dnl --------------------------------------------------
dnl Set options that we want to pass into all other
dnl configure scripts we might call
dnl --------------------------------------------------

SUBCONFIG_OPTS=""

if test x$build_alias != x; then
SUBCONFIG_OPTS="$SUBCONFIG_OPTS --build=$build_alias"
fi


dnl --------------------------------------------------
dnl Check for libraries
dnl --------------------------------------------------

AC_CHECK_LIB(m, cos)

SYNC="nosync"
PTHREAD_LIBS=""
AC_CHECK_LIB(pthread, pthread_create, [
  SYNC=posync;
  PTHREAD_LIBS="-lpthread"
])
AC_SUBST(SYNC)
AC_SUBST(PTHREAD_LIBS)

dnl Tests for iconv (Needed for OpenPrinting Vector, "opvp" output device)
AC_ARG_WITH(libiconv,
            [AC_HELP_STRING([--with-libiconv=@<:@no/gnu/native@:>@],
                            [use the libiconv library])],,
	    [with_libiconv=maybe])
found_iconv=no
case $with_libiconv in
  maybe)
    # Check in the C library first
    AC_CHECK_FUNC(iconv_open, [with_libiconv=no; found_iconv=yes])
    # Check if we have GNU libiconv
    if test $found_iconv = "no"; then
      AC_CHECK_LIB(iconv, libiconv_open, [with_libiconv=gnu; found_iconv=yes])
    fi
    # Check if we have a iconv in -liconv, possibly from vendor
    if test $found_iconv = "no"; then
      AC_CHECK_LIB(iconv, iconv_open, [with_libiconv=native; found_iconv=yes])
    fi
    ;;
  no)
    found_iconv=no
    ;;
  gnu|yes)
    AC_CHECK_LIB(iconv, libiconv_open, [with_libiconv=gnu; found_iconv=yes])
    ;;
  native)
    AC_CHECK_LIB(iconv, iconv_open, [with_libiconv=native; found_iconv=yes])
    ;;
esac
if test x$found_iconv != xno -a x$with_libiconv != xno ; then
  LIBS="$LIBS -liconv"
fi

case $with_libiconv in
  gnu)
    AC_DEFINE(USE_LIBICONV_GNU, 1, [Using GNU libiconv])
    CFLAGS="$CFLAGS -DUSE_LIBICONV_GNU"
    ;;
  native)
    AC_DEFINE(USE_LIBICONV_NATIVE, 1, [Using a native implementation of iconv in a separate library])
    ;;
esac

dnl Check for libidn (needed for Unicode password support)
AC_ARG_WITH(libidn,
	    [AC_HELP_STRING([--without-libidn],
		   	    [don't use libidn to support Unicode passwords])],,
	    [with_libidn=maybe])
if test x$with_libidn != xno; then
  AC_CHECK_LIB(idn, stringprep, [
    with_libidn=no
    AC_CHECK_HEADER([stringprep.h], [with_libidn=yes])
    ], [
    if test x$with_libidn != xmaybe; then
      AC_MSG_ERROR([libidn not found])
    fi
    with_libidn=no
  ])
fi
HAVE_LIBIDN=''
UTF8DEVS=''
if test x$with_libidn != xno; then
  HAVE_LIBIDN=-DHAVE_LIBIDN
  LIBS="$LIBS -lidn"

  if test x$found_iconv != xno; then
    UTF8DEVS='$(PSD)utf8.dev'
  fi
fi
AC_SUBST(HAVE_LIBIDN)
AC_SUBST(UTF8DEVS)

dnl Tests for libpaper (to determine system default paper size)
AC_ARG_WITH([libpaper],
            AC_HELP_STRING([--without-libpaper],
                           [disable libpaper support]))
if test x$with_libpaper != xno; then
    AC_CHECK_LIB(paper, systempapername, [with_libpaper=yes],
    [
	AC_MSG_WARN([disabling support for libpaper])
        with_libpaper=no
    ])
fi
if test x$with_libpaper != xno; then
    AC_CHECK_HEADER([paper.h], [with_libpaper=yes],
    [
        AC_MSG_WARN([disabling support for libpaper])
        with_libpaper=no
    ])
fi

if test x$with_libpaper != xno; then
    LIBS="$LIBS -lpaper"
    AC_DEFINE(USE_LIBPAPER, 1, [Using libpaper])
    CFLAGS="$CFLAGS -DUSE_LIBPAPER"
fi

dnl Fontconfig support
HAVE_FONTCONFIG=""
FONTCONFIG_CFLAGS=""
FONTCONFIG_LIBS=""
AC_ARG_ENABLE([fontconfig], AC_HELP_STRING([--disable-fontconfig],
    [Don't use fontconfig to list system fonts]))
if test "$enable_fontconfig" != "no"; then
	# We MUST NOT use PKG_CHECK_MODULES since it is a) not a standard
	# autoconf macro and b) requires pkg-config on the system, which is
	# NOT standard on ANY OS, including Linux!
	if test "x$PKGCONFIG" != x; then
		AC_MSG_CHECKING(for fontconfig with pkg-config)
		if $PKGCONFIG --exists fontconfig; then
			AC_MSG_RESULT(yes)
			FONTCONFIG_CFLAGS="$CFLAGS `$PKGCONFIG --cflags fontconfig`"
			FONTCONFIG_LIBS="`$PKGCONFIG --libs fontconfig`"
			HAVE_FONTCONFIG=-DHAVE_FONTCONFIG
		else
			AC_MSG_RESULT(no)
		fi
	fi
	if test -z "$HAVE_FONTCONFIG"; then
		AC_CHECK_LIB([fontconfig], [FcInitLoadConfigAndFonts], [
		  AC_CHECK_HEADER([fontconfig/fontconfig.h], [
		    FONTCONFIG_LIBS="-lfontconfig"
		    HAVE_FONTCONFIG="-DHAVE_FONTCONFIG"
		  ])
		])
	fi
fi
AC_SUBST(HAVE_FONTCONFIG)
AC_SUBST(FONTCONFIG_CFLAGS)
AC_SUBST(FONTCONFIG_LIBS)

dnl DBus support
HAVE_DBUS=""
DBUS_CFLAGS=""
DBUS_LIBS=""
AC_ARG_ENABLE([dbus], AC_HELP_STRING([--disable-dbus],
    [Do not use dbus to communicate with external services]))
if test "$enable_dbus" != "no"; then
	if test "x$PKGCONFIG" != x; then
		AC_MSG_CHECKING(for dbus with pkg-config)
		if $PKGCONFIG --exists dbus-1; then
			AC_MSG_RESULT(yes)
			DBUS_CFLAGS="$CFLAGS `$PKGCONFIG --cflags dbus-1`"
			DBUS_LIBS="`$PKGCONFIG --libs dbus-1`"
			HAVE_DBUS=-DHAVE_DBUS
		else
			AC_MSG_RESULT(no)
		fi
	fi
	if test -z "$HAVE_DBUS"; then
		AC_CHECK_LIB([dbus], [dbus_message_iter_get_basic], [
		  AC_CHECK_HEADER([dbus-1.0/dbus/dbus.h], [
		    DBUS_LIBS="-ldbus-1 -lpthread -lrt"
		    HAVE_DBUS="-DHAVE_DBUS"
		  ])
		])
	fi
fi
AC_SUBST(HAVE_DBUS)
AC_SUBST(DBUS_CFLAGS)
AC_SUBST(DBUS_LIBS)

AC_CHECK_LIB(dl, dlopen)

AC_ARG_ENABLE([freetype], AC_HELP_STRING([--disable-freetype],
	[Disable freetype for font rasterization]))
FT_BRIDGE=0
SHARE_FT=0
FTSRCDIR=
FT_CFLAGS=
FT_LIBS=

dnl UFST detection
AC_ARG_WITH([ufst], AC_HELP_STRING([--with-ufst=UFST_ROOT_DIR],
                                   [Use UFST]),
            [], [with_ufst=no])
INSERT_UFST_BRIDGE_EQUAL_ONE=
UFST_ROOT=
UFST_CFLAGS=
UFST_LIB_EXT=
if test -d $with_ufst; then
INSERT_UFST_BRIDGE_EQUAL_ONE="UFST_BRIDGE=1"
UFST_ROOT=$with_ufst
UFST_CFLAGS=-DGCCx86
UFST_LIB_EXT=.a
fi
AC_SUBST(INSERT_UFST_BRIDGE_EQUAL_ONE)
AC_SUBST(UFST_ROOT)
AC_SUBST(UFST_CFLAGS)
AC_SUBST(UFST_LIB_EXT)

if test x"$enable_freetype" != xno; then
  AC_MSG_CHECKING([for local freetype library source])
  dnl We prefer freetype2 over freetype, so it is easy to override
  dnl the included freetype source with a checkout from upstream.
  for dir in freetype2 freetype; do
    if test -f $dir/src/base/ftbbox.c; then
	AC_MSG_RESULT(yes)
	SHARE_FT=0
	FTSRCDIR="$dir"
	FT_CFLAGS="-I$dir/include"
	FT_BRIDGE=1
	break;
    fi
  done
  if test -z $FTSRCDIR; then
    AC_MSG_RESULT([no])
    if test "x$PKGCONFIG" != x; then
	AC_MSG_CHECKING(for system freetype with pkg-config)
	    if $PKGCONFIG --exists freetype2; then
		AC_MSG_RESULT(yes)
		FT_CFLAGS="$CFLAGS `$PKGCONFIG --cflags freetype2`"
		FT_LIBS="`$PKGCONFIG --libs freetype2`"
		FT_BRIDGE=1
		SHARE_FT=1
	    else
		AC_MSG_RESULT(no)
		AC_MSG_WARN([freetype library source not found...using native rasterizer])
	    fi
    fi
  fi
fi
AC_SUBST(FT_BRIDGE)
AC_SUBST(SHARE_FT)
AC_SUBST(FTSRCDIR)
AC_SUBST(FT_CFLAGS)
AC_SUBST(FT_LIBS)
  
AC_MSG_CHECKING([for local jpeg library source])
dnl At present, we give the local source priority over the shared
dnl build, so that the D_MAX_BLOCKS_IN_MCU patch will be applied.
dnl A more sophisticated approach would be to test the shared lib
dnl to see whether it has already been patched.
LIBJPEGDIR=src
if test -f jpeg/jpeglib.h; then
	AC_MSG_RESULT([jpeg])
	SHARE_LIBJPEG=0
	LIBJPEGDIR=jpeg
elif test -f jpeg-6b/jpeglib.h; then
	AC_MSG_RESULT([jpeg-6b])
	SHARE_LIBJPEG=0
	LIBJPEGDIR=jpeg-6b
else
	AC_MSG_RESULT([no])
	AC_CHECK_LIB(jpeg, jpeg_set_defaults, [
	  AC_CHECK_HEADERS([jpeglib.h], [SHARE_LIBJPEG=1])
	])
fi
if test -z "$SHARE_LIBJPEG"; then
  AC_MSG_ERROR([I wasn't able to find a copy
  of the jpeg library. This is required for compiling
  ghostscript. Please download a copy of the source,
  e.g. from http://www.ijg.org/, unpack it at the
  top level of the gs source tree, and rename
  the directory to 'jpeg'.
  ])
fi
AC_SUBST(SHARE_LIBJPEG)
AC_SUBST(LIBJPEGDIR)
dnl check for the internal jpeg memory header
AC_MSG_CHECKING([for jmemsys.h])
if test -r $LIBJPEGDIR/jmemsys.h; then
  AC_MSG_RESULT([yes])
else
  AC_MSG_RESULT([no])
  AC_DEFINE([DONT_HAVE_JMEMSYS_H], 1, 
    [define if the libjpeg memory system prototypes aren't available])
fi

AC_MSG_CHECKING([for local zlib source])
dnl zlib is needed for language level 3, and libpng
# we must define ZLIBDIR regardless because png.mak does a -I$(ZLIBDIR)
# this seems a harmless default
ZLIBDIR=src
if test -d zlib; then
	AC_MSG_RESULT([yes])
	SHARE_ZLIB=0
	ZLIBDIR=zlib
else
	AC_MSG_RESULT([no])
	AC_CHECK_LIB(z, deflate, [
	  AC_CHECK_HEADERS(zlib.h, [SHARE_ZLIB=1])
	])
fi
if test -z "$SHARE_ZLIB"; then
  AC_MSG_ERROR([I did not find a copy of zlib on your system.
  Please either install it, or unpack a copy of the source in a
  local directory named 'zlib'. See http://www.gzip.org/zlib/
  for more information.
  ])
fi

dnl if GS is to use the system zlib, freetype
dnl should do the same
FT_SYS_ZLIB=""
if test x$FT_BRIDGE != x0; then
  if test xx$SHARE_FT != x1; then
    if test x$SHARE_ZLIB != x0; then
      FT_SYS_ZLIB="-DFT_CONFIG_OPTION_SYSTEM_ZLIB"
    fi
  fi
fi

AC_SUBST(SHARE_ZLIB)
AC_SUBST(ZLIBDIR)
AC_SUBST(FT_SYS_ZLIB)

dnl png for the png output device; it also requires zlib
LIBPNGDIR=src
PNGDEVS=''
PNGDEVS_ALL='png48 png16m pnggray pngmono png256 png16 pngalpha'
AC_MSG_CHECKING([for local png library source])
if test -f libpng/pngread.c; then
	AC_MSG_RESULT([yes])
	SHARE_LIBPNG=0
	LIBPNGDIR=libpng
	PNGDEVS="$PNGDEVS_ALL"
else
	AC_MSG_RESULT([no])
	AC_CHECK_LIB(png, png_create_write_struct, [
	  AC_CHECK_HEADERS(png.h, [
		SHARE_LIBPNG=1
		PNGDEVS="$PNGDEVS_ALL"
	  ], [SHARE_LIBPNG=0])
	], [SHARE_LIBPNG=0], [-lz])
fi
if test -z "$PNGDEVS"; then
  AC_MSG_NOTICE([disabling png output devices])
fi
AC_SUBST(SHARE_LIBPNG)
AC_SUBST(LIBPNGDIR)
#AC_SUBST(PNGDEVS)

AC_MSG_CHECKING([for local lcms library source])
LCMSDIR=lcms
SHARELCMS=0
if test -f $LCMSDIR/include/lcms.h; then
	AC_MSG_RESULT([yes])
else
AC_CHECK_LIB(lcms, cmsCreateXYZProfile, [
	  AC_CHECK_HEADERS([lcms.h], [SHARELCMS=1;LCMSDIR=""])
	])
fi

AC_MSG_CHECKING([for local lcms2 library source])
LCMS2DIR=lcms2
if test -f $LCMS2DIR/include/lcms2.h; then
	AC_MSG_RESULT([yes])
else
AC_CHECK_LIB(lcms2, cmsCreateXYZProfile, [
	  AC_CHECK_HEADERS([lcms2.h], [LCMS2DIR=""])
	])
fi

AC_SUBST(SHARELCMS)
AC_SUBST(LCMSDIR)
AC_SUBST(LCMS2DIR)

dnl look for libtiff, it also requires lib
dnl png for the png output device; it also requires zlib
AC_ARG_WITH([system-libtiff], AC_HELP_STRING([--with-system-libtiff],
					     [Force using the systems libtiff]),
	    [], [with_system_libtiff=check])
TIFFDEVS=''
TIFFDEVS_ALL='$(DD)tiffs $(DD)tiff12nc $(DD)tiff24nc $(DD)tiff48nc $(DD)tiff32nc $(DD)tiff64nc $(DD)tiffcrle $(DD)tifflzw $(DD)tiffpack $(DD)tiffgray $(DD)tiffsep $(DD)tiffscaled'
case "x$with_system_libtiff" in
    xcheck)
	if test -d tiff; then
	    LIBTIFFDIR=tiff
	    HAVE_LOCAL_LIBTIFF=1
	    SHARE_LIBTIFF=0
	else
	    AC_CHECK_LIB(tiff, TIFFOpen,
		     [AC_CHECK_HEADERS(tiff.h, [HAVE_SYSTEM_LIBTIFF=1;SHARE_LIBTIFF=1])],
		     [], [-ljpeg])
	fi
	if test "x$HAVE_LOCAL_LIBTIFF" = x && test "x$HAVE_SYSTEM_LIBTIFF" = x; then
	    AC_MSG_NOTICE([Could not find a copy of libtiff on your system.
Disabling tiff output devices.])
	else
	    TIFFDEVS="$TIFFDEVS_ALL"
	fi
	;;
    xyes)
	AC_CHECK_LIB(tiff, TIFFOpen,
		     [AC_CHECK_HEADERS(tiff.h, [HAVE_SYSTEM_LIBTIFF=1;SHARE_LIBTIFF=1])],
		     [], [-ljpeg])
	if test "x$HAVE_SYSTEM_LIBTIFF" != x; then
	    SHARE_LIBTIFF=1
	    TIFFDEVS="$TIFFDEVS_ALL"
	else
	    AC_MSG_NOTICE([Could not find a copy of libtiff on your system.
Disabling tiff output devices.])
	fi
	;;
    xno)
	AC_MSG_CHECKING([for local libtiff source])
        if test -d tiff; then
	    AC_MSG_RESULT([yes])
	    LIBTIFFDIR=tiff
	    SHARE_LIBTIFF=0
	    TIFFDEVS="$TIFFDEVS_ALL"
	else
	    AC_MSG_RESULT([no])
	    AC_MSG_NOTICE([Could not find local copy of libtiff.
Disabling tiff output devices.])
	fi
	;;
esac

if test $SHARE_LIBTIFF -eq 0; then
      echo
      echo "Running libtiff configure script..."
      olddir=`pwd`
      cd $LIBTIFFDIR && ./configure --disable-jbig $SUBCONFIG_OPTS
      status=$?
      if test "$status" -ne 0 ; then
        AC_MSG_ERROR([libtiff configure script failed], $status)
      fi
      cd $olddir
      echo
      echo "Continuing with Ghostscript configuration..."
fi

AC_SUBST(SHARE_LIBTIFF)
AC_SUBST(TIFFDEVS)
AC_SUBST(LIBTIFFDIR)


dnl look for CUPS...
AC_ARG_ENABLE([cups], AC_HELP_STRING([--disable-cups],
    [Don't include CUPS support]))

AC_ARG_WITH([pdftoraster], AC_HELP_STRING([--without-pdftoraster],
    [Don't include CUPS' pdftoraster filter]))

AC_ARG_WITH([local-cups], AC_HELP_STRING([--with-local-cups],
					     [Force using the GS supplied cups code - only useful for debugging]),
	    [with_local_cups=yes], [with_local_cups=no])

AC_ARG_WITH([install-cups], AC_HELP_STRING([--with-install-cups],
					     [Install the cups conversion tools]),
	    [CUPSINSTALL=install-cups], [CUPSINSTALL=])

CUPSDEV=""
CUPSINCLUDE=""
CUPSCFLAGS=""
CUPSLIBS=""
CUPSLIBDIRS=""
CUPSCONFIG="${CUPSCONFIG:=}"
CUPSSERVERBIN=""
CUPSSERVERROOT=""
CUPSDATA=""
CUPSVERSION="0"
CUPSPDFTORASTER="0"

SHARELCUPS=1
SHARELCUPSI=1

if ( test -d cups ); then
    if test x$enable_cups != xno; then
        if test x$with_local_cups != xyes; then
	    AC_PATH_PROG(CUPSCONFIG,cups-config)
	    AC_CHECK_HEADER([cups/raster.h],[],[CUPSCONFIG=""])
	    if test "x$CUPSCONFIG" != x; then
	        dnl Use values from CUPS config...
	        CUPSCFLAGS="`$CUPSCONFIG --cflags` $CFLAGS"
#	        CUPSLINK="`$CUPSCONFIG --ldflags` `$CUPSCONFIG --static --image --libs | sed -e '1,$s/-lssl//'` $LIBS"
	        CUPSLINK="`$CUPSCONFIG --ldflags` `$CUPSCONFIG --image --libs`"
	        GS_SPLIT_LIBS([CUPSLIBS], [$CUPSLINK])
	        GS_SPLIT_LIBPATHS([CUPSLIBDIRS],[$CUPSLINK])
	        CUPSSERVERROOT="`$CUPSCONFIG --serverroot`"
	        CUPSSERVERBIN="`$CUPSCONFIG --serverbin`"
	        CUPSDATA="`$CUPSCONFIG --datadir`"
	        CUPSINCLUDE="include cups/cups.mak"
	        CUPSDEV="cups"
	        CUPSVERSION="`$CUPSCONFIG --version`"
	        LCUPSINCLUDE="include \$(GLSRCDIR)/lcups.mak"
	        LCUPSIINCLUDE="include \$(GLSRCDIR)/lcupsi.mak"
	        if ( test x$with_pdftoraster != xno ); then
	            if test "$CUPSVERSION" ">" "1.2"; then
	                CUPSPDFTORASTER="1"
	            fi
	        fi
	    fi
        else
            if test "$(uname)" = "Linux"; then
                AC_MSG_WARN([* USING LOCAL CUPS SOURCE *])
                SHARELCUPS=0
                SHARELCUPSI=0
                LCUPSBUILDTYPE=linux
	        LCUPSINCLUDE="include \$(GLSRCDIR)/lcups.mak"
	        LCUPSIINCLUDE="include \$(GLSRCDIR)/lcupsi.mak"
	        CUPSDEV="cups"
                
            fi
        fi
    fi
fi

#AC_SUBST(CUPSDEV)
AC_SUBST(CUPSCFLAGS)
AC_SUBST(CUPSLIBS)
AC_SUBST(CUPSLIBDIRS)
AC_SUBST(CUPSINCLUDE)
AC_SUBST(CUPSSERVERBIN)
AC_SUBST(CUPSSERVERROOT)
AC_SUBST(CUPSDATA)
AC_SUBST(CUPSINSTALL)

AC_SUBST(SHARELCUPS)
AC_SUBST(SHARELCUPSI)
AC_SUBST(LCUPSBUILDTYPE)
AC_SUBST(LCUPSINCLUDE)
AC_SUBST(LCUPSIINCLUDE)


AC_SUBST(CUPSPDFTORASTER)

dnl look for IJS implementation
AC_ARG_WITH([ijs], AC_HELP_STRING([--without-ijs],
    [disable IJS driver support]))
dnl set safe defaults
    IJSDIR=src
    IJSDEVS=''
    SHAREIJS=0
if test x$with_ijs != xno; then
    AC_MSG_CHECKING([for local ijs library source])
    if test -d ijs; then
        AC_MSG_RESULT([yes])
        IJSDIR=ijs
        IJSDEVS='ijs'
    else
        AC_MSG_RESULT([no])
        AC_CHECK_LIB(ijs, ijs_server_init, [
	  AC_CHECK_HEADERS(ijs/ijs.h, [SHAREIJS=1])
	])
        if test $SHAREIJS -eq 1 ; then
            IJSLIB=ijs
            # This is for safety - it prevents our header search path going outside the GS source tree
            IJSDIR='$(GLOBJDIR)'
            IJSDEVS='ijs'
        fi
    fi
fi
AC_SUBST(IJSDIR)
AC_SUBST(SHAREIJS)
AC_SUBST(IJSLIB)
#AC_SUBST(IJSDEVS)


JBIG2_DECODER=
JBIG2DIR=src
SHARE_JBIG2=0
JBIG2DEVS=''
JBIG2_AUTOCONF_CFLAGS=

dnl Luratech detection
LURATECHDIR=luratech

AC_ARG_WITH([luratech], AC_HELP_STRING([--without-luratech],
    [do not try to use the Luratech library for JBIG2 nor JPX decoding]))


if test x$with_luratech != xno; then
  AC_MSG_CHECKING([for local Luratech JBIG2 library source])
  if test -d luratech/ldf_jb2; then
    AC_MSG_RESULT([yes])
    JBIG2_DECODER=luratech
    SHARE_JBIG2=0
    JBIG2DIR=luratech/ldf_jb2
    if test `uname` = Darwin*; then
      JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -DMAC -DMAC_OS_X_BUILD"
    else
      JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -DLINUX"
    fi
    JBIG2DEVS='$(PSD)jbig2.dev'
  else
    AC_MSG_RESULT([no])
  fi
fi

if test "x$JBIG2_DECODER" = x; then
  dnl look for jbig2dec
  AC_ARG_WITH([jbig2dec], AC_HELP_STRING([--without-jbig2dec],
      [disable JBIG2 decode support]))
  if test x$with_jbig2dec != xno; then
    AC_MSG_CHECKING([for local jbig2dec library source])
    for d in jbig2dec jbig2dec-0.2 jbig2dec-0.3; do
      test -d "$d" && JBIG2DIR=$d && break
    done
    if test "x$JBIG2DIR" != xsrc; then
        JBIG2_DECODER=jbig2dec
        echo "Running jbig2dec configure script..."
        olddir=`pwd`
        cd $JBIG2DIR && ./configure $SUBCONFIG_OPTS
        status=$?
        if test "$status" -ne 0 ; then
          AC_MSG_ERROR([jbig2dec configure script failed], $status)
        fi
        if test "$status" -eq 0 ; then
          JBIG2_AUTOCONF_CFLAGS=-DHAVE_CONFIG_H
        fi
        cd $olddir
        echo
        echo "Continuing with Ghostscript configuration..."
        AC_MSG_RESULT([$JBIG2DIR])
    else
      AC_MSG_RESULT([no])
      AC_CHECK_LIB([jbig2dec], [jbig2_page_out], [
          SHARE_JBIG2=1
      ], [
          AC_MSG_WARN([disabling support for JBIG2 files])
          with_jbig2dec=no
    ])
      if test x$with_jbig2dec != xno; then
        JBIG2_DECODER=jbig2dec
      fi
    fi
  fi
  if test x$with_jbig2dec != xno; then
    if test x$ac_cv_header_stdint_h != xyes && test x$ac_cv_header_inttypes_h != xyes; then
      AC_MSG_WARN([JBIG2 support requires stdint types which do not seem to be available.])
    else
      JBIG2DEVS='$(PSD)jbig2.dev'
    fi
  fi
fi

AC_SUBST(JBIG2_DECODER)
AC_SUBST(JBIG2DIR)
AC_SUBST(SHARE_JBIG2)
AC_SUBST(JBIG2DEVS)
AC_SUBST(JBIG2_AUTOCONF_CFLAGS)

JPXDIR=src
SHARE_JASPER=0
JPXDEVS=''
JPX_DECODER=
JPX_AUTOCONF_CFLAGS=

if test x$with_luratech != xno; then
  AC_MSG_CHECKING([for local Luratech JPEG2K library source])
  if test -d luratech/lwf_jp2; then
    AC_MSG_RESULT([yes])
    JPX_DECODER=luratech
    SHARE_JASPER=0
    JPXDIR=luratech/lwf_jp2
    if test `uname` = Darwin*; then
      JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 -DMAC -DMAC_OS_X_BUILD"
    else
      JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 -DLINUX"
    fi
    JPXDEVS='$(PSD)jpx.dev'
  else
    AC_MSG_RESULT([no])
  fi
fi


if test "x$JPX_DECODER" = x; then
  dnl look for the jasper JPEG 2000 library
  AC_ARG_WITH([jasper], AC_HELP_STRING([--without-jasper],
    [don't use the JasPer library for JPEG 2000]))
  if test x$with_jasper != xno; then
    AC_MSG_CHECKING([for local jasper library source])
    for d in jasper jasper-1.7*; do
      test -d "$d" && JPXDIR=$d && break
    done
    if test "x$JPXDIR" != xsrc; then
      AC_MSG_RESULT([$JPXDIR])
      AC_MSG_CHECKING([for local jasper configure script])
      if test -x $JPXDIR/configure; then
        AC_MSG_RESULT([yes])
        echo
        echo "Running jasper configure script..."
        olddir=`pwd`
        cd $JPXDIR && ./configure $SUBCONFIG_OPTS
        status=$?
        if test "$status" -ne 0 ; then
          AC_MSG_ERROR([jasper configure script failed], $status)
        fi
        cd $olddir
        echo
        echo "Continuing with Ghostscript configuration..."
      else
        AC_MSG_RESULT([no])
        AC_MSG_CHECKING([for local jasper autogen.sh script])
        if test -x $JPXDIR/autogen.sh; then
          AC_MSG_RESULT([yes])
          echo
          echo "Running jasper autogen script..."
          olddir=`pwd`
          cd $JPXDIR && ./autogen.sh
          status=$?
          if test "$status" -ne 0 ; then
            AC_MSG_ERROR([jasper autogen script failed], $status)
          fi
          cd $olddir
          echo
          echo "Continuing with Ghostscript configuration..."
        else
          AC_MSG_ERROR([
Unable to find $JPXDIR/src/libjasper/include/jas_config.h,
or generate generate such a file for this system. You will
have to build one by hand, or configure, build and install
the jasper library separately.

You can also pass --without-jasper to configure to disable
JPEG 2000 PDF image support entirely.
])
        fi
      fi
    else
      AC_MSG_RESULT([no])
      AC_CHECK_LIB([jasper], [jas_image_create], [
          SHARE_JASPER=1
      ], [
          AC_MSG_WARN([disabling support for JPEG 2000 images])
          with_jasper=no
      ])
    fi
  fi
  if test x$with_jasper != xno; then
    JPX_DECODER=jasper
    JPX_AUTOCONF_CFLAGS="-DJAS_CONFIGURE"
    JPXDEVS='$(PSD)jpx.dev'
  fi
fi


AC_SUBST(JPX_DECODER)
AC_SUBST(JPX_AUTOCONF_CFLAGS)
AC_SUBST(JPXDIR)
AC_SUBST(SHARE_JASPER)
AC_SUBST(JPXDEVS)

dnl check if we can/should build the gtk loader
AC_ARG_ENABLE([gtk], AC_HELP_STRING([--disable-gtk],
    [Don't build the gtk loader]))
SOC_CFLAGS=""
SOC_LIBS=""
SOC_LOADER="dxmainc.c"
if test "x$enable_gtk" != "xno"; then
    # Try GTK+ 2.x first...
    if test "x$PKGCONFIG" != x; then
	AC_MSG_CHECKING(for GTK+ 2.x)
	if $PKGCONFIG --exists gtk+-2.0; then
	    SOC_LOADER="dxmain.c"
	    SOC_CFLAGS="`$PKGCONFIG gtk+-2.0 --cflags`"
	    SOC_LIBS="`$PKGCONFIG gtk+-2.0 --libs`"
	    AC_MSG_RESULT([yes])
	else
	    AC_MSG_RESULT([no])
	fi
    fi

    # Then fall back on GTK+ 1.x...
    if test "x$SOC_LOADER" = x; then
	AC_PATH_PROG(GTKCONFIG, gtk-config)
	if test "x$GTKCONFIG" != x; then
	    SOC_LOADER="dxmain.c"
	    SOC_CFLAGS="`$GTKCONFIG --cflags`"
	    SOC_LIBS="`$GTKCONFIG --libs`"
	fi
    fi
fi
AC_SUBST(SOC_CFLAGS)
AC_SUBST(SOC_LIBS)
AC_SUBST(SOC_LOADER)

dnl look for omni implementation
AC_ARG_WITH([omni], AC_HELP_STRING([--with-omni],
	[enable the omni driver]))
dnl set safe defaults
OMNIDEVS=''
INCLUDEOMNI=no
if ( ! test -z "$CONTRIBINCLUDE" ) && ( test x$with_omni = xyes ); then
	INCLUDEOMNI=yes
        OMNIDEVS='$(DD)omni.dev'

	if test -n "$GCC"; then
		LIBS="$LIBS -lstdc++"
	fi
fi
AC_SUBST(OMNIDEVS)

dnl optional X11 for display devices
AC_PATH_XTRA

X_LDFLAGS=""
X_CFLAGS=""
X_DEVS=""
X_LIBS=""

if test x$no_x != xyes; then
	if test "$x_libraries" = "/usr/lib"; then
		echo "Ignoring X library directory \"$x_libraries\" requested by configure."
		x_libraries="NONE"
	fi
	if test ! "$x_libraries" = "NONE" -a ! "$x_libraries" = ""; then
		X_LDFLAGS="-L$x_libraries"
		if test "$uname" = "SunOS"; then
			X_LDFLAGS="$X_LDFLAGS -R$x_libraries"
		fi
	fi

	if test "$x_includes" = "/usr/include"; then
		echo "Ignoring X include directory \"$x_includes\" requested by configure."
		x_includes="NONE"
	fi
	if test ! "$x_includes" = "NONE" -a ! "$x_includes" = ""; then
		X_CFLAGS="-I$x_includes"
	fi

	SAVELIBS="$LIBS"
	SAVELDFLAGS="$LDFLAGS"
	LDFLAGS="$LDFLAGS $X_LDFLAGS"

	AC_CHECK_LIB(X11,XOpenDisplay)
	AC_CHECK_LIB(Xext,XdbeQueryExtension)
	AC_CHECK_LIB(Xt,XtAppCreateShell)

	LDFLAGS="$SAVELDFLAGS"
	LIBS="$SAVELIBS"

	if test "$ac_cv_lib_Xt_XtAppCreateShell" = yes; then
		X11DEVS="x11 x11alpha x11cmyk x11mono x11_ x11alt_ x11cmyk2 x11cmyk4 x11cmyk8 x11rg16x x11rg32x x11gray2 x11gray4"
		X_DEVS=$X11DEVS
		# the makefile wants a list of just the library names in X_LIBS
		GS_SPLIT_LIBS([X_LIBS], 
			[-lXt $X_PRE_LIBS -lXext -lX11 $X_EXTRA_LIBS])
	fi
fi

AC_SUBST(X_LDFLAGS)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)
#AC_SUBST(X_DEVS)
#AC_SUBST(X11DEVS)
AC_SUBST(XLIBS)

dnl executible name
AC_ARG_WITH([gs], AC_HELP_STRING([--with-gs=NAME],
	[name of the Ghostscript executible [[gs]]]),
	[GS="$with_gs"],[GS='gs'])
AC_SUBST(GS)

dnl do we compile the postscript initialization files into Ghostscript?
COMPILE_INITS="1"
AC_ARG_ENABLE([compile-inits], AC_HELP_STRING([--disable-compile-inits],
       [Don't compile in initialization files]),[
               if test "x$enable_compile_inits" = xno; then
                       COMPILE_INITS="0"
               fi])
AC_SUBST(COMPILE_INITS)

dnl look for drivers to compile...
AC_ARG_WITH(drivers,
[  --with-drivers=LIST     Drivers to support, separated by commas.
                          Either list the drivers or use aliases:
                          ALL      = all drivers
                          FILES    = all file format drivers
                          PRINTERS = all printer drivers
                          Printers:
                          APPLE    = all Apple printers
                          BROTHER  = all Brother printers
                          CANON    = all Canon printers
                          EPSON    = all Epson printers
                          HP       = all HP printers
                          IBM      = all IBM printers
                          JAPAN    = older japanese printers
                          LEXMARK  = all Lexmark printers
                          OKI      = all OKI printers
			  PCLXL    = all PCL XL/6 printers
                          File formats:
                          BMP      = Output to bmp files
                          FAX      = Output to fax files
                          JPEG     = Output to JPEG files
                          PBM      = Output to PBM/PNM
                          PCX      = Output to PCX
			  PNG      = Output to PNG
                          PS       = Output to PostScript/PDF
                          TIFF     = Output to TIFF
			  WTS      = WTS Halftoning devices
			  ETS      = ETS Halftoning devices
                          You can mix both variants, e.g.
                          --with-drivers=HP,stcolor would build HP drivers and
                          the Epson stcolor driver.
                          Aliases must be uppercase (a 3rd party driver might
                          have the same name).
                          Default: ALL],drivers="$withval",drivers="ALL")

AC_ARG_WITH(driversfile,
[  --with-driversfile=FILE Drivers to support from file, separated by newlines.],
driversfile="$withval",driversfile="")

if test "x$driversfile" != x; then
	# Add drivers from file...
	drivers="`tr '\n' ',' <$driversfile`"
fi

dnl Check which drivers we'd like to support.
P_DEVS0=""
F_DEVS0=""
CUPS_DEVS0=""
SVG_DEVS0=""
JBIG2_DEVS=""
IJS_DEVS0=""
PNG_DEVS0=""
X11_DEVS0=""


dnl Known printers
HP_DEVS='cdj500 djet500 djet500c dnj650c cljet5pr deskjet laserjet ljetplus ljet2p ljet3 ljet3d ljet4 ljet4d lj4dith lj5mono lj5gray cdeskjet cdjcolor cdjmono cdj550 pj pjxl pjxl300 lp2563 paintjet pjetxl cljet5 cljet5c pxlmono pxlcolor cdj670 cdj850 cdj880 cdj890 cdj970 cdj1600 cdnj500 chp2200 pcl3 hpdjplus hpdjportable hpdj310 hpdj320 hpdj340 hpdj400 hpdj500 hpdj500c hpdj510 hpdj520 hpdj540 hpdj550c hpdj560c hpdj600 hpdj660c hpdj670c hpdj680c hpdj690c hpdj850c hpdj855c hpdj870c hpdj890c hpdj1120c lj3100sw'
PCLXL_DEVS='pxlmono pxlcolor'
EPSON_DEVS='eps9high eps9mid epson epsonc escp lp8000 lq850 photoex st800 stcolor alc1900 alc2000 alc4000 alc4100 alc8500 alc8600 alc9100 lp3000c lp8000c lp8200c lp8300c lp8500c lp8800c lp9000c lp9200c lp9500c lp9800c lps6500 epl2050 epl2050p epl2120 epl2500 epl2750 epl5800 epl5900 epl6100 epl6200 lp1800 lp1900 lp2200 lp2400 lp2500 lp7500 lp7700 lp7900 lp8100 lp8300f lp8400f lp8600 lp8600f lp8700 lp8900 lp9000b lp9100 lp9200b lp9300 lp9400 lp9600 lp9600s lps4500 eplcolor eplmono'
CANON_DEVS='bj10e bj200 bjc600 bjc800 lbp8 lips3 bjcmono bjcgray bjccmyk bjccolor'
LEXMARK_DEVS='lxm5700m lx5000 lxm3200 lex2050 lex3200 lex5700 lex7000'
BROTHER_DEVS='hl7x0 hl1240 hl1250'
APPLE_DEVS='appledmp iwhi iwlo iwlq'
IBM_DEVS='ibmpro jetp3852'
OKI_DEVS='oki182 okiibm oki4w'
JAPAN_DEVS='lips4 lips4v ljet4pjl lj4dithp dj505j picty180 lips2p bjc880j pr201 pr150 pr1000 pr1000_4 jj100 bj10v bj10vh mj700v2c mj500c mj6000c mj8000c fmpr fmlbp ml600 lbp310 lbp320 md50Mono md50Eco md1xMono escpage lp2000 npdl rpdl'
MISC_PDEVS='uniprint ap3250 atx23 atx24 atx38 coslw2p coslwxl cp50 declj250 fs600 imagen lj250 m8510 necp6 oce9050 r4081 sj48 tek4696 t4693d2 t4693d4 t4693d8 dl2100 la50 la70 la75 la75plus ln03 xes md2k md5k gdi samsunggdi'
OPVP_DEVS='opvp oprp'

ETS_HALFTONING_DEVS='rinkj'

dnl Known file formats
BMP_DEVS='bmpmono bmpgray bmpsep1 bmpsep8 bmp16 bmp256 bmp16m bmp32b'
FAX_DEVS='cfax dfaxlow dfaxhigh fax tfax tiffg3 tiffg32d tiffg4 faxg3 faxg32d faxg4'
JPEG_DEVS='jpeg jpeggray jpegcmyk'
# PNG_DEVS='png16 png16m png256 pngalpha pnggray pngmono'
TIFF_DEVS='tiffs tiff12nc tiff24nc tiff48nc tiff32nc tiff64nc tiffcrle tifflzw tiffpack tiffgray tiffsep tiffsep1 tiffscaled tiffscaled8 tiffscaled24'
PCX_DEVS='pcxmono pcxgray pcx16 pcx256 pcx24b pcxcmyk pcx2up'
PBM_DEVS='pbm pbmraw pgm pgmraw pgnm pgnmraw pnm pnmraw ppm ppmraw pkm pkmraw pksm pksmraw pam'
PS_DEVS='psdf psdcmyk psdrgb pdfwrite pswrite ps2write epswrite psgray psmono psrgb bbox'
WTS_HALFTONING_DEVS='imdi simdi wtsimdi wtscmyk'
MISC_FDEVS='ccr cgm24 cgm8 cgmmono cif inferno mag16 mag256 mgr4 mgr8 mgrgray2 mgrgray4 mgrgray8 mgrmono miff24 plan9bm sgirgb sunhmono bit bitrgb bitrgbtags bitcmyk devicen spotcmyk xcf'
SVGDEV='svgwrite'

while test -n "$drivers"; do
	if echo $drivers |grep "," >/dev/null; then
		THIS="`echo $drivers |sed -e 's/,.*//'`"
		drivers="`echo $drivers |sed -e \"s/$THIS,//\"`"
	else
		THIS=$drivers
		drivers=""
	fi
	case "$THIS" in
	ALL)
		# ALL = PRINTERS + FILES...
		if test -z "$drivers"; then
			drivers="PRINTERS,FILES,X11"
		else
			drivers="$drivers,PRINTERS,FILES,X11"
		fi
		;;
	PRINTERS)
		P_DEVS0="$P_DEVS0 $CANON_DEVS $EPSON_DEVS $HP_DEVS $LEXMARK_DEVS $BROTHER_DEVS $APPLE_DEVS $IBM_DEVS $OKI_DEVS $JAPAN_DEVS $MISC_PDEVS $ETS_HALFTONING_DEVS $OPVP_DEVS"
                IJS_DEVS0="$IJSDEVS"
		;;
	FILES)
		F_DEVS0="$F_DEVS0 $BMP_DEVS $FAX_DEVS $JPEG_DEVS $TIFF_DEVS $PCX_DEVS $PBM_DEVS $PS_DEVS $WTS_HALFTONING_DEVS $MISC_FDEVS"
		CUPS_DEVS0="$CUPSDEV"
		JBIG2_DEVS="$JBIG2DEVS"
		PNG_DEVS0="$PNGDEVS"
		;;
	APPLE)
		# All Apple printers
		P_DEVS0="$P_DEVS0 $APPLE_DEVS"
		;;
	BMP)
		# BMP file format
		F_DEVS0="$F_DEVS0 $BMP_DEVS"
		;;
	CANON)
		# All Canon printers
		P_DEVS0="$P_DEVS0 $CANON_DEVS"
		;;
	EPSON)
		# All Epson printers
		P_DEVS0="$P_DEVS0 $EPSON_DEVS"
		;;
	FAX)
		# Fax file formats
		F_DEVS0="$F_DEVS0 $FAX_DEVS"
		;;
	JPEG)
		# Jpeg file formats
		F_DEVS0="$F_DEVS0 $JPEG_DEVS"
		;;
	JBIG2)
		# JBIG file formats
		JBIG2_DEVS="$JBIG2DEVS"
		;;
	PNG)
		# PNG file formats
		PNG_DEVS0="$PNGDEVS"
		;;
	TIFF)
		# TIFF file formats
		F_DEVS0="$F_DEVS0 $TIFF_DEVS"
		;;
	PCLXL)
		# PCL XL/PCL 6 drivers
		F_DEVS0="$F_DEVS0 $PCLXL_DEVS"
		;;
	PCX)
		# PCX file formats
		F_DEVS0="$F_DEVS0 $PCX_DEVS"
		;;
	PBM)
		# PBM file formats
		F_DEVS0="$F_DEVS0 $PBM_DEVS"
		;;
	CUPS)
		# CUPS file format
		CUPS_DEVS0="$CUPSDEV"
		;;
	HP)
		# All HP printers
		P_DEVS0="$P_DEVS0 $HP_DEVS"
		;;
	LEXMARK)
		# All Lexmark printers
		P_DEVS0="$P_DEVS0 $LEXMARK_DEVS"
		;;
	BROTHER)
		# All Brother printers
		P_DEVS0="$P_DEVS0 $BROTHER_DEVS"
		;;
	OKI)
		# All OKI printers
		P_DEVS0="$P_DEVS0 $OKI_DEVS"
		;;
	IBM)
		# All IBM printers
		P_DEVS0="$P_DEVS0 $IBM_DEVS"
		;;
	IJS)
		# IJS printers
		IJS_DEVS0="$IJSDEVS"
		;;
	JAPAN)
		# All old japanese printers
		P_DEVS0="$P_DEVS0 $JAPAN_DEVS"
		;;
	PS)
		# PostScript/PDF writing
		F_DEVS0="$F_DEVS0 $PS_DEVS"
		;;
	SVG)
		# PostScript/PDF writing
		SVG_DEVS0="$SVGDEV"
		;;
	WTS)
		# WTS Halftoning devices
		F_DEVS0="$F_DEVS0 $WTS_HALFTONING_DEVS"
		;;
	ETS)
		# ETS Halftoning devices
		F_DEVS0="$F_DEVS0 $ETS_HALFTONING_DEVS"
		;;
	X11)
		# X11 display devices
		X11_DEVS0="$X_DEVS"
		;;
        opvp)
		# Open Vector Printing driver...
		if test x$ac_cv_lib_dl_dlopen != xno -a x$found_iconv != xno; then
			P_DEVS0="$P_DEVS0 $OPVP_DEVS"
		else
			AC_MSG_WARN(Unable to include opvp/oprp driver due to missing or disabled prerequisites...)
		fi
		;;
	*)
		# It's a driver name (or a user messup)
		P_DEVS0="$P_DEVS0 `echo $THIS |sed -e 's,\.dev$,,'`"
		;;
	esac
done

noncontribmakefiles=`find . -name '*.mak' -print | grep -v '^\./contrib/'`
# No need to include opvp/oprp driver without iconv/libiconv.
if test -n "$P_DEVS0"; then
    if test x$found_iconv = xno ; then
        P_DEVS0=`echo $P_DEVS0 | sed -e 's|opvp||' -e 's|oprp||'` 
        AC_MSG_WARN(Unable to include opvp/oprp driver due to missing iconv/libiconv...)
    fi

#    Remove contributed drivers if requested and make sure we don't have any 
#   duplicates in there, add $(DD)foo.dev constructs
    P_DEVS=`(for i in $P_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles 2>&1 >/dev/null ) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$F_DEVS0"; then
    F_DEVS=`(for i in $F_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$CUPS_DEVS0"; then
    CUPS_DEVS=`(for i in $CUPS_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$SVG_DEVS0"; then
    SVG_DEVS=`(for i in $SVG_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$IJS_DEVS0"; then
    IJS_DEVS=`(for i in $IJS_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$PNG_DEVS0"; then
    PNG_DEVS=`(for i in $PNG_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

if test -n "$X11_DEVS0"; then
    X11_DEVS=`(for i in $X11_DEVS0; do d='$(DD)'${i}.dev; if ( grep '^'$d $noncontribmakefiles  2>&1 >/dev/null) || ( ! test -z "$CONTRIBINCLUDE" ); then echo $d; fi; done) | sort | uniq | tr '\012\015' '  '`
fi

AC_SUBST(P_DEVS)
AC_SUBST(F_DEVS)
AC_SUBST(CUPS_DEVS)
AC_SUBST(SVG_DEVS)
AC_SUBST(JBIG2_DEVS)
AC_SUBST(IJS_DEVS)
AC_SUBST(PNG_DEVS)

# This now gets done after handling --enable-dynamic
# AC_SUBST(X11_DEVS)

dnl Dynamic device support.
DYNAMIC_CFLAGS=""
DYNAMIC_DEVS=""
DYNAMIC_FLAGS=""
DYNAMIC_LDFLAGS=""
DYNAMIC_LIBS=""
INSTALL_SHARED=""

case `uname` in
	Linux*|GNU*)
	DYNAMIC_CFLAGS="-fPIC"
	DYNAMIC_LDFLAGS="-fPIC -shared"
        if test $ac_cv_prog_gcc = yes; then
            # GCC high level flag
	    DYNAMIC_LIBS="-rdynamic -ldl"
        else
            DYNAMIC_LIBS=""
        fi
	;;
	*BSD)
	DYNAMIC_CFLAGS="-fPIC"
	DYNAMIC_LDFLAGS="-fPIC -shared"
	DYNAMIC_LIBS=""
	;;
	Darwin*)
	DYNAMIC_LDFLAGS="-dynamiclib"
	DYNAMIC_LIBS=""
	;;
	SunOS)
	if test $ac_cv_prog_gcc = yes; then
	    DYNAMIC_CFLAGS="-fPIC"
	else
	    DYNAMIC_CFLAGS="-KPIC"
	fi
	DYNAMIC_LDFLAGS="-G"
	DYNAMIC_LIBS=""
	;;
esac

AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
    [Enable dynamically loaded drivers]),
[
	case `uname` in
		Linux*|GNU*)
		INSTALL_SHARED="install-shared"
		if test "x$X_DEVS" != x; then
			DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
		else
			DYNAMIC_DEVS=""
		fi
		DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
		X11_DEVS=""
		OPT_CFLAGS="$DYNAMIC_CFLAGS $OPT_CFLAGS"
		DBG_CFLAGS="$DYNAMIC_CFLAGS $DBG_CFLAGS"
		;;
		*BSD)
		DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
		DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
		X11_DEVS=""
		OPT_CFLAGS="$DYNAMIC_CFLAGS $OPT_CFLAGS"
		DBG_CFLAGS="$DYNAMIC_CFLAGS $DBG_CFLAGS"
		;;
		Darwin*)
		INSTALL_SHARED="install-shared"
		DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
		X11_DEVS=""
		OPT_CFLAGS="$DYNAMIC_CFLAGS $OPT_CFLAGS"
		DBG_CFLAGS="$DYNAMIC_CFLAGS $DBG_CFLAGS"
		;;
		SunOS)
		DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
		DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
		OPT_CFLAGS="$DYNAMIC_CFLAGS $OPT_CFLAGS"
		DBG_CFLAGS="$DYNAMIC_CFLAGS $DBG_CFLAGS"
		;;
		*)
		AC_MSG_ERROR([Sorry, dynamic driver support not available on this platform!])
		;;
	esac
])

AC_SUBST(DYNAMIC_CFLAGS)
AC_SUBST(DYNAMIC_DEVS)
AC_SUBST(DYNAMIC_FLAGS)
AC_SUBST(DYNAMIC_LDFLAGS)
AC_SUBST(DYNAMIC_LIBS)
AC_SUBST(INSTALL_SHARED)
AC_SUBST(X11_DEVS)

dnl look for default font path...
AC_ARG_WITH([fontpath],  AC_HELP_STRING([--with-fontpath],
    [set font search path for gs]), fontpath="$withval", fontpath="")

dnl Fix "prefix" variable...
if test "x$prefix" = xNONE; then
	prefix=/usr/local
fi

dnl Fix "datadir" variable...
if test "x$datadir" = 'x${prefix}/share'; then
	datadir="$prefix/share"
fi

dnl Fix "fontpath" variable...
if test "x$fontpath" = "x"; then
	# These font directories are used by various Linux distributions...
	fontpath="$datadir/fonts/default/ghostscript"
	fontpath="${fontpath}:$datadir/fonts/default/Type1"
	fontpath="${fontpath}:$datadir/fonts/default/TrueType"

	# These font directories are used by IRIX...
	fontpath="${fontpath}:/usr/lib/DPS/outline/base"

	# These font directories are used by Solaris...
	fontpath="${fontpath}:/usr/openwin/lib/X11/fonts/Type1"
	fontpath="${fontpath}:/usr/openwin/lib/X11/fonts/TrueType"

	# This font directory is used by CUPS...
	if test "x$CUPSCONFIG" != x; then
	  fontpath="${fontpath}:`$CUPSCONFIG --datadir`/fonts"
	fi
fi

AC_SUBST(fontpath)

dnl --------------------------------------------------
dnl Check for library functions
dnl --------------------------------------------------

AC_CHECK_FUNCS([mkstemp], [HAVE_MKSTEMP=-DHAVE_MKSTEMP])
AC_SUBST(HAVE_MKSTEMP)

AC_CHECK_FUNCS([fopen64], [HAVE_FILE64=-DHAVE_FILE64])
AC_SUBST(HAVE_FILE64)

AC_CHECK_FUNCS([mkstemp64], [HAVE_MKSTEMP64=-DHAVE_MKSTEMP64])
AC_SUBST(HAVE_MKSTEMP64)

AC_CHECK_FUNCS([setlocale], [HAVE_SETLOCALE=-DHAVE_SETLOCALE])
AC_SUBST(HAVE_SETLOCALE)

AC_PROG_GCC_TRADITIONAL

dnl NB: We don't actually provide autoconf-switched fallbacks for any
dnl     of these functions, so the checks are purely informational.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([bzero dup2 floor gettimeofday memchr memmove memset mkdir mkfifo modf pow putenv rint setenv sqrt strchr strerror strrchr strspn strstr])

dnl --------------------------------------------------
dnl check for sse2 intrinsics
dnl --------------------------------------------------

HAVE_SSE2=""
AC_LINK_IFELSE([
#include <emmintrin.h>
int main (int argc, char *argv[])
{
  __m128i input1;
  return(0);
}
],HAVE_SSE2="-DHAVE_SSE2")

AC_ARG_ENABLE([sse2], AC_HELP_STRING([--disable-sse2],
       [Do not use sse2 instrinsics]), [
             if test "x$enable_sse2" = xno; then
                HAVE_SSE2=""
             fi])

AC_SUBST(HAVE_SSE2)

dnl --------------------------------------------------
dnl check for byte swap intrinsics
dnl --------------------------------------------------

HAVE_BSWAP32=""
AC_LINK_IFELSE([
int main (int argc, char *argv[])
{
  int a = __builtin_bswap32(argc);
  return(0);
}
],HAVE_BSWAP32="-DHAVE_BSWAP32", HAVE_BSWAP32="")

AC_ARG_ENABLE([bswap32], AC_HELP_STRING([--disable-bswap32],
       [Do not use bswap32 instrinsic]), [
             if test "x$enable_bswap32" = xno; then
                HAVE_BSWAP32=""
             fi])
 
AC_SUBST(HAVE_BSWAP32)

dnl --------------------------------------------------
dnl check for byte swap header
dnl --------------------------------------------------

HAVE_BYTESWAP_H=""
AC_COMPILE_IFELSE([
#include "byteswap.h"
int main (int argc, char *argv[])
{
  int a = bswap_32(argc);
  return(0);
}
],HAVE_BYTESWAP_H="-DHAVE_BYTESWAP_H", HAVE_BYTESWAP_H="")

AC_ARG_ENABLE([byteswap-h], AC_HELP_STRING([--disable-byteswap-h],
       [Do not use byteswap.h functions]), [
             if test "x$enable_byteswap-h" = xno; then
                HAVE_BYTESWAP_H=""
             fi])
 
AC_SUBST(HAVE_BYTESWAP_H)

dnl --------------------------------------------------
dnl Do substitutions
dnl --------------------------------------------------

AC_SUBST(OPT_CFLAGS)
AC_SUBST(DBG_CFLAGS)
AC_SUBST(GCFLAGS)

AC_OUTPUT(Makefile)

if ( test -d cups ); then
AC_OUTPUT(cups/pstopxl)
chmod +x cups/pstopxl
fi