summaryrefslogtreecommitdiffstats
path: root/src/ghostscript-1-fixes.patch
blob: 496841a7585041efc5a5ffd5456c321705fd487d (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
This file is part of MXE. See LICENSE.md for licensing information.

Contains ad hoc patches for cross building.

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: darealshinji <djcj@gmx.de>
Date: Mon, 3 Dec 2018 21:05:41 +0100
Subject: [PATCH 1/2] cross-build fixes, hide libgs symbols


diff --git a/Makefile.in b/Makefile.in
index 1111111..2222222 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -172,6 +172,9 @@ CAPOPT= @HAVE_MKSTEMP@ @HAVE_FILE64@ @HAVE_FSEEKO@ @HAVE_MKSTEMP64@ @HAVE_FONTCO
 
 GS=@GS@
 GS_SO_BASE=@GS@
+GS_SONAME=@GS_SONAME@
+GS_SONAME_MAJOR=@GS_SONAME_MAJOR@
+GS_SONAME_MAJOR_MINOR=@GS_SONAME_MAJOR_MINOR@
 
 PCL=@PCL@
 PCL_SO_BASE=@PCL@
@@ -183,7 +186,7 @@ GPDL=@GPDL@
 GPDL_SO_BASE=@GPDL@
 
 XE=@EXEEXT@
-XEAUX=@EXEEXT@
+XEAUX=@AUXEXEEXT@
 
 PCL_TARGET=@PCL_TARGET@
 XPS_TARGET=@XPS_TARGET@
diff --git a/base/gp_unix.c b/base/gp_unix.c
index 1111111..2222222 100644
--- a/base/gp_unix.c
+++ b/base/gp_unix.c
@@ -16,6 +16,9 @@
 
 /* Unix-specific routines for Ghostscript */
 
+#ifdef __MINGW32__
+#  include "windows_.h"
+#endif
 #include "pipe_.h"
 #include "string_.h"
 #include "time_.h"
@@ -466,3 +469,54 @@ void gp_enumerate_fonts_free(void *enum_state)
     }
 #endif
 }
+
+/* A function to decode the next codepoint of the supplied args from the
+ * local windows codepage, or -1 for EOF.
+ * (copied from gp_win32.c)
+ */
+
+#ifdef __MINGW32__
+int
+gp_local_arg_encoding_get_codepoint(gp_file *file, const char **astr)
+{
+    int len;
+    int c;
+    char arg[3];
+    wchar_t unicode[2];
+    char utf8[4];
+
+    if (file) {
+        c = fgetc(file);
+        if (c == EOF)
+            return EOF;
+    } else if (**astr) {
+        c = *(*astr)++;
+        if (c == 0)
+            return EOF;
+    } else {
+        return EOF;
+    }
+
+    arg[0] = c;
+    if (IsDBCSLeadByte(c)) {
+        if (file) {
+            c = fgetc(file);
+            if (c == EOF)
+                return EOF;
+        } else if (**astr) {
+            c = *(*astr)++;
+            if (c == 0)
+                return EOF;
+        }
+        arg[1] = c;
+        len = 2;
+    } else {
+        len = 1;
+    }
+
+    /* Convert the string (unterminated in, unterminated out) */
+    len = MultiByteToWideChar(CP_ACP, 0, arg, len, unicode, 2);
+
+    return unicode[0];
+}
+#endif /* __MINGW32__ */
diff --git a/base/unix-aux.mak b/base/unix-aux.mak
index 1111111..2222222 100644
--- a/base/unix-aux.mak
+++ b/base/unix-aux.mak
@@ -57,23 +57,29 @@ $(AUX)gp_stdia.$(OBJ): $(GLSRC)gp_stdia.c $(AK)\
 # -------------------------- Auxiliary programs --------------------------- #
 
 $(ECHOGS_XE): $(GLSRC)echogs.c $(AK) $(stdpre_h) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(ECHOGS_XE) || \
 	$(CCAUX_) $(I_)$(GLSRCDIR)$(_I) $(O_)$(ECHOGS_XE) $(GLSRC)echogs.c $(AUXEXTRALIBS)
 
 $(PACKPS_XE): $(GLSRC)pack_ps.c $(stdpre_h) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(PACKPS_XE) || \
 	$(CCAUX_) $(I_)$(GLSRCDIR)$(_I) $(O_)$(PACKPS_XE) $(GLSRC)pack_ps.c $(AUXEXTRALIBS)
 
 # On the RS/6000 (at least), compiling genarch.c with gcc with -O
 # produces a buggy executable.
 $(GENARCH_XE): $(GLSRC)genarch.c $(AK) $(GENARCH_DEPS) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(GENARCH_XE) || \
 	$(CCAUX_) $(I_)$(GLSRCDIR)$(_I) $(O_)$(GENARCH_XE) $(GLSRC)genarch.c $(AUXEXTRALIBS)
 
 $(GENCONF_XE): $(GLSRC)genconf.c $(AK) $(GENCONF_DEPS) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(GENCONF_XE) || \
 	$(CCAUX_) $(I_)$(GLSRCDIR)$(_I) $(O_)$(GENCONF_XE) $(GLSRC)genconf.c $(AUXEXTRALIBS)
 
 $(GENDEV_XE): $(GLSRC)gendev.c $(AK) $(GENDEV_DEPS) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(GENDEV_XE) || \
 	$(CCAUX_) $(I_)$(GLSRCDIR)$(_I) $(O_)$(GENDEV_XE) $(GLSRC)gendev.c $(AUXEXTRALIBS)
 
 $(GENHT_XE): $(GLSRC)genht.c $(AK) $(GENHT_DEPS) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(GENHT_XE) || \
 	$(CCAUX_) $(GENHT_CFLAGS) $(O_)$(GENHT_XE) $(GLSRC)genht.c $(AUXEXTRALIBS)
 
 # To get GS to use the system zlib, you remove/hide the gs/zlib directory
