# -*- Makefile -*-

# Add the location of the source code.
CXXINCLUDE += -I..

#include Makefile.compilers
CXX = g++
CXXFLAGS += $(CXXINCLUDE)
ifdef DEBUG
CXXFLAGS += -g -DDEBUG_stlib
else
# Optimization
# Improves performance by 3 or 4%. Should I use it?
#CXXFLAGS += -ffast-math
# Increase the inline limit from 600 to 6000.
CXXFLAGS += -finline-limit=6000
CXXFLAGS += -O3 -funroll-loops -Wstrict-aliasing
endif
# Language.
CXXFLAGS += -ansi -Wall
# Commented out for Eigen.
#CXXFLAGS += -pedantic

ifndef SOURCES
# The homogeneous sources have mass action solvers that can be pre-compiled.
SOURCES = $(wildcard Homogeneous*.cc)
endif
DEPENDENCIES = $(SOURCES:.cc=.d)
TARGETS = $(SOURCES:.cc=)

.SUFFIXES:
.SUFFIXES: .cc .d

# The default target.
install: all
	mv $(TARGETS) ../../solvers

all: $(TARGETS)

clean: 
	$(RM) *.o *.d *~ core* *.stackdump .DS_Store .Thumbs.db

distclean: 
	$(MAKE) clean 
	$(RM) $(TARGETS) $(DEPENDENCIES)

again: 
	$(MAKE) distclean 
	$(MAKE) 

# Implicit rules.

.cc.d: 
	$(CXX) -MM $(CXXINCLUDE) $< > $@.$$$$; \
  sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  $(RM) $@.$$$$

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),distclean)
-include $(DEPENDENCIES)
endif
endif
