summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Jamfile4
-rw-r--r--Jamrules184
-rw-r--r--apps/Jamfile12
-rw-r--r--apps/windows/winmain.c2
-rw-r--r--base/Jamfile15
-rw-r--r--include/fitz/base_runtime.h25
-rw-r--r--include/fitz/base_sysdep.h100
7 files changed, 195 insertions, 147 deletions
diff --git a/Jamfile b/Jamfile
index 01c536ab..f4fc1cf1 100644
--- a/Jamfile
+++ b/Jamfile
@@ -1,13 +1,15 @@
# --------------------------------------------------------------------------
#
# This is the Jamfile used for building Fitz and MuPDF.
-# Put compiler options and other tweaks in Jamrules, not here.
+# Put paths and other options in Jamrules, not here.
#
# http://public.perforce.com/public/jam/src/Jam.html
#
SubDir TOP ;
+HDRS = [ FDirName $(TOP) include ] ;
+
Main hexdump : hexdump.c ;
SubInclude TOP base ;
diff --git a/Jamrules b/Jamrules
index 1308e75a..86e49995 100644
--- a/Jamrules
+++ b/Jamrules
@@ -1,89 +1,133 @@
-# -------------------------------------------------------------------------
#
-# Jamrules -- the build flags for Fitz and MuPDF.
-# This file is sourced by Jamfile when building.
-# Put all system configuration stuff here.
+# Jamrules -- build configurations
+#
+# JBIG2 and JPEG2000 support is optional. To compile with this,
+# add the following to the jam command line:
+#
+# -sHAVE_JBIG2DEC=true
+# -sHAVE_JASPER=true
+#
+# Windows builds assume that third party headers and
+# libraries are in c:/local/include and c:/local/lib.
+#
+# MacOS X builds assume that you have third party libraries installed
+# from MacPorts in /opt/local.
+#
+# Linux builds assume that you have freetype-config to find the paths
+# to the freetype library.
+#
+# To override these defaults, please supply the paths on the jam
+# command line with -sTHIRDPARTINC and -sTHIRDPARTYLIB.
+#
+# -sTHIRDPARTYINC="-Ic:/wherever/include"
+# -sTHIRDPARTYLIB="-Lc:/wherever/lib"
#
-HDRS = [ FDirName $(TOP) include ] ;
+# Workaround for different OS/OSPLAT settings on FTJam and plain jam
+if $(JAM_TOOLSET) = MINGW { OS = MINGW ; }
+if $(JAM_TOOLSET) = VISUALC { OS = NT ; }
-ALL_LOCATE_TARGET = [ FDirName $(TOP) build $(BUILD) ] ;
+# Place all build products here:
+ALL_LOCATE_TARGET ?= [ FDirName $(TOP) build $(OS)-$(OSPLAT) ] ;
-HAVE_JBIG2DEC ?= yes ; # set to "yes" to include JBIG2 support
-HAVE_JASPER ?= no ; # set to "yes" to include JPEG2000 support
+# Add compile time defines for JBIG2 and JPEG2000 support.
+if $(HAVE_JBIG2DEC) { DEFINES += HAVE_JBIG2DEC ; }
+if $(HAVE_JASPER) { DEFINES += HAVE_JASPER ; }
-BUILD_X11APP ?= no ; # set to "yes" to build unix/x11 viewer
-BUILD_WINAPP ?= no ; # set to "yes" to build windows viewer
-BUILD_PLUGIN ?= no ; # set to "yes" to build mozilla plugin
+# NEED_GETOPT = true ;
+# NEED_STRLCAT = true ;
+# NEED_STRLCPY = true ;
+# NEED_STRSEP = true ;
-# -------------------------------------------------------------------------
+if $(OS) = LINUX
+{
+ Echo Building for LINUX ;
-CCFLAGS ?= "`freetype-config --cflags`" -Wall -std=c99 -DHAVE_C99 ;
-LINKFLAGS ?= "`freetype-config --libs`" ;
-LINKLIBS ?= -lfreetype -ljpeg -lz -lm ;
+ THIRDPARTYINC ?= "`freetype-config --cflags`" ;
+ THIRDPARTYLIB ?= "`freetype-config --libs`" ;
-if $(JAM_TOOLSET) = MINGW
-{
- BUILD_WINAPP = yes ;
- BUILD_PLUGIN = yes ;
- CCFLAGS =
- -Ic:/local/include -Wall -std=c99 -DHAVE_C99 -DWIN32 ;
- LINKFLAGS = -Lc:/local/lib ;
- LINKLIBS = -lfreetype -ljpeg -lz -ljbig2dec ;
- WINLIBS = -lgdi32 -lcomdlg32 -luser32 -ladvapi32 -lshell32 ;
+ BUILD_X11APP = true ;
+
+ CCFLAGS = -Wall -std=c99 $(THIRDPARTYINC) ;
+ LINKFLAGS = $(THIRDPARTYLIB) ;
+ LINKLIBS = -lfreetype -ljpeg -lz -lm ;
+ APPLINKLIBS = -lX11 -lXext ;
+
+ if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
+ if $(HAVE_JASPER) { LINKLIBS += -ljasper ; }
}
-if $(JAM_TOOLSET) = VISUALC
+if $(OS) = MACOSX
{
- BUILD_WINAPP = yes ;
- CCFLAGS = /Ic:/local/include /DWIN32 ;
- LINKFLAGS = /LIBPATH:c:/local/lib ;
- LINKLIBS = freetype.lib jpeg.lib z.lib jbig2dec.lib ;
- WINLIBS = gdi32.lib comdlg32.lib user32.lib advapi32.lib shell32.lib ;
- NEED_GETTIMEOFDAY = yes ;
+ Echo Building for MACOSX ;
+
+ BUILD_X11APP = true ;
+
+ THIRDPARTYINC ?= -I/opt/local/include -I/usr/X11R6/include ;
+ THIRDPARTYLIB ?= -L/opt/local/lib -L/usr/X11R6/lib ;
+
+ CCFLAGS = -Wall -std=c99 $(THIRDPARTYINC) ;
+ LINKFLAGS = $(THIRDPARTYLIB) ;
+ LINKLIBS = -lfreetype -ljpeg -lz -lm ;
+ APPLINKLIBS = -lX11 -lXext ;
+
+ if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
+ if $(HAVE_JASPER) { LINKLIBS += -ljasper ; }
}
-switch $(OS)
+if $(OS) = MINGW
{
- case LINUX :
- BUILD_X11APP = yes ;
- X11LIBS = -lX11 -lXext ;
- NEED_STRLCPY = yes ;
- NEED_STRLCAT = yes ;
-
- case MACOSX :
- BUILD_X11APP = yes ;
- CCFLAGS += -I/opt/local/include -I/usr/X11R6/include ;
- LINKFLAGS += -L/opt/local/lib -L/usr/X11R6/lib ;
- X11LIBS = -lX11 -lXext ;
-
- case NT :
- NEED_GETOPT = yes ;
- NEED_STRSEP = yes ;
- NEED_STRLCAT = yes ;
- NEED_STRLCPY = yes ;
- NEED_MATH = yes ;
-
- case * :
- Echo "OS '$(OS)' not known by build system." ;
- Echo "If you get errors, please edit Jamrules." ;
+ Echo Building for MINGW ;
+
+ NOARSCAN = true ;
+
+ BUILD_WINAPP = true ;
+ BUILD_PLUGIN = true ;
+
+ THIRDPARTYINC ?= -Ic:/local/include ;
+ THIRDPARTYLIB ?= -Lc:/local/lib ;
+
+ CCFLAGS = -Wall -std=c99 $(THIRDPARTYINC) ;
+ LINKFLAGS = $(THIRDPARTYLIB) ;
+ LINKLIBS = -lfreetype -ljpeg -lz ;
+ APPLINKLIBS = -lgdi32 -lcomdlg32 -luser32 -ladvapi32 -lshell32 -mwindows ;
+
+ if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
+ if $(HAVE_JASPER) { LINKLIBS += -ljasper ; }
+
+ actions WindRes { windres -i $(>) -o $(<) --include-dir=$(>:D) }
}
-# -------------------------------------------------------------------------
+if $(OS) = NT
+{
+ Echo Building for MSVC ;
-if $(HAVE_JASPER) = yes { DEFINES += HAVE_JASPER ; }
-if $(HAVE_JBIG2DEC) = yes { DEFINES += HAVE_JBIG2DEC ; }
+ DEFINES += MSVC ;
-if $(NEED_GETOPT) = yes { DEFINES += NEED_GETOPT ; }
-if $(NEED_STRLCAT) = yes { DEFINES += NEED_STRLCAT ; }
-if $(NEED_STRLCPY) = yes { DEFINES += NEED_STRLCPY ; }
-if $(NEED_STRSEP) = yes { DEFINES += NEED_STRSEP ; }
-if $(NEED_MATH) = yes { DEFINES += NEED_MATH ; }
+ BUILD_WINAPP = true ;
+
+ THIRDPARTYINC ?= /Ic:/local/include ;
+ THIRDPARTYLIB ?= /LIBPATH:c:/local/lib ;
+
+ CCFLAGS = $(THIRDPARTYINC) ;
+ LINKFLAGS = $(THIRDPARTYLIB) ;
+ LINKLIBS = freetype.lib jpeg.lib z.lib ;
+ APPLINKLIBS = gdi32.lib comdlg32.lib user32.lib advapi32.lib shell32.lib ;
+
+ if $(HAVE_JBIG2DEC) { LINKLIBS += jbig2dec.lib ; }
+ if $(HAVE_JASPER) { LINKLIBS += jasper.lib ; }
+
+ actions WindRes { rc /fo $(<) $(>) }
+}
+
+# Set some DEFINES based on missing platform features
+
+if $(NEED_GETOPT) { DEFINES += NEED_GETOPT ; }
+if $(NEED_STRLCAT) { DEFINES += NEED_STRLCAT ; }
+if $(NEED_STRLCPY) { DEFINES += NEED_STRLCPY ; }
+if $(NEED_STRSEP) { DEFINES += NEED_STRSEP ; }
-# -------------------------------------------------------------------------
-#
# WindRes rule for compiling the windows viewer and plugin
-#
rule UserObject
{
@@ -100,13 +144,3 @@ rule WindRes
Clean clean : $(<) ;
}
-if $(JAM_TOOLSET) = MINGW
-{
- actions WindRes { windres -i $(>) -o $(<) --include-dir=$(>:D) }
-}
-
-if $(JAM_TOOLSET) = VISUALC
-{
- actions WindRes { rc /fo $(<) $(>) }
-}
-
diff --git a/apps/Jamfile b/apps/Jamfile
index 9c9af761..e8a9f333 100644
--- a/apps/Jamfile
+++ b/apps/Jamfile
@@ -9,28 +9,28 @@ LinkLibraries pdftool : $(FITZLIBS) ;
SubDir TOP apps common ;
Library libpdfapp : pdfapp.c ;
-if $(BUILD_WINAPP) = yes
+if $(BUILD_WINAPP)
{
SubDir TOP apps windows ;
Main pdfview : winmain.c winres.rc ;
LinkLibraries pdfview : libpdfapp $(FITZLIBS) ;
- LINKLIBS on pdfview$(SUFEXE) = $(LINKLIBS) $(WINLIBS) ;
+ LINKLIBS on pdfview$(SUFEXE) = $(LINKLIBS) $(APPLINKLIBS) ;
}
-if $(BUILD_X11APP) = yes
+if $(BUILD_X11APP)
{
SubDir TOP apps unix ;
Main pdfview : x11pdf.c ximage.c ;
LinkLibraries pdfview : libpdfapp $(FITZLIBS) ;
- LINKLIBS on pdfview$(SUFEXE) = $(LINKLIBS) $(X11LIBS) ;
+ LINKLIBS on pdfview$(SUFEXE) = $(LINKLIBS) $(APPLINKLIBS) ;
}
-if $(BUILD_PLUGIN) = yes
+if $(BUILD_PLUGIN)
{
SubDir TOP apps mozilla ;
SUFEXE on npmupdf.dll = ;
LINKFLAGS on npmupdf.dll = $(LINKFLAGS) -shared -Wl,--kill-at ;
- LINKLIBS on npmupdf.dll = $(LINKLIBS) -lgdi32 ;
+ LINKLIBS on npmupdf.dll = $(LINKLIBS) $(APPLINKLIBS) ;
Main npmupdf.dll : npwin.c moz_winres.rc moz_main.c ;
LinkLibraries npmupdf.dll : $(FITZLIBS) ;
}
diff --git a/apps/windows/winmain.c b/apps/windows/winmain.c
index b5fd2a67..cc7f3bdb 100644
--- a/apps/windows/winmain.c
+++ b/apps/windows/winmain.c
@@ -787,7 +787,7 @@ int main(int argc, char **argv)
winopen();
if (argc == 2)
- filename = strdup(argv[1]);
+ filename = fz_strdup(argv[1]);
else
{
if (!winfilename(buf, sizeof buf))
diff --git a/base/Jamfile b/base/Jamfile
index 95470425..b73797d8 100644
--- a/base/Jamfile
+++ b/base/Jamfile
@@ -11,9 +11,14 @@ Library libbase :
base_cleanname.c
;
-if $(NEED_GETOPT) = yes { Library libbase : util_getopt.c ; }
-if $(NEED_STRLCAT) = yes { Library libbase : util_strlcat.c ; }
-if $(NEED_STRLCPY) = yes { Library libbase : util_strlcpy.c ; }
-if $(NEED_STRSEP) = yes { Library libbase : util_strsep.c ; }
-if $(NEED_GETTIMEOFDAY) = yes { Library libbase : util_gettimeofday.c ; }
+Library libbase : util_getopt.c ;
+Library libbase : util_strlcat.c ;
+Library libbase : util_strlcpy.c ;
+Library libbase : util_strsep.c ;
+
+# MSVC does not have gettimeofday()
+if $(OS) = NT
+{
+ Library libbase : util_gettimeofday.c ;
+}
diff --git a/include/fitz/base_runtime.h b/include/fitz/base_runtime.h
index fc7ad920..4bd5cc91 100644
--- a/include/fitz/base_runtime.h
+++ b/include/fitz/base_runtime.h
@@ -12,26 +12,33 @@
#endif
#endif
-#undef nil
+#ifndef nil
#define nil ((void*)0)
+#endif
-#undef offsetof
+#ifndef offsetof
#define offsetof(s, m) (unsigned long)(&(((s*)0)->m))
+#endif
-#undef nelem
+#ifndef nelem
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
+#endif
-#undef ABS
+#ifndef ABS
#define ABS(x) ( (x) < 0 ? -(x) : (x) )
+#endif
-#undef MAX
+#ifndef MAX
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
+#endif
-#undef MIN
+#ifndef MIN
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
+#endif
-#undef CLAMP
+#ifndef CLAMP
#define CLAMP(x,a,b) ( (x) > (b) ? (b) : ( (x) < (a) ? (a) : (x) ) )
+#endif
#define MAX4(a,b,c,d) MAX(MAX(a,b), MAX(c,d))
#define MIN4(a,b,c,d) MIN(MIN(a,b), MIN(c,d))
@@ -64,10 +71,6 @@ void fz_printerror(fz_error *eo);
void fz_droperror(fz_error *eo);
void fz_warn(char *fmt, ...) __printflike(1,2);
-#ifdef WIN32
-#define __func__ __FUNCTION__
-#endif
-
#define fz_throw(...) fz_throwimp(nil, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define fz_rethrow(cause, ...) fz_throwimp(cause, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define fz_okay ((fz_error*)0)
diff --git a/include/fitz/base_sysdep.h b/include/fitz/base_sysdep.h
index 4e1e250a..49a7786a 100644
--- a/include/fitz/base_sysdep.h
+++ b/include/fitz/base_sysdep.h
@@ -2,7 +2,9 @@
* Include the basic standard libc headers.
*/
+#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <stdarg.h>
@@ -14,47 +16,19 @@
#include <errno.h>
#include <fcntl.h> /* O_RDONLY & co */
-#ifdef HAVE_C99
-# define FZ_FLEX
-#else
-# define FZ_FLEX 1
-# define restrict
-#ifdef _MSC_VER
-# define inline __inline
-#else
-# define inline __inline__
-#endif
-#endif
+/* Some useful (but not C99 standard) functions */
-#ifdef WIN32
-#if _MSC_VER < 1500
-# define vsnprintf _vsnprintf
-#endif
-# include <io.h>
-#else
-# include <unistd.h>
-#endif
-
-#ifndef va_copy
-#define va_copy(a,b) (a) = (b)
-#endif
-
-#ifndef R_OK
-#define R_OK 4
-#endif
+extern int strlcpy(char *dst, const char *src, int n);
+extern int strlcat(char *dst, const char *src, int n);
-#ifndef O_BINARY
-#define O_BINARY 0
-#endif
+extern char *strsep(char **stringp, const char *delim);
-/*
- * Extras! Extras! Get them while they're hot!
- */
+extern int getopt(int nargc, char * const * nargv, const char *ostr);
+extern int opterr, optind, optopt;
+extern char *optarg;
-/* not supposed to be here, but printf debugging sorta needs it */
-#include <stdio.h>
+/* Some useful (but not C99 standard) math macros */
-#ifdef NEED_MATH
#define M_E 2.71828182845904523536
#define M_LOG2E 1.44269504088896340736
#define M_LOG10E 0.434294481903251827651
@@ -69,26 +43,56 @@
#define M_2_SQRTPI 1.12837916709551257390
#define M_SQRT2 1.41421356237309504880
#define M_SQRT_2 0.707106781186547524401
+
+/*
+ * MSVC section
+ */
+
+#ifdef MSVC
+
+#include <io.h>
+
+extern int gettimeofday(struct timeval *tv, struct timezone *tz);
+
+#define FZ_FLEX 1
+#define restrict
+
+#ifdef _MSC_VER
+#define inline __inline
+#else
+#define inline __inline__
+#endif
+
+#define __func__ __FUNCTION__
+
+#if _MSC_VER < 1500
+#define vsnprintf _vsnprintf
+#endif
+
#ifndef isnan
#define isnan _isnan
#endif
-#endif
-#ifdef NEED_STRLCPY
-extern int strlcpy(char *dst, const char *src, int n);
-extern int strlcat(char *dst, const char *src, int n);
+#ifndef va_copy
+#define va_copy(a,b) (a) = (b)
#endif
-#ifdef NEED_STRSEP
-extern char *strsep(char **stringp, const char *delim);
+#ifndef R_OK
+#define R_OK 4
#endif
-#ifdef NEED_GETOPT
-extern int getopt(int nargc, char * const * nargv, const char *ostr);
-extern int opterr, optind, optopt;
-extern char *optarg;
+#ifndef O_BINARY
+#define O_BINARY 0
#endif
-#ifdef NEED_GETTIMEOFDAY
-extern int gettimeofday(struct timeval *tv, struct timezone *tz);
+/*
+ * C99 section
+ */
+
+#else
+
+#include <unistd.h>
+#define FZ_FLEX
+
#endif
+