#common directives

#
# set $(sources) to list all source files (*.h *.cc Makefile...)
# first: be the first TAG
# $(TAR) file di TAR
#

first_tag: first

version:
	@echo package $(DIRNAME) CPPFLAGS $(CPPFLAGS)

DIRNAME=$(notdir $(CURDIR))

CPPFLAGS+= -Wall

ifeq ($(findstring -rev,$DIRNAME),)
  ## WORKING VERSION 
  COMMON_CPPFLAGS+= -g
else
  ## FINAL VERSION
  COMMON_CPPFLAGS+= -DNDEBUG -O3
endif

TAR=$(DIRNAME).tgz

-include $(filter %.d, $(sources:.cc=.d))

%.d: %.cc
	set -e; $(CXX) -MM $(CPPFLAGS) $< \
	| sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $@; \
	[ -s $@ ] || rm -f $@

clear.common:
	rm -f *.o *~ delme* *.d $(TAR)
	for file in "" $(filter-out $(sources),$(wildcard *)) ; do \
	  if [ -f "$$file" ] ; then rm -i "$$file" ; fi; done

tar.common:
	tar -C .. -czf $(TAR) \
	$(patsubst %,$(DIRNAME)/%,$(sources))

## fine common