@@ -84,6 +90,7 @@ MKROMFS_OBJS_0=$(MKROMFS_ZLIB_OBJS) $(AUX)gpmisc.$(OBJ) $(AUX)gp_getnv.$(OBJ) \
  $(AUX)gp_stdia.$(OBJ) $(AUX)gsutil.$(OBJ) $(AUX)memento.$(OBJ)
 
 $(MKROMFS_XE)_0: $(GLSRC)mkromfs.c $(MKROMFS_COMMON_DEPS) $(MKROMFS_OBJS_0) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(MKROMFS_XE)_0 || \
 	$(CCAUX_) $(GENOPTAUX) $(I_)$(GLSRCDIR)$(_I) $(I_)$(GLOBJ)$(_I) $(I_)$(ZSRCDIR)$(_I) $(GLSRC)mkromfs.c $(O_)$(MKROMFS_XE)_0 $(MKROMFS_OBJS_0) $(AUXEXTRALIBS)
 
 # .... and one using the zlib library linked via the command line
@@ -93,9 +100,11 @@ MKROMFS_OBJS_1=$(AUX)gscdefs.$(OBJ) \
  $(AUX)gp_stdia.$(OBJ) $(AUX)gsutil.$(OBJ)
 
 $(MKROMFS_XE)_1: $(GLSRC)mkromfs.c $(MKROMFS_COMMON_DEPS) $(MKROMFS_OBJS_1) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(MKROMFS_XE)_1 || \
 	$(CCAUX_) $(GENOPTAUX) $(I_)$(GLSRCDIR)$(_I) $(I_)$(GLOBJ)$(_I) $(I_)$(ZSRCDIR)$(_I) $(GLSRC)mkromfs.c $(O_)$(MKROMFS_XE)_1 $(MKROMFS_OBJS_1) $(AUXEXTRALIBS)
 
 $(MKROMFS_XE): $(MKROMFS_XE)_$(SHARE_ZLIB) $(UNIX_AUX_MAK) $(MAKEDIRS)
+	test -e $(MKROMFS_XE) || \
 	$(CP_) $(MKROMFS_XE)_$(SHARE_ZLIB) $(MKROMFS_XE)
 
 # Query the environment to construct gconfig_.h.
diff --git a/base/unix-dll.mak b/base/unix-dll.mak
index 1111111..2222222 100644
--- a/base/unix-dll.mak
+++ b/base/unix-dll.mak
@@ -66,9 +66,6 @@ GPDL_SONAME_BASE=lib$(GPDL_SO_BASE)
 GS_SOEXT=$(SO_LIB_EXT)
 GS_DLLEXT=$(DLL_EXT)
 
