#
# Common makefile include for tks-source and plugins
#  (requires MSYS shell, MSVC and GNU make)
#


#
# Where to install tks
#   (creates 
#         $(TKS_SITE_PREFIX)/plugins
#         $(TKS_SITE_PREFIX)/libraries
#         $(TKS_SITE_PREFIX)/applications
#         $(TKS_SITE_PREFIX)/modules 
#         directories,
#    copies tks.exe to $(TKS_SITE_PREFIX)/tks.exe
#    )
#
TKS_PREFIX=../../
#/c/Program Files/tks
TKS_SITE_PREFIX=$(TKS_PREFIX)


# 
# Number of parallel targets to make
# 
NUMJOBS=$(NUMBER_OF_PROCESSORS)
#NUMJOBS=4


#
# Set to 'y' to use shared "msvcrtXX.dll"
# (decreases file size considerably but requires the user to have e.g. msvcrt90.dll
#  installed)
# (if unsure, choose 'y')
#
#USE_SHARED_MSVCRT=y
USE_SHARED_MSVCRT=n


#
# Set this to != 'n' to use VC/Platform libs from WinDDK
#  (requires USE_SHARED_MSVCRT=y)
#  (This is used to get of the "dll hell" msvcrtXX.dll dependencies)
#  (this disables compiler security checks because _security_check_cookie() 
#   does not seem to be exported by this version of msvcrt)
#
#WINDDK_PATH=h:/dev/winddk_msvcrt/3790.1830
WINDDK_PATH=n


#
# Set to 'y' to use shared "zlib1.dll"
# (otherwise compile and statically link zlib sources)
# (if unsure, choose 'y' because zlib is also used by the tkopengl plugin)
#
USE_SHARED_ZLIB=y


#
# Set to 'y' to use shared libpng.dll
#  (otherwise compile and statically link libpng sources)
#  (actually you need to keep this set to 'n' on Win32
#   since the official libpng Win32 binaries are for GCC
#   and I've been too lazy to build the .dll myself ._°)
#
USE_SHARED_LIBPNG=n


#
# Common source directory for 3rd party libs (libpng, zlib)
#
# Now this is a bit tricky: The directory name MUST use the
# MSDOS style drive:/path naming convention, NOT the MSYS
# /drive/path one! (required by the MSVC compiler)
#
OTHER_SRC=h:/sources


#
# Path to zlib sources (required if USE_SHARED_ZLIB != y)
#  (zlib123.zip distribution)
#
ZLIB_SRC=$(OTHER_SRC)/zlib123


#
# Path to zlib binaries (required if USE_SHARED_ZLIB=y)
#  (zlib123-dll.zip distribution)
#
ZLIB_BIN=$(OTHER_SRC)/zlib123-dll


#
# Path to libpng sources (required if USE_SHARED_LIBPNG != y)
#  (lpng1235.zip)
#  (Note: you may need to fix "fileno" to "_fileno" in pngwio.c:140
#         because of ISO-C++ compliance)
#
LIBPNG_SRC=$(OTHER_SRC)/lpng1235


#
# Set this to the Visual Studio installation directory.
# Includes/libraries will be searched in $VCTK/include and $VCTK/lib
#
VCTK=c:/Program Files/Microsoft Visual Studio 9.0/VC



#
# Set this to the platform SDK installation directory
#
#W32API=d:/Programme/Microsoft Platform SDK
#W32API=f:/fli/tools/dev/MSVCTK2003/w32api
#W32API=c:/Programme/Microsoft Platform SDK
W32API=c:/Program Files/Microsoft SDKs/Windows/v6.0a


#
# Set this to the DirectX SDK installation directory
#
#DXSDK_LIB=f:/fli/tools/dev/MSVCTK2003/w32api/lib
#DXSDK_LIB=c:/Programme/Microsoft DirectX SDK (December 2005)/lib/x86
#DXSDK_LIB='c:/Programme/Microsoft DirectX SDK (August 2006)/Lib/x86'
DXSDK_LIB=c:/Program Files/Microsoft DirectX SDK (August 2008)/Lib/x86

#DXSDK_INC=f:/fli/tools/dev/MSVCTK2003/w32api/include
#DXSDK_INC=c:/Programme/Microsoft DirectX SDK (December 2005)/include
#DXSDK_INC='c:/Programme/Microsoft DirectX SDK (August 2006)/Include'
DXSDK_INC=c:/Program Files/Microsoft DirectX SDK (August 2008)/Include



#
# Tool setup
#
CC        = "$(VCTK)/bin/cl.exe"
LD        = "$(VCTK)/bin/link.exe"
LIB       = "$(VCTK)/bin/lib.exe"
CP        = cp -f
MAKE      = make
FIND      = /c/msys/1.0/bin/find.exe
MKDIR     = mkdir -p
RM        = rm -f
SED       = sed
TKS       = "$(TKS_PREFIX)/syntracker2.exe"  -ap ../../applications/
ZIP       = zip
MD5SUM    = md5sum
#
# UPX binary [optional]
#  (Note: UPX303w crashes without -q option during parallel build (-j 4))
#
#UPX=/h/fli/tools/dev/upx304w/upx.exe -q
UPX=/h/fli/tools/dev/upx303w/upx.exe -q




