#####################################
# Makefile genérica
#  V. Santos, 30-Sep-2009,11:04
####################################
#As minhas sources...
SRC=main.c
#O executável
PROG=out
#O ficheiro de configuração de documentação (a gerar)
DOXYFILE=Doxyfile

#Generates dependencies of object on sources and headers
#Can be useful to use later
#GCC -MM $(SRC)  > rules.mk
#And also to include in makefile
#include rules.mk

#Also useful a way to increment an existing macro :-)
# CFLAGS += -Werror


################################
## Daqui para baixo em geral não deve ser preciso mexer muito
###definições (macros)
CC=gcc
CFLAGS=-Wall
OBJ=$(SRC:.c=.o)
LIBS= -lm
INCLUDE=

#### Targets

$(PROG): prototypes.h $(OBJ)
	$(CC) $(OBJ) -o $(PROG) $(LIBS)

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

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

allclean: clean
	rm -f $(DOXYFILE)
	rm -rf latex html
	rm -f prototypes.h

doc:
	@ if ! [ -f $(DOXYFILE) ] ; then \
		doxygen -g $(DOXYFILE) ; \
		cat $(DOXYFILE) |\
		sed 's/^PROJECT_NAME.*$$/PROJECT_NAME      = $(PROG)/'|\
        sed 's/^SOURCE_BROWSER.*$$/SOURCE_BROWSER  = YES/'|\
        sed 's/^INLINE_SOURCES.*$$/INLINE_SOURCES  = YES/'|\
		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

#A rule simply to force prototypes.h to update
proto: prototypes.h

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