-GS_SONAME=$(GS_SONAME_BASE)$(GS_SOEXT)$(GS_DLLEXT)
-GS_SONAME_MAJOR=$(GS_SONAME_BASE)$(GS_SOEXT)$(SO_LIB_VERSION_SEPARATOR)$(GS_VERSION_MAJOR)$(GS_DLLEXT)
-GS_SONAME_MAJOR_MINOR=$(GS_SONAME_BASE)$(GS_SOEXT)$(SO_LIB_VERSION_SEPARATOR)$(GS_VERSION_MAJOR)$(SO_LIB_VERSION_SEPARATOR)$(GS_VERSION_MINOR)$(GS_DLLEXT)
 
 PCL_SONAME=$(PCL_SONAME_BASE)$(GS_SOEXT)$(GS_DLLEXT)
 PCL_SONAME_MAJOR=$(PCL_SONAME_BASE)$(GS_SOEXT)$(SO_LIB_VERSION_SEPARATOR)$(GS_VERSION_MAJOR)$(GS_DLLEXT)
diff --git a/configure.ac b/configure.ac
index 1111111..2222222 100644
--- a/configure.ac
+++ b/configure.ac
@@ -23,6 +23,7 @@ AC_INIT
 AC_PREREQ(2.63)
 AC_LANG(C)
 AC_CONFIG_SRCDIR(psi/gs.c)
+AC_CANONICAL_HOST
 
 dnl Inherit compiler flags from the environment...
 CFLAGS="${CFLAGS:=}"
@@ -125,8 +126,11 @@ AUXEXTRALIBSTMP="\$(EXTRALIBS)"
 
 # purposefully do not include "help" output for this
 AC_ARG_ENABLE([save_confaux])
+AC_ARG_ENABLE([auxtools_only])
 
-if test x"$CCAUX" != x"" ; then
+absolute_source_path=$(cd "$(dirname "$0")" && pwd)
+
+if test x"$host" != x"$build" ; then
   # rerun configure for the AUX tools, disabling a load of tests not relevant for CCAUX
   olddir=`pwd`
   if test x"$enable_save_confaux" = x"yes"; then
@@ -146,9 +150,10 @@ if test x"$CCAUX" != x"" ; then
   echo $AUXFLAGS_MAK_LINE06 >> $AUXFLAGS_MAK.in
   echo $AUXFLAGS_MAK_LINE07 >> $AUXFLAGS_MAK.in
 
-  ../$0 CC="$CCAUX" CFLAGS="$CFLAGSAUX" LDFLAGS="$LDFLAGSAUX" CCAUX= CFLAGSAUX= CFLAGSAUX= MAKEFILE=$AUXFLAGS_MAK --host= --build= --without-libtiff --disable-contrib --disable-fontconfig --disable-dbus --disable-freetype --disable-fapi --disable-cups --disable-openjpeg --disable-gtk --with-libiconv=no --without-libidn --without-libpaper --without-pdftoraster --without-ijs --without-luratech --without-jbig2dec --without-x --with-drivers=""
+  AC_MSG_NOTICE([Begin recursive call to configure script (for auxiliary tools)])
+  "$absolute_source_path/configure" CC="$CCAUX" CFLAGS="$CFLAGSAUX" LDFLAGS="$LDFLAGSAUX" CCAUX= CFLAGSAUX= CFLAGSAUX= MAKEFILE=$AUXFLAGS_MAK --host=$build --build=$build --enable-auxtools_only --with-local-zlib --without-libtiff --disable-contrib --disable-fontconfig --disable-dbus --disable-freetype --disable-fapi --disable-cups --disable-openjpeg --disable-gtk --with-libiconv=no --without-libidn --without-libpaper --without-pdftoraster --without-ijs --without-luratech --without-jbig2dec --without-x --with-drivers=""
   status=$?
-  cp config.log ../configaux.log
+  cp config.log $olddir/configaux.log
   if test $status -eq 0 ; then
     CCAUX=$(grep CCAUX $AUXFLAGS_MAK | sed "s/CCAUX=//g")
     GCFLAGSAUXTMP=$(grep GCFLAGSAUX $AUXFLAGS_MAK | sed "s/GCFLAGSAUX=//g")
@@ -204,7 +209,7 @@ AC_PATH_TOOL(PKGCONFIG, pkg-config)
 # but if we are cross compiling, and there isn't a matching
 # pkconfig for the --host setting, then don't use the 'local'
 # pkconfig at all
-if test x"$cross_compiling" = x"yes"; then
+if test x"$host" != x"$build" ; then
   AC_PATH_PROG(BUILD_PKGCONFIG, pkg-config)
   if test x"$BUILD_PKGCONFIG" = x"$PKGCONFIG" ; then
     PKGCONFIG=
