# --------------------- INFORMATION --------------------------------

# This the DDS Makefile for Windows and the Cygwin GNU g++
# compiler.  It assumes a Unix-like setup for some commands.

# The "windres" and "cvtres" tools are used for putting version
# information into the DLL in a way that Windows can see.
# It is not mandatory, and if you don't have those tools,
# You can remove $(VFILE).obj in the target line below.

# --------------------- CONFIGURATION ------------------------------

# You can configure the following:

# 1. The threading systems that you want in the DLL/executable.
# You will always get single-threading.  If you have multiple
# threading systems, the default will be the multi-threading one
# with the lowest number (see System.cpp).  All that matters is
# CC_THREADING.

# GCD doesn't work on Windows.
THR_WINAPI	= -DDDS_THREADS_WINAPI
THR_OPENMP	= -DDDS_THREADS_OPENMP
THR_GCD		= -DDDS_THREADS_GCD
THR_BOOST	= -DDDS_THREADS_BOOST
THR_STL		= -DDDS_THREADS_STL
THR_TBB		= -DDDS_THREADS_TBB
THR_STLIMPL	= -DDDS_THREADS_STLIMPL
THR_PPLIMPL	= -DDDS_THREADS_PPLIMPL

THREADING	= $(THR_BOOST) $(THR_OPENMP) $(THR_WINAPI) $(THR_STL)

# If you need to add something for a threading system, this is
# the place.

CC_BOOST_LINK	= -lboost_system -lboost_thread

THREAD_COMPILE	= -fopenmp
THREAD_LINK	= $(CC_BOOST_LINK)

# 2. Debugging options.  (There are more granular options in debug.h.)

DEBUG_ALL	= -DDDS_DEBUG_ALL 
TIMING		= -DDDS_TIMING
SCHEDULER	= -DDDS_SCHEDULER

# All that matters from no. 2 and no. 3 is the following.  Here you
# can add $(SMALL_MEMORY) etc.

DDS_BEHAVIOR	=

# ----------------------- OFTEN OK    ------------------------------

# From here on you you don't have to change anything to CONFIGURE
# the compilation.  But you may well have to change something to 
# get it to compile.

INCL_SOURCE	= Makefiles/sources.txt
INCL_DEPENDS	= Makefiles/depends_o.txt

# If your compiler name is not given here, change it.
CC		= g++

# We compile with aggressive warnings, but we have to turn off some
# of them as they appear in libraries in great numbers...

WARN_FLAGS	= 		\
	-Wshadow 		\
	-Wsign-conversion 	\
	-pedantic -Wall -Wextra  \
	-Wcast-align -Wcast-qual \
	-Wctor-dtor-privacy 	\
	-Wdisabled-optimization \
	-Wformat=2 		\
	-Winit-self 		\
	-Wlogical-op 		\
	-Wmissing-declarations 	\
	-Wmissing-include-dirs 	\
	-Wnoexcept 		\
	-Wold-style-cast 	\
	-Woverloaded-virtual 	\
	-Wredundant-decls 	\
	-Wsign-promo 		\
	-Wstrict-null-sentinel 	\
	-Wstrict-overflow=1 	\
	-Wswitch-default -Wundef \
	-Werror 		\
	-Wno-unused 		\
	-Wno-unknown-pragmas 	\
	-Wno-long-long

COMPILE_FLAGS	= -O3 -flto -fopenmp -mtune=generic -fno-use-linker-plugin \
		$(WARN_FLAGS) \
		$(DDS_BEHAVIOR) $(THREAD_COMPILE) $(THREADING)

LINK1_FLAGS	= -shared -fopenmp
LINK2_FLAGS	= 		\
	-Wl,--subsystem,windows \
	-Wl,--output-def,$(DLLBASE).def	\
	-Wl,--dynamicbase 	\
	-Wl,--nxcompat 		\
	-Wl,--no-seh 		\
	-Wl,--enable-stdcall-fixup \
	$(THREAD_LINK)

DLLBASE		= dds
DLL 		= $(DLLBASE).dll
DLIB 		= $(DLLBASE).lib
EXPORTER	= Exports.def

VFILE		= ddsres
WINDRES_FLAG	= 

include $(INCL_SOURCE)

O_FILES 	= $(subst .cpp,.o,$(SOURCE_FILES)) $(VFILE).o

cygwin:	$(O_FILES)
	$(CC) $(LINK1_FLAGS) $(O_FILES) \
	$(LINK2_FLAGS) $(EXPORTER) -o $(DLL)

%.o:	%.cpp
	$(CC) $(COMPILE_FLAGS) -c $<

$(DLLBASE).res:	$(DLLBASE).rc
	windres $(DLLBASE).rc $(DLLBASE).res

$(VFILE).o:	$(DLLBASE).rc
	windres $(WINDRES_FLAG) $(DLLBASE).rc $(VFILE).o

depend:
	makedepend -Y -- $(SOURCE_FILES)

clean:
	rm -f $(O_FILES) $(DLL) $(DLLBASE).{lib,def,exp,res}

install:
	test -d ../test || mkdir ../test
	test -d ../examples || mkdir ../examples
	cp $(DLL) $(DLLBASE).def ../test
	cp $(DLL) $(DLLBASE).def ../examples

# If you don't have a Linux-like setup, use "del" instead of "rm
# and "copy" instead of "cp".

include $(INCL_DEPENDS)

