CXX=g++
CFLAGS=-Wall -g -ggdb -O2
LDFLAGS=-lm
SOURCES=main.cxx variables.cxx cell.cxx grid.cxx solver.cxx timestep_constant.cxx march.cxx
STASH=grid-init.o
OBJECTS=$(SOURCES:.cxx=.o) $(STASH)
DEPENDS=$(OBJECTS:.o=.deps)
EXECUTABLE=frolov

all:
	@echo "syntax: make test-*"
	@echo "See Makefile in order to know the aims"

build: $(EXECUTABLE)

rebuild: $(STASH) stash clean unstash build

stash: $(STASH)
	mv $(STASH) stashed/

unstash: 
	cd stashed && mv $(STASH) .. && cd -

# tests
test-mono: 
	make grid-init-monotonous.o
	ln -f grid-init-monotonous.o grid-init.o
	make build

test-shock1: grid-init-shock1.o
	ln -f grid-init-shock1.o grid-init.o
	make build

test-shock2a: grid-init-shock2a.o
	ln -f grid-init-shock2a.o grid-init.o
	make build

test-shock2b: grid-init-shock2b.o
	ln -f grid-init-shock2b.o grid-init.o
	make build

# the main aim
$(EXECUTABLE): $(OBJECTS) 
	$(CXX) $(CFLAGS) $(LDFLAGS) $(OBJECTS) -o $@

# pull in dependency info for *existing* .o files
-include $(DEPENDS)

# compile and generate dependency info
%.o: %.cxx
	$(CXX) -c $(CFLAGS) $*.cxx -o $*.o
	$(CXX) -MM $(CFLAGS) $*.cxx > $*.deps

test-clean: clean-test
clean-test:
	find test/ -not \( -name "test" -o -name "README" -o -name "frolov" \) -delete

clean: clean-test
	rm -f $(EXECUTABLE) *.o *.deps