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

# This the DDS Makefile for MacOS and the g++ compiler.
# It creates a dynamically linked (shared) library, libdds.so.

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

# You can configure the following:

# 1. The threading systems that you want in the library.
# 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 and WINAPI don't work on Windows.
THR_BOOST	= -DDDS_THREADS_BOOST
THR_GCD		= -DDDS_THREADS_GCD
THR_OPENMP	= -DDDS_THREADS_OPENMP
THR_WINAPI	= -DDDS_THREADS_WINAPI
THR_STL		= -DDDS_THREADS_STL

THREADING	= $(THR_OPENMP) $(THR_STL)

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

THREAD_COMPILE	= 
THREAD_LINK	= -lgomp

# 2. The small memory option, which causes DDS to consume a lot less
# memory and to run somewhat more slowly.

SMALL_MEMORY	= -DSMALL_MEMORY_OPTION

# 3. 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		= gcc-4.9

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

WARN_FLAGS	= 		\
         -fno-use-linker-plugin \
	-Wshadow 		\
	-Wsign-conversion 	\
	-pedantic -Wall -Wextra  \
	-Wcast-align -Wcast-qual \
	-Wctor-dtor-privacy 	\
	-Wdisabled-optimization \
	-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		\
	-Wno-format

COMPILE_FLAGS	= -fPIC -O3 -flto -mtune=generic -Wno-write-string \
		-fopenmp -std=c++11 \
		$(WARN_FLAGS) 	\
		$(DDS_BEHAVIOR) $(THREAD_COMPILE) $(THREADING)

DLLBASE		= dds
SHARED_LIB	= lib$(DLLBASE).so

LINK_FLAGS	=		\
	-shared			\
	$(THREAD_LINK)		\
	-fPIC

include $(INCL_SOURCE)

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


macos:	$(O_FILES)
	$(CC) -o $(SHARED_LIB) $(O_FILES) $(LINK_FLAGS) -lstdc++

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

depend:
	makedepend -Y -- $(SOURCE_FILES)

clean:
	rm -f $(O_FILES) $(SHARED_LIB)

install:
	test -d ../test || mkdir ../test
	test -d ../examples || mkdir ../examples
	cp $(SHARED_LIB) ../test
	cp $(SHARED_LIB) ../examples

include $(INCL_DEPENDS)

