Skip to content

Instantly share code, notes, and snippets.

@darealshinji
Last active April 24, 2020 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save darealshinji/c8c8f824d9d54ef1c065c0d4960c33ae to your computer and use it in GitHub Desktop.
Save darealshinji/c8c8f824d9d54ef1c065c0d4960c33ae to your computer and use it in GitHub Desktop.
This file is part of MXE. See LICENSE.md for licensing information.
Contains ad hoc patches for cross building.
diff --git a/configure.ac b/configure.ac
index 1111111..2222222 100644
--- a/configure.ac
+++ b/configure.ac
@@ -146,9 +148,16 @@ 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=""
+ if test "$0" = "./configure" ; then
+ basedir=".."
+ configure="../configure"
+ else
+ basedir="$(basename "$0")"
+ configure="$0"
+ fi
+ "$configure" 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=""
status=$?
- cp config.log ../configaux.log
+ cp config.log "$basedir/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")
@@ -974,7 +983,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
@@ -2323,12 +2323,6 @@
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)"
- 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
@@ -2337,12 +2331,6 @@
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)"
- if test $ac_cv_prog_gcc = yes; then
- # GCC high level flag
- DYNAMIC_LIBS="-rdynamic"
- else
- DYNAMIC_LIBS=""
- fi
SO_LIB_EXT=".so"
;;
MINGW*|MSYS*)
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 @@
# 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
diff --git a/psi/iapi.c b/psi/iapi.c
index 1111111..2222222 100644
--- a/psi/iapi.c
+++ b/psi/iapi.c
@@ -17,6 +17,9 @@
/* Public Application Programming Interface to Ghostscript interpreter */
+#ifdef __WIN32__
+#include "windows_.h"
+#endif
#include "string_.h"
#include "ierrors.h"
#include "gscdefs.h"
@@ -42,6 +45,57 @@ static const int gsapi_instance_max = 1;
#endif
+/* A function to decode the next codepoint of the supplied args from the
+ * local windows codepage, or -1 for EOF.
+ */
+
+#ifdef __WIN32__
+int
+gp_local_arg_encoding_get_codepoint(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 /* __WIN32__ */
+
+
/* Return revision numbers and strings of Ghostscript. */
/* Used for determining if wrong GSDLL loaded. */
/* This may be called before any other function. */
# This file is part of MXE. See LICENSE.md for licensing information.
PKG := ghostscript
$(PKG)_WEBSITE := https://www.ghostscript.com/
$(PKG)_IGNORE :=
$(PKG)_VERSION := 9.23
$(PKG)_NODOTVER := $(subst .,,$($(PKG)_VERSION))
$(PKG)_CHECKSUM := 1fcedc27d4d6081105cdf35606cb3f809523423a6cf9e3c23cead3525d6ae8d9
$(PKG)_SUBDIR := $(PKG)-$($(PKG)_VERSION)
$(PKG)_FILE := $(PKG)-$($(PKG)_VERSION).tar.xz
$(PKG)_URL := https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs$($(PKG)_NODOTVER)/$($(PKG)_FILE)
$(PKG)_DEPS := cc dbus fontconfig freetype lcms libiconv libidn libjpeg-turbo libpaper libpng openjpeg tiff zlib
define $(PKG)_UPDATE
$(WGET) -q -O- 'https://ghostscript.com/Releases.html' | \
$(SED) -n 's:.*GPL_Ghostscript_::p' | \
$(SED) -n 's:\.html.*::p'
endef
define $(PKG)_BUILD
cd '$(SOURCE_DIR)' && rm -rf freetype jpeg libpng openjpeg tiff zlib
cd '$(SOURCE_DIR)' && autoreconf -f -i
cd '$(BUILD_DIR)' && CCAUX='$(BUILD_CC)' \
CPPFLAGS='$(CPPFLAGS) -DHAVE_SYS_TIMES_H=0' \
$(SOURCE_DIR)/configure \
$(MXE_CONFIGURE_OPTS) \
--with-exe-ext='.exe' \
--with-drivers=ALL \
--with-arch_h='$(SOURCE_DIR)/arch/windows-x$(if $(filter x86_64-%,$(TARGET)),64,86)-msvc.h' \
--with-memory-alignment='$(if $(filter x86_64-%,$(TARGET)),8,4)' \
--disable-contrib \
--disable-cups \
--disable-gtk \
--with-libiconv=gnu \
--with-system-libtiff \
--without-ijs
$(MAKE) -C '$(BUILD_DIR)' -j '$(JOBS)' all libgs
$(INSTALL) -d '$(PREFIX)/$(TARGET)/include/ghostscript'
$(INSTALL) '$(SOURCE_DIR)/devices/gdevdsp.h' '$(PREFIX)/$(TARGET)/include/ghostscript/gdevdsp.h'
$(INSTALL) '$(SOURCE_DIR)/base/gserrors.h' '$(PREFIX)/$(TARGET)/include/ghostscript/gserrors.h'
$(INSTALL) '$(SOURCE_DIR)/psi/iapi.h' '$(PREFIX)/$(TARGET)/include/ghostscript/iapi.h'
$(INSTALL) '$(SOURCE_DIR)/psi/ierrors.h' '$(PREFIX)/$(TARGET)/include/ghostscript/ierrors.h'
$(INSTALL) -d '$(PREFIX)/$(TARGET)/bin'
$(INSTALL) -d '$(PREFIX)/$(TARGET)/lib'
$(INSTALL) '$(BUILD_DIR)/bin/gs.exe' '$(PREFIX)/$(TARGET)/bin/gs.exe'
$(INSTALL) '$(BUILD_DIR)/bin/gs.a' '$(PREFIX)/$(TARGET)/lib/libgs.a'
$(INSTALL) -d '$(PREFIX)/$(TARGET)/lib/pkgconfig'
(echo 'Name: ghostscript'; \
echo 'Version: $($(PKG)_VERSION)'; \
echo 'Description: Ghostscript library'; \
echo 'Cflags: -I"$(PREFIX)/$(TARGET)/include/ghostscript"'; \
echo 'Cflags.private: -DGS_STATIC_LIB'; \
echo 'Libs: -L"$(PREFIX)/$(TARGET)/lib" -lgs'; \
echo 'Requires: fontconfig freetype2 libidn libtiff-4 libpng jpeg lcms2 zlib'; \
echo '# https://github.com/mxe/mxe/issues/1446'; \
echo 'Libs.private: -lm -liconv -lpaper -lopenjp2 -lwinspool';) \
> '$(PREFIX)/$(TARGET)/lib/pkgconfig/ghostscript.pc'
# wine gs.exe -q -sDEVICE=pdfwrite -o out.pdf examples/snowflak.ps
'$(TARGET)-gcc' \
-W -Wall -Werror -pedantic \
'$(TEST_FILE)' -o '$(PREFIX)/$(TARGET)/bin/test-ghostscript.exe' \
`$(TARGET)-pkg-config --cflags --libs ghostscript`
endef
# enable/disable in libspectre too
$(PKG)_BUILD_SHARED =
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment