# author: isvoboda
# project: potted plant detector - vocabulary generator

# Compiler
CC				= g++

# CXXFLAGS - flags for compiler for c++ language 
CXXFLAGS 		= -Wall -fmessage-length=0

PPD_LIB_PATH	= ../ppd_library/

# Windows / Linux setting
ifeq ($(OS),Windows_NT)
	#Libraries - names in Windows system
	LIBS		= -lppd -lticpp -lopencv_highgui231 -lopencv_features2d231 -lopencv_imgproc231 -lopencv_core231 -lopencv_ml231
	
	# The include path for all languages of *.h and *.hpp
	CPPFLAGS	= -IC:\Users\isvoboda\Dropbox\Programs\OpenCv\OpenCv_2.3.1\include -I../ppd_library
	
	# Library path neede for linking on Windows
	LibraryPath	= -L..\ppd_library\XmlParser\lib -L"C:\Users\isvoboda\Dropbox\Programs\OpenCv\OpenCv_2.3.1\x86\mingw\lib" -L..\ppd_library
	Program 	= ppd_voc_gen.exe
	ERASE		= del
else
	MakeLib = ar
	#Libraries - names on Linux system
	LIBS		= -lppd -lticpp -lopencv_highgui -lopencv_features2d -lopencv_imgproc -lopencv_core -lopencv_ml 
	
	CPPFLAGS	= -I../ppd_library
	
	# Library path needed for linking on Linux
	LibraryPath = -L../ppd_library/XmlParser/lib -L../ppd_library
	Program 	= ppd_voc_gen
	ERASE		= rm -f
endif

OBJ				= main.o

all: release

#following rows @ can be used according to the spec., it is Target-specific Variable Values
release: CXXFLAGS += -O3 -mtune=core2 -fopenmp
release: PPD_LIB_BUILD = release
release: $(Program)

$(Program): MAKE_PPD_LIB $(OBJ)
	$(CC) -o $(Program) $(OBJ) $(LibraryPath) $(LIBS) -fopenmp

debug: CXXFLAGS += -O0 -g3
debug: LIBS += -lppdd
debug: PPD_LIB_BUILD = debug
debug: $(Program)

MAKE_PPD_LIB: 
	 $(MAKE) -C $(PPD_LIB_PATH) $(PPD_LIB_BUILD)

clean:
	$(ERASE) $(Program) $(OBJ)

# Not needed thanks to implicit rule
#main.o: main.cpp bow_generator.hpp
#bow_generator.o: bow_generator.cpp bow_generator.hpp read_dataset.hpp
#read_dataset.o: read_dataset.cpp read_dataset.hpp

#Shortcuts
# $@ : text in front of semicolon
# $< : Name of first prerequisit
# $< : Names of all prerequisits divided by space
# $? : Names of all prerequisits which are newer then target
# -c param of gcc to compile do not link
# -o fileName create file with fileName

# For *.o objects the implicit rule is used
# %.o: %.c
#	$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

# $(RM) - varibale of del-win (works with cygwin) and rm-linux