@@ -217,7 +222,7 @@ AC_PATH_TOOL(STRIP_XE, strip)
 # but if we are cross compiling, and there isn't a matching
 # pkconfig for the --host setting, then don't use the 'local'
 # pkconfig at all
-if test x"$cross_compiling" = x"yes"; then
+if test x"$host" != x"$build" ; then
   AC_PATH_PROG(BUILD_STRIP_XE, strip)
   if test x"$BUILD_STRIP_XE" = x"$STRIP_XE" ; then
     STRIP_XE=
@@ -234,18 +239,14 @@ CONTRIBINCLUDE="include $srcdir/contrib/contrib.mak"
 INSTALL_CONTRIB="install-contrib-extras"
 
 if test x"$enable_contrib" = x; then
-  if test x"$cross_compiling" = x"yes"; then
-    enable_contrib=
-  else
-    case `uname` in
-      MINGW*|MSYS*)
+    case $host in
+      *-mingw*|*-msys*|*-cygwin*)
         AC_MSG_WARN([disabling contrib devices])
         enable_contrib=no
       ;;
       *)
       ;;
     esac
-  fi
 fi
 
 if test x"$enable_contrib" != x"no"; then
@@ -274,26 +275,27 @@ dnl --------------------------------------------------
 CC_OPT_FLAGS_TO_TRY="-O"
 SET_DT_SONAME="-soname="
 
-if test x"$cross_compiling" = x"yes"; then
-  if test $ac_cv_prog_gcc = yes; then
-      CC_OPT_FLAGS_TO_TRY="-O2"
-      CC_DBG_FLAGS_TO_TRY="-gdwarf-2 -g3 -O0"
-  fi
-else
-  case `uname` in
-        Linux*|GNU*)
+  case $host in
+        *-mingw*|*-msys*|*-cygwin*)
         if test $ac_cv_prog_gcc = yes; then
             CC_OPT_FLAGS_TO_TRY="-O2"
             CC_DBG_FLAGS_TO_TRY="-gdwarf-2 -g3 -O0"
         fi
+        SET_DT_SONAME=""
         ;;
-        *BSD)
+        *-linux*|*-gnu)
+        if test $ac_cv_prog_gcc = yes; then
+            CC_OPT_FLAGS_TO_TRY="-O2"
+            CC_DBG_FLAGS_TO_TRY="-gdwarf-2 -g3 -O0"
+        fi
+        ;;
+        *bsd*)
         if test $ac_cv_prog_gcc = yes; then
             CC_OPT_FLAGS_TO_TRY="-O2"
             CC_DBG_FLAGS_TO_TRY="-gdwarf-2 -g3 -O0"
         fi
         ;;
-        Darwin*)
+        *-darwin*)
         if test $ac_cv_prog_gcc = yes; then
             CC_OPT_FLAGS_TO_TRY="-O2"
             CC_DBG_FLAGS_TO_TRY="-gdwarf-2 -g3 -O0"
@@ -321,7 +323,6 @@ else
         fi
         ;;
   esac
-fi
 
 AC_SUBST(SET_DT_SONAME)
 
@@ -368,18 +369,20 @@ AC_ARG_WITH([arch_h], AC_HELP_STRING([--with-arch_h=<arch.h to use>],
 ARCH_CONF_HEADER=
 
 if test x"$with_arch_h" = x""; then
-  if test x"$cross_compiling" = x"yes"; then
-    ARCH_CONF_HEADER="\$(GLSRCDIR)/../$ARCH_AUTOCONF_HEADER"
-  else
-    case `uname` in
-          Darwin*)
+  case $host in
+          x86_64*-mingw*|x86_64*-msys*|x86_64*-cygwin*)
+            ARCH_CONF_HEADER="\$(GLSRCDIR)/../arch/windows-x64-msvc.h"
+          ;;
+          *-mingw*|*-msys*|*-cygwin*)
+            ARCH_CONF_HEADER="\$(GLSRCDIR)/../arch/windows-x86-msvc.h"
+          ;;
+          *-darwin*)
             ARCH_CONF_HEADER="\$(GLSRCDIR)/../arch/osx-x86-x86_64-ppc-gcc.h"
           ;;
           *)
             ARCH_CONF_HEADER=
           ;;
     esac
-  fi
 else
   ARCH_CONF_HEADER=$with_arch_h
 fi