#
# C compiler flags
#
#CFLAGS= -nologo -W3 -Zp8 -GR- -EHs-c- -D_CRT_SECURE_NO_DEPRECATE -DWIN32 -MP4
CFLAGS= -nologo -W3 -Zp8 -GR- -EHs-c- -D_CRT_SECURE_NO_DEPRECATE -DWIN32 
#-MP4
#-fp:fast
####CFLAGS= -nologo -W3 -Zp8 -GR- -EHs-c- -D_CRT_SECURE_NO_DEPRECATE -DWIN32 -MT -MP4
####CFLAGS= -nologo -W3 -Zp8 -GR- -D_CRT_SECURE_NO_DEPRECATE -DWIN32 -MD -MP4


#
# C++ compiler flags
#
CPPFLAGS= $(CFLAGS)


#
# Default linker flags
#
LDFLAGS= -INCREMENTAL:NO -MACHINE:X86 -VERSION:0.9 
#LDFLAGS= -INCREMENTAL:NO -MACHINE:X86 -VERSION:0.9 -DEBUG -FIXED:NO


#
# Size optimization linker flags (used by plugins)
#
LDFLAGS_SIZE=
#LDFLAGS_SIZE= -MACHINE:X86 -VERSION:0.9 -OPT:REF -OPT:ICF=10 -LTCG -INCREMENTAL:NO -NOASSEMBLY -SUBSYSTEM:CONSOLE 
#####-FORCE 
#####-NODEFAULTLIB:LIBCMT 
#####-OPT:NOWIN98 -NODEFAULTLIB


#
# Extra includes
#
EXTRA_INCLUDES=


#
# Extra library paths
#
EXTRA_LIBS=


#
# Default Optimization flags
#
OPTFLAGS= -Ox -Ot
#OPTFLAGS= -Od -D_DEBUG

#-Ox
#OPTFLAGS  = /Os /O1
#/Oy 
#/fp:strict /GS-


#
# Size optimization flags (used by plugins)
#
OPTFLAGS_SIZE= -Os -GL -GF -Gy -GA


#
# Which flags to use for plugins
#
#OPTFLAGS_PLUGIN = $(OPTFLAGS_SIZE)
OPTFLAGS_PLUGIN = $(OPTFLAGS)


#
# Debug flags
#
DBGFLAGS=


#
# Do not define if msvcrt is missing hypotf() (old versions only)
# Set to 'y' if it has.
#
#HAVE_HYPOTF=y



#
# Nothing to change after this line-----------------------------
#
CFLAGS+= $(EXTRA_INCLUDES) $(DBGFLAGS)
CPPFLAGS+= $(EXTRA_INCLUDES) $(DBGFLAGS)
LDFLAGS+= $(EXTRA_LIBS)

# hack for portaudio plugin 
#  (uses alloca resulting in unresolved __alloca_probe_16 reference)
ifeq ($(FORCE_NO_WINDDK),y)
WINDDK_PATH=n
endif


ifeq ($(USE_SHARED_MSVCRT),y)
# link runtime libs dynamically..
SHARED_MSVCRT_CFLAGS = -MD
ifneq ($(WINDDK_PATH),n)
# ..using WinDDK
SHARED_MSVCRT_LDFLAGS =  -LIBPATH:"$(WINDDK_PATH)/lib/crt/i386" -LIBPATH:"$(WINDDK_PATH)/lib/wxp/i386" msvcrt.lib kernel32.lib bufferoverflow.lib ntdll.lib
SHARED_MSVCRT_CFLAGS += -I"$(WINDDK_PATH)/inc/crt" -I"$(WINDDK_PATH)/inc/wxp" -QIfist -DDX_NEED_FPUFIX
else
# ..using VC install + Platform SDK
SHARED_MSVCRT_LDFLAGS =   -LIBPATH:"$(VCTK)/lib" -LIBPATH:"$(W32API)/lib" msvcrt.lib kernel32.lib
SHARED_MSVCRT_CFLAGS += -I"$(VCTK)/include" -I"$(W32API)/include"
endif # WINDDK_PATH
else
# link runtime libs statically
SHARED_MSVCRT_CFLAGS = -MT -I"$(VCTK)/include" 
SHARED_MSVCRT_LDFLAGS = -LIBPATH:"$(VCTK)/lib" -LIBPATH:"$(W32API)/lib" 
endif # USE_SHARED_MSVCRT

LDFLAGS += $(SHARED_MSVCRT_LDFLAGS)
LDFLAGS_SIZE += $(SHARED_MSVCRT_LDFLAGS)
CFLAGS += $(SHARED_MSVCRT_CFLAGS)
CPPFLAGS += $(SHARED_MSVCRT_CFLAGS)


#
# HYPOTF emulation (tkmath)
#
ifeq ($(HAVE_HYPOTF),y)
CFLAGS += -DHAVE_HYPOTF
CPPFLAGS += -DHAVE_HYPOTF
endif
