########################################################### 
# This is a generic Makefile that takes all .cpp files
# in the directory, compiles them to .o files with
# their dependencies and then links all the .o 
# files together.
###########################################################
# have compiler flag -g for debugging

FILES= $(basename $(wildcard *.cpp))
O_FILES = $(addsuffix .o,$(FILES))
CPP=g++
CPPFLAGS= -Wall -ansi -pedantic -O3
# could be using all kinds of nifty compiler settings ...
# -O9 -funroll-loops -ffast-math -fomit-frame-pointer -malign-double -finline-functions -fno-exceptions

all: gls+
gls+: $(O_FILES)
	$(CPP) $(CPPFLAGS) $(O_FILES) -o gls+ -lm

clean:
	rm *.o
	rm rbsls

###########################################################
# The following rules extract the dependencies from 
# the .cpp files, such that nothing remains to be 
# done manually.
###########################################################
%.d: %.cpp
	@set -e; rm -f $@; \
	 $(CPP) -MM $(CPPFLAGS) $< \
	 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' > $@

%.o: %.cpp
	$(CPP) -c $(CPPFLAGS) $<
