#####################################
# Makefile genérica
#  V. Santos, Oct-2011
####################################
#As minhas sources...  exemplos
SRC=mainfile.cpp arduino_serial.cpp arduino_interface.cpp
#O executável ... exemplo
PROG=arduino_calibrator
#O ficheiro de configuração de documentação (a gerar)
DOXYFILE=Doxyfile
#Header files (exemplos)
HEADERS=headerfile.h

################################
## Daqui para baixo não deve ser preciso mexer muito :-)

###definições (macros)
CC=g++
CFLAGS=-Wall 
#CFLAGS+=`pkg-config --cflags opencv`
#INCLUDE=-I.
OBJ=$(SRC:.cpp=.o)
#LIBS+=`pkg-config --libs opencv` -lm

#### MACRO updates

CFLAGS+=`pkg-config --cflags gtk+-2.0`
CFLAGS+=-ILibrary
LIBS+=`pkg-config --libs gtk+-2.0` -export-dynamic #TCP_client/libtcp_client.a
#LIBS+=-LLibrary
# The -export-dynamic (or -E flag in the linker) is required to export all dynamic symbols.
#-lfuncs estava acravado no fim do proto, a seguir ao LIBS

#### Targets

$(PROG): proto $(OBJ)
	$(CC) $(OBJ) -o $(PROG) $(LIBS) 

.cpp.o: 
	$(CC) $(CFLAGS) -c $(INCLUDE) $< -o $@

clean:
	rm -f $(PROG) $(OBJ)

allclean: clean
	rm -f $(OBJ)
	rm -rf latex html

depend:
	@#redirect output to /dev/null due to some bugs in makedepend :-(
	makedepend -Y $(SRC) 2> /dev/null

doc:
	@ if ! [ -f $(DOXYFILE) ] ; then \
		doxygen -g $(DOXYFILE) ; \
		cat $(DOXYFILE) |\
		sed 's/^PROJECT_NAME.*$$/PROJECT_NAME      = $(PROG)/'|\
		sed 's/^QUIET.*$$/QUIET      = YES/'|\
		sed 's/^GENERATE_TREEVIEW.*$$/GENERATE_TREEVIEW      = ALL/'|\
		sed 's/^GENERATE_LATEX.*$$/GENERATE_LATEX      = NO/'|\
		sed 's/^HAVE_DOT.*$$/HAVE_DOT      = YES/'\
		> $(DOXYFILE) ; \
		doxygen $(DOXYFILE) ; \
	else \
		doxygen $(DOXYFILE); \
	fi

#Generate a list of functions (useful for prototypes)
#notice the $$ to escape the Make interpretation of $
proto prototype.h:
	@echo /*File generated automatically. Do not edit*/ > prototype.h
 	@ ctags -x --c-kinds=f $(SRC) |\
 	grep -v main | \
 	awk '{for(n=5; n<=NF; n++) printf("%s ", $$n) ; printf(";\n");}' >> prototype.h

tags: $(SRC) $(HEADERS)
	ctags $(SRC) $(HEADERS)

#	Target to view the documentation
view:
	firefox html/index.html