#
# Jamrules -- build configurations
#
# The default build is for debugging. To compile a release
# build, add -sBUILD=release to the jam command line. To provide
# a custom build you can use any name you want instead of release
# or debug.
#
# 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
# in /usr/local or some other system known location.
#
# Linux builds assume that you have the freetype2 headers installed
# in /usr/include/freetype2.
#
# If the above assumptions are incorrect, please edit the relevant
# sections of this Jamrules file.
#
# JBIG2 and JPEG2000 support is optional. To compile with this,
# add the following to the jam command line:
#
#   -sHAVE_JBIG2DEC=true
#
#   -sHAVE_OPENJPEG=true
#
# To compile without builtin CJK CMap and font support, and save a few
# megabytes of executable space:
#
#   -sDEFINES=NOCJK 
#

# Workaround for different OS/OSPLAT settings on FTJam and plain jam
if $(JAM_TOOLSET) = MINGW   { OS = MINGW ; OSPLAT = x86 ; }
if $(JAM_TOOLSET) = VISUALC { OS = NT ; }

# detect amd64, which isn't in the outdated jambase :(
if $(OS) = NT {
	if $(Platform) = X64 {
		OSPLAT = amd64 ;
	} else {
		OSPLAT ?= x86 ;
	}
} else {
	OSPLAT ?= amd64 ;
}

BUILD ?= debug ;

# Place all build products here:
ALL_LOCATE_TARGET ?= [ FDirName $(TOP) build $(OS:L)-$(OSPLAT:L)-$(BUILD:L) ] ;

# Add compile time defines for JBIG2 and JPEG2000 support.
if $(HAVE_JBIG2DEC) { DEFINES += HAVE_JBIG2DEC ; }
if $(HAVE_OPENJPEG) { DEFINES += HAVE_OPENJPEG ; }

if $(OS) = LINUX
{
    Echo Building for LINUX ;

    BUILD_X11APP = true ;

    CCFLAGS = -Wall -std=gnu99 -I/usr/include/freetype2 ;
    LINKFLAGS = -L/usr/X11R6/lib ;
    LINKLIBS = -lfreetype -ljpeg -lz -lm ;
    APPLINKLIBS = -lX11 -lXext -lpthread ;

    if $(BUILD) = debug   { OPTIM = -g -O0 -fno-inline ; }
    if $(BUILD) = release { OPTIM = -O3 ; }

    if $(HAVE_JBIG2DEC)	{ LINKLIBS += -ljbig2dec ; }
    if $(HAVE_OPENJPEG)	{ LINKLIBS += -lopenjpeg ; }
}

if $(OS) = MACOSX
{
    Echo Building for MACOSX ;

    BUILD_X11APP = true ;

    CCFLAGS = -Wall -std=gnu99 ;
    LINKFLAGS = -L/usr/X11R6/lib ;
    LINKLIBS = -lfreetype -ljpeg -lz -lm ;
    APPLINKLIBS = -lX11 -lXext ;

    if $(BUILD) = debug   { OPTIM = -g -O0 -fno-inline ; }
    if $(BUILD) = release { OPTIM = -O3 ; }

    if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
    if $(HAVE_OPENJPEG)	{ LINKLIBS += -lopenjpeg ; }
}

if $(OS) = MINGW
{
    Echo Building for MINGW ;

    NOARSCAN = true ;

    BUILD_WINAPP = true ;
    BUILD_PLUGIN = true ;

    CCFLAGS = -Wall -std=gnu99 -Ic:/msys/1.0/local/include ;
    LINKFLAGS = -Lc:/msys/1.0/local/lib ;
    LINKLIBS = -lfreetype -ljpeg -lz -lm ;
    APPLINKLIBS = -lgdi32 -lcomdlg32 -luser32 -ladvapi32 -lshell32 ;

    if $(BUILD) = debug   { OPTIM = -g -O0 -fno-inline ; }
    if $(BUILD) = release { OPTIM = -O3 ; APPLINKLIBS += -mwindows ; }

    if $(HAVE_JBIG2DEC) { LINKLIBS += -ljbig2dec ; }
    if $(HAVE_OPENJPEG)	{ LINKLIBS += -lopenjpeg ; }

    actions WindRes { windres -i $(>) -o $(<) --include-dir=$(>:D) }
}

if $(OS) = NT
{
    Echo Building for MSVC ;

    DEFINES += MSVC ;

    BUILD_WINAPP = true ;

    CCFLAGS = /I../msvc-include ;
    LINKFLAGS = /LIBPATH:../msvc-lib-$(OSPLAT)
	/NODEFAULTLIB:LIBCMTD /NODEFAULTLIB:MSVCRT ;
    LINKLIBS = freetype.lib libjpeg.lib zlib.lib ;
    APPLINKLIBS = gdi32.lib comdlg32.lib user32.lib shell32.lib ;

    if $(BUILD) = debug   { }
    if $(BUILD) = release { OPTIM = /O2 ; }

    if $(HAVE_JBIG2DEC) { LINKLIBS += jbig2dec.lib ; }
    if $(HAVE_OPENJPEG)	{ LINKLIBS += openjpeg.lib ; }

    actions WindRes { rc /fo $(<) $(>) }
}

# WindRes rule for compiling the windows viewer and plugin

rule UserObject
{
    switch $(>)
    {
	case *.rc : WindRes $(<) : $(>) ;
	case * : Echo "unknown suffix on" $(>) ;
    }
}

rule WindRes
{
    Depends $(<) : $(>) ;
    Clean clean : $(<) ;
}