@@ -658,15 +661,7 @@ 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
-
-if test x"$host_alias" != x""; then
-  SUBCONFIG_OPTS="$SUBCONFIG_OPTS --host=$host_alias"
-fi
+SUBCONFIG_OPTS="--build=$build --host=$host"
 
 dnl --------------------------------------------------
 dnl Check for libraries
@@ -996,7 +991,7 @@ if test x"$enable_fapi" != xno; then
             if $PKGCONFIG --atleast-version=12.0.6 freetype2; then
                 AC_MSG_RESULT(yes)
                 FT_CFLAGS="$CFLAGS `$PKGCONFIG --cflags freetype2`"
-                FT_LIBS="`$PKGCONFIG --libs freetype2`"
+                FT_LIBS="`$PKGCONFIG --libs-only-l freetype2`"
                 FT_BRIDGE=1
                 SHARE_FT=1
             else
@@ -1047,6 +1042,14 @@ AC_SUBST(FTSRCDIR)
 AC_SUBST(FT_CFLAGS)
 AC_SUBST(FT_LIBS)
 
+if test x"$enable_auxtools_only" = x"yes" ; then
+  LIBJPEGDIR=
+  SHARE_LIBJPEG=0
+  AC_DEFINE([DONT_HAVE_JMEMSYS_H], 1, [])
+  AC_SUBST(SHARE_LIBJPEG)
+  AC_SUBST(LIBJPEGDIR)
+else
+
 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.
@@ -1088,6 +1091,13 @@ else
     [define if the libjpeg memory system prototypes aren't available])
 fi
 
+fi # $enable_auxtools_only
+
+# this option is useful if you're cross-compiling and want to use
+# your toolchain's zlib for $host but the local one for $build
+AC_ARG_WITH([local-zlib], AC_HELP_STRING([--without-local-zlib],
+  [do not check for local zlib sources (has no effect on AUX toolchain when cross-building)]))
+
 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)
@@ -1096,6 +1106,13 @@ ZLIBDIR=src
 AUX_SHARED_ZLIB=
 ZLIBCFLAGS=""
 
+if test x"$with_local_zlib" = x"no" ; then
+  AC_MSG_RESULT([skip])
+  AC_CHECK_LIB(z, deflate, [
+    AC_CHECK_HEADERS(zlib.h, [SHARE_ZLIB=1; AUX_SHARED_ZLIB="-l\$(ZLIB_NAME)"])
+  ])
+else
+
 if test -d $srcdir/zlib; then
         AC_MSG_RESULT([yes])
         SHARE_ZLIB=0
@@ -1110,6 +1127,9 @@ else
           AC_CHECK_HEADERS(zlib.h, [SHARE_ZLIB=1; AUX_SHARED_ZLIB="-l\$(ZLIB_NAME)"])
         ])
 fi
+
+fi # $with_local_zlib
+
 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
@@ -1136,6 +1156,11 @@ AC_SUBST(ZLIBDIR)
 AC_SUBST(FT_SYS_ZLIB)
 
 dnl png for the png output device; it also requires zlib
+if test x"$enable_auxtools_only" = x"yes" ; then
+  LIBPNGDIR=""
+  SHARE_LIBPNG=0
+else
+
 LIBPNGDIR=src
 PNGDEVS=''
 PNGDEVS_ALL='png48 png16m pnggray pngmono pngmonod png256 png16 pngalpha'
@@ -1157,12 +1182,21 @@ fi
 if test -z "$PNGDEVS"; then
   AC_MSG_NOTICE([disabling png output devices])
 fi
+
+fi # $enable_auxtools_only
+
 AC_SUBST(SHARE_LIBPNG)
 AC_SUBST(LIBPNGDIR)
 #AC_SUBST(PNGDEVS)
 
 WHICHLCMS=
 
+if test x"$enable_auxtools_only" = x"yes" ; then
+  SHARELCMS=0
+  LCMS2DIR=
+  LCMS2MTDIR=
+else
+
 AC_MSG_CHECKING([for local lcms2mt library source])
 LCMS2DIR=src
 LCMS2MTDIR=src
@@ -1197,6 +1231,8 @@ else
    fi
 fi
 
+fi # $enable_auxtools_only
+
 AC_SUBST(SHARELCMS)
 AC_SUBST(WHICHLCMS)
 AC_SUBST(LCMS2DIR)
@@ -1349,7 +1385,7 @@ EXPATDIR=src
 EXPAT_CFLAGS=
 EXPAT_LIBS=
 
