Ghostscript iOS static library

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 cpu
mkdir -p obj/aux
cp ../echogs obj/aux
cp ../genarch obj/aux
cp ../genconf obj/aux
cp ../iOS/MakefileSimulator ./Makefile
cp ../iOS/arch.h ./obj/
make
#make will fail here so restart after copying file
cp ../mkromfs obj/aux
cp ../mkromfs_0 obj/aux
make
#remove duplicate symbol object files
rm obj/inobtokn.o
rm obj/gsiodevs.o
ar -crs libgs_x86_release.a obj/*.o
rm -r obj
mkdir -p obj/aux
cp ../echogs obj/aux
cp ../genarch obj/aux
cp ../genconf obj/aux
cp ../iOS/arch.h ./obj/
cp ../iOS/MakefileiOS ./Makefile
make
cp ../mkromfs obj/aux
cp ../mkromfs_0 obj/aux
make
ar -crs libgs_arm7_release.a obj/*.o
lipo -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/gcc
CCAUX=/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.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>