#************************************************************************************
#
#	@file		makefile
#	@brief		make file for sofa2json
#	@author     Thibaut Carpentier
#	@version    1.0.0
#	@date       18/07/2012
#
#************************************************************************************

#************************************************************************************
# source files.
SRC 		=  	../../src/sofa2json.cpp

#************************************************************************************
# where to build the .o files
BUILDDIR 	= .

#************************************************************************************
# object files
OBJ 		= 	$(SRC:.cpp=.o) 

#************************************************************************************
# output library
OUT 		= 	../../lib/sofa2json

#************************************************************************************
# header search paths
INCLUDES 	= 	-I/usr/include \
				-I../../src \
				-I../../dependencies/include

#************************************************************************************
# preprocessor macros
LIBSOFA_MACROS = 	     \
						-DLINUX=1 \
						-D__unix__=1 \
						-DHOST_ENDIAN_LITTLE=1

#************************************************************************************
# Warning levels
WARNING_CFLAGS	=   -Wno-unknown-pragmas -Wno-reorder -Wno-unused-value -Wno-unused

#************************************************************************************
# C++ compiler flags (-g -O2 -Wall)
CCFLAGS 		= 	$(LIBSOFA_MACROS)  \
					-g  \
					-O3  \
					$(WARNING_CFLAGS)

#************************************************************************************
# compiler
CCC 		= g++

#************************************************************************************
# library search paths
LDFLAGS 	= -L../../../libsofa/lib

#************************************************************************************
# linker flags
LDLIBS 		= -l:libsofa.a -lstdc++ -l:libnetcdf.a -l:libhdf5_hl.a -l:libhdf5.a -l:libcurl.a -lm -lz -l:libdl.a -l:libnetcdf_c++4.so -ljson-c


#************************************************************************************

.PHONY: depend clean

all:    $(OUT)
		@echo " "
		@echo  Build $(OUT) is OK !!
		@echo " "

$(OUT): $(OBJ) makefile_sofa2json
		@echo "Linking $(OUT) ... "
		$(CCC) -O -o $(OUT) $(OBJ) $(LDFLAGS) $(LDLIBS) 
	
# this is a suffix replacement rule for building .o's from .c's
# it uses automatic variables $<: the name of the prerequisite of
# the rule(a .c file) and $@: the name of the target of the rule (a .o file) 
# (see the gnu make manual section about automatic variables)
.cpp.o:
		@echo " "
		@echo " "
		@echo "Compiling $< ..."
		@echo " "
		$(CCC) $(CCFLAGS) $(INCLUDES) -c $<  -o $@
		@echo " "
		@echo " "

clean:
		@echo "Cleaning..."
		$(RM) $(OBJ) *~ $(OUT)

depend: $(SRC) 
		@echo "Generating dependencies for $^"
		makedepend $(INCLUDES) $^

# DO NOT DELETE THIS LINE -- make depend needs it	
		