-if test x"$with_xps" != x"no" ; then
+if test x"$with_xps" != x"no" -a x"$enable_auxtools_only" != x"yes" ; then
   if test -f $srcdir/xps/xps.mak; then
     AC_MSG_CHECKING([for local expat library source])
     if test -f $srcdir/expat/lib/expat.h ; then
@@ -1528,16 +1564,14 @@ dnl look for IJS implementation
 AC_ARG_WITH([ijs], AC_HELP_STRING([--without-ijs],
     [disable IJS driver support]))
 
-if test x"$cross_compiling" != x"yes"; then
-  case `uname` in
-    MINGW*|MSYS*)
+  case $host in
+    *-mingw*|*-msys*|*-cygwin*)
       AC_MSG_WARN([disabling the ijs device])
       with_ijs=no
     ;;
     *)
     ;;
   esac
-fi
 
 dnl set safe defaults
     IJSDIR=src
@@ -1589,15 +1623,8 @@ if test x$with_luratech != xno; then
     SHARE_JBIG2=0
     JBIG2DIR=$srcdir/luratech/ldf_jb2
 
-    if test x"$cross_compiling" = x"yes"; then
-        if test x"$JBIG2_CFLAGS" != x""; then
-          JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -fsigned-char $JBIG2_CFLAGS"
-        else
-          JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -fsigned-char -DLINUX=1 -DFORTE"
-        fi
-    else
-      case `uname` in
-        Darwin*)
+      case $host in
+        *-darwin*)
           JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -DMAC -DMAC_OS_X_BUILD -fsigned-char"
         ;;
         AIX)
@@ -1611,7 +1638,6 @@ if test x$with_luratech != xno; then
           JBIG2_AUTOCONF_CFLAGS="-DUSE_LDF_JB2 -fsigned-char -DLINUX=1 -DFORTE"
         ;;
       esac
-    fi
 
     JBIG2FILEDEVS='$(DD)gdevjbig2.dev'
     JBIG2DEVS='$(PSD)jbig2.dev'
@@ -1734,15 +1760,8 @@ if test x$with_luratech != xno; then
     SHARE_JPX=0
     JPXDIR=$srcdir/luratech/lwf_jp2
 
-    if test x"$cross_compiling" = x"yes"; then
-        if test x"$JPX_CFLAGS" != x""; then
-          JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 $JPX_CFLAGS"
-        else
-          JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 -DLINUX=1 -DFORTE"
-        fi
-    else
-      case `uname` in
-        Darwin*)
+      case $host in
+        *-darwin*)
           JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 -DMAC -DMAC_OS_X_BUILD"
         ;;
         AIX)
@@ -1756,7 +1775,6 @@ if test x$with_luratech != xno; then
           JPX_AUTOCONF_CFLAGS="-DUSE_LWF_JP2 -DLINUX=1 -DFORTE"
         ;;
       esac
-    fi
     JPXDEVS='$(PSD)jpx.dev'
   else
     AC_MSG_RESULT([no])
@@ -2506,22 +2524,15 @@ SO_LIB_EXT=".so"
 DLL_EXT=""
 SO_LIB_VERSION_SEPARATOR="."
 
-if test x"$cross_compiling" = x"yes"; then
-  DYNAMIC_CFLAGS="-fPIC"
-  GS_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(GS_SONAME_MAJOR)"
-  PCL_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(PCL_SONAME_MAJOR)"
-  XPS_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(XPS_SONAME_MAJOR)"
-  PDL_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(GPDL_SONAME_MAJOR)"
-  if test $ac_cv_prog_gcc = yes; then
-    # GCC high level flag
-    DYNAMIC_LIBS="-rdynamic"
-  else
-    DYNAMIC_LIBS=""
-  fi
-  SO_LIB_EXT=".so"
-else
-  case `uname` in
-    Linux*|GNU*)
+libname1="_SO_BASE)\$(GS_SOEXT)\$(DLL_EXT)"
+libname2="_SO_BASE)\$(GS_SOEXT)\$(SO_LIB_VERSION_SEPARATOR)\$(GS_VERSION_MAJOR)\$(DLL_EXT)"
+libname3="_SO_BASE)\$(GS_SOEXT)\$(SO_LIB_VERSION_SEPARATOR)\$(GS_VERSION_MAJOR)\$(SO_LIB_VERSION_SEPARATOR)\$(GS_VERSION_MINOR)\$(DLL_EXT)"
+GS_SONAME="lib\$(GS${libname1}"
+GS_SONAME_MAJOR="lib\$(GS${libname2}"
+GS_SONAME_MAJOR_MINOR="lib\$(GS${libname3}"
+
+case $host in
+    *-linux*|*-gnu)
       DYNAMIC_CFLAGS="-fPIC"
       GS_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(GS_SONAME_MAJOR)"
       PCL_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(PCL_SONAME_MAJOR)"
