First some version details:
- Ghostscript version: 9.10
- CPU Type: armv7 (can be modified easily)
- iOS Version: 7.0 (can be modified easily)
Ghostscript iOS static library source code contains build script with makefile, architecture details and bunch of executable binaries which are required during compilation.
Lets walk through the build script, which should be copied inside the ghostscript directory and should be run from there. iOS directory and other executable stay at same level as actual ghostscript code.
#Configure is necessary to create tif-config. Also disable cups and sse2./configure –disable-cups –disable-sse2#Copy precompiled files for machine cpumkdir -p obj/auxcp ../echogs obj/auxcp ../genarch obj/auxcp ../genconf obj/auxcp ../iOS/MakefileSimulator ./Makefilecp ../iOS/arch.h ./obj/make#make will fail here so restart after copying filecp ../mkromfs obj/auxcp ../mkromfs_0 obj/auxmake#remove duplicate symbol object filesrm obj/inobtokn.orm obj/gsiodevs.oar -crs libgs_x86_release.a obj/*.orm -r objmkdir -p obj/auxcp ../echogs obj/auxcp ../genarch obj/auxcp ../genconf obj/auxcp ../iOS/arch.h ./obj/cp ../iOS/MakefileiOS ./Makefilemakecp ../mkromfs obj/auxcp ../mkromfs_0 obj/auxmakear -crs libgs_arm7_release.a obj/*.olipo -output libgsuniversal_release.a -create libgs_arm7_release.a libgs_x86_release.a
Though we have complete make files (which are modified), we need to configure as tiff-config is generated by this command. Compiling cups is not trivial on iOS and SSE2 instructions don’t exist on arm processors hence they are disabled.
After that we copy pre compiled binaries in obj/aux directory. The reason is that we we compile for certain architecture like arm, as we do using specific makefile, we can’t run those executables on the x86 machine. Hence one idea would be compile the complete source as default and then extract these executables to be used later. Here we provide these with the build script.
Now genarch binary generates specific arch according to machine (also explained here), hence we have used the same code to derive architecture specific details by running it on simulator and device. We found it didn’t change hence we use same arch.h for both. Though arm64 may have different architecture details. We copy this pre derived file to obj folder. A modified lib.mak is given as well which can be copied to base folder but we found it unnecessary after copying the arch.h. lib.mak has modification to not generate arch.h.
We copy MakefileSimulator to Makefile inside ghostscript directory. This makefile has modification to use gcc which comes with Xcode for simulator with system root and arch i386 flag to be used. Following has our modifications underlined:
CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gccCCAUX=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc# Define the name of the linker for the final link step.# Normally this is the same as the C compiler.CCLD=$(CC)CCAUXLD=$(CCAUX)# Define the default gcc flags.GCFLAGS= -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -Wno-strict-aliasing -Wdeclaration-after-statement -fno-builtin -fno-common -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DGX_COLOR_INDEX_TYPE=”unsigned long int” –sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -arch i386
Above are the modifications done to makefile generated by configure command.
After running make, it fails on the mkromfs hence we copy correct files to obj/aux in build script and make again. You may see link error but they are just for generating main executable “gs” which we don’t need to worry about. We do same for device as well. Though one thing is different on simulator that we remove couple of object files as otherwise it gives us duplicate symbol issues.
Apart from build script there is Xcode project in GhostscriptiOS folder which has universal library. Example converts the pdf to ps and saves it in documents directory.
Its pretty dirty hack and hopefully I will get time to refine it.