@@ -2535,17 +2546,21 @@ else
       fi
       SO_LIB_EXT=".so"
     ;;
-    MINGW*|MSYS*)
-      DYNAMIC_CFLAGS=""
-      GS_DYNAMIC_LDFLAGS="-shared  -Wl,--out-implib=\$(BINDIR)/lib\$(GS_SO_BASE).dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import"
+    *-mingw*|*-msys*|*-cygwin*)
+      DYNAMIC_CFLAGS="-fvisibility=hidden -DGSDLLEXPORT=\"__declspec(dllexport)\""
+      GS_DYNAMIC_LDFLAGS="-shared -Wl,--out-implib=\$(BINDIR)/lib\$(GS_SO_BASE).dll.a -Wl,--enable-auto-import"
       PCL_DYNAMIC_LDFLAGS="-shared  -Wl,--out-implib=\$(BINDIR)/lib\$(PCL_SO_BASE).dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import"
       XPS_DYNAMIC_LDFLAGS="-shared  -Wl,--out-implib=\$(BINDIR)/lib\$(XPS_SO_BASE).dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import"
       PDL_DYNAMIC_LDFLAGS="-shared  -Wl,--out-implib=\$(BINDIR)/lib\$(PDL_SO_BASE).dll.a -Wl,--export-all-symbols -Wl,--enable-auto-import"
       SO_LIB_EXT=""
       DLL_EXT=".dll"
       SO_LIB_VERSION_SEPARATOR="-"
+      # make sure the import library doesn't link a program against the DLL with the minor version in it
+      GS_SONAME="lib\$(GS${libname1}"
+      GS_SONAME_MAJOR="lib\$(GS${libname3}"
+      GS_SONAME_MAJOR_MINOR="lib\$(GS${libname2}"
     ;;
-    *BSD)
+    *bsd*)
       DYNAMIC_CFLAGS="-fPIC"
       GS_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(GS_SONAME_MAJOR)"
       PCL_DYNAMIC_LDFLAGS="-shared -Wl,\$(LD_SET_DT_SONAME)\$(LDFLAGS_SO_PREFIX)\$(PCL_SONAME_MAJOR)"
@@ -2553,7 +2568,7 @@ else
       DYNAMIC_LIBS=""
       SO_LIB_EXT=".so"
     ;;
-    Darwin*)
+    *-darwin*)
       GS_DYNAMIC_LDFLAGS="-dynamiclib -install_name \$(GS_SONAME_MAJOR_MINOR)"
       PCL_DYNAMIC_LDFLAGS="-dynamiclib -install_name \$(PCL_SONAME_MAJOR_MINOR)"
       XPS_DYNAMIC_LDFLAGS="-dynamiclib -install_name \$(XPS_SONAME_MAJOR_MINOR)"
@@ -2591,15 +2606,18 @@ else
       fi
       SO_LIB_EXT=".so"
       ;;
-  esac
-fi
+esac
+
+AC_SUBST(GS_SONAME)
+AC_SUBST(GS_SONAME_MAJOR)
+AC_SUBST(GS_SONAME_MAJOR_MINOR)
 
 AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
     [Enable dynamically loaded drivers]),
 [
   if test "x$enable_dynamic" != xno; then
-    case `uname` in
-      Linux*|GNU*)
+    case $host in
+      *-linux*|*-gnu)
       INSTALL_SHARED="install-shared"
       if test "x$X_DEVS" != x; then
               DYNAMIC_DEVS="\$(GLOBJDIR)/X11.so"
@@ -2611,14 +2629,14 @@ AC_ARG_ENABLE([dynamic], AC_HELP_STRING([--enable-dynamic],
       OPT_CFLAGS="$DYNAMIC_CFLAGS $OPT_CFLAGS"
       DBG_CFLAGS="$DYNAMIC_CFLAGS $DBG_CFLAGS"
       ;;
-      *BSD)
+      *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*)
+      *-darwin*)
       INSTALL_SHARED="install-shared"
       DYNAMIC_FLAGS="-DGS_DEVS_SHARED -DGS_DEVS_SHARED_DIR=\\\"\$(gssharedir)\\\""
       X11_DEVS=""
@@ -2963,23 +2981,31 @@ AC_SUBST(AUXDIRPOSTFIX)
 # usually empty on Unix-like systems
 # --------------------------------------------------
 EXEEXT=""
+AUXEXEEXT=""
+
+case $host in
+    *-mingw*|*-msys*|*-cygwin*)
+      EXEEXT=".exe"
+    ;;
+    *)
+    ;;
+esac
 
 AC_ARG_WITH([exe-ext],  AC_HELP_STRING([--with-exe-ext=EXT],
-    [set the file name executable extension (must include any separator e.g. the period in ".exe")]),[], [exe_ext=])
+    [set the file name executable extension (must include any separator e.g. the period in ".exe")]),
+    [EXEEXT="$with_exe_ext"])
 
-if test "x"$with_exe_ext != "x"; then
-  EXEEXT="$with_exe_ext"
-else
-  if test x"$cross_compiling" != x"yes"; then
-    case `uname` in
-      MINGW*|MSYS*)
-        EXEEXT=".exe"
-      ;;
-    esac
-  fi
-fi
+case $build in
+    *-mingw*|*-msys*|*-cygwin*)
+      AUXEXEEXT=".exe"
+    ;;
+    *)
+      AUXEXEEXT="$EXEEXT"
+    ;;
+esac
 
 AC_SUBST(EXEEXT)
+AC_SUBST(AUXEXEEXT)
 
 # --------------------------------------------------
 # Check for disabling of versioned path option.
@@ -3034,7 +3060,7 @@ fi
 
 AC_SUBST(CLUSTER_CFLAGS)
 
-if test x"$CCAUX" != x"$CC"; then
+if test x"$build" != x"$host"; then
 
   ilog2()
   {
@@ -3174,7 +3200,7 @@ AC_SUBST(AUXEXTRALIBS)
 
 CONFIG_FILES_LIST="$CONFIG_FILES_LIST $THEMAKEFILE"
 
-if test x"$THEMAKEFILE" != x"$MAKEFILE" && test x"$CCAUX" = x"$CC"; then
+if test x"$THEMAKEFILE" != x"$MAKEFILE" && test x"$build" = x"$host"; then
   CONFIG_FILES_LIST="$CONFIG_FILES_LIST"
 fi
 
diff --git a/psi/iapi.h b/psi/iapi.h
index 1111111..2222222 100644
--- a/psi/iapi.h
+++ b/psi/iapi.h
@@ -68,6 +68,11 @@ extern "C" {
 #    define GSDLLEXPORT
 #  endif
 # endif
+# ifdef __MINGW32__
+/* export stdcall functions as "name" instead of "_name@ordinal" */
+#  undef GSDLLAPI
+#  define GSDLLAPI
+# endif
 # ifndef GSDLLAPI
 #  define GSDLLAPI __stdcall
 # endif

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Chris Liddell <chris.liddell@artifex.com>
Date: Tue, 20 Oct 2020 08:49:45 +0100
Subject: [PATCH 2/2] Bug 702985: drop use of FT_CALLBACK_DEF() def

Taken from:
https://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=41ef9a0bc36b#patch1

From 2.10.3, Freetype disappeared the FT_CALLBACK_DEF() macro, which is what
we used when defining our callbacks from Freetype.

No guidance forthcoming from the Freetype developer who made those changes,
so change to explicitly declaring the callbacks file static.

Should fix the reported build failures.

diff --git a/base/fapi_ft.c b/base/fapi_ft.c
index 1111111..2222222 100644
--- a/base/fapi_ft.c
+++ b/base/fapi_ft.c
@@ -125,7 +125,7 @@ static void
 delete_inc_int_info(gs_fapi_server * a_server,
                     FT_IncrementalRec * a_inc_int_info);
 
-FT_CALLBACK_DEF(void *)
+static void *
 FF_alloc(FT_Memory memory, long size)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;
@@ -133,7 +133,7 @@ FF_alloc(FT_Memory memory, long size)
     return (gs_malloc(mem, size, 1, "FF_alloc"));
 }
 
-FT_CALLBACK_DEF(void *)
+static void *
     FF_realloc(FT_Memory memory, long cur_size, long new_size, void *block)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;
@@ -153,7 +153,7 @@ FT_CALLBACK_DEF(void *)
     return (tmp);
 }
 
-FT_CALLBACK_DEF(void)
+static void
     FF_free(FT_Memory memory, void *block)
 {
     gs_memory_t *mem = (gs_memory_t *) memory->user;