######################################################################
# How to use this Makefile
#
# make		-- same as "make Opt"
# make Opt	-- build optimized executable in opt/
# make Gprof	-- build executable for profiling with gprof in gprof/
# make Debug	-- build executable for debugging with gdb in debug/
# make clean	-- clean generated files for optimized version
# make cleanall	-- clean generated files for all above versions, and
#                  dependency files.
######################################################################

# optional flags
#CP_OPTS += -I/opt/local/include
#LD_OPTS += -L/opt/local/lib
#LD_OPTS += -Wl,-stack_size,0x10000000

# the name of the C++ compiler
GPP=g++

# the default version
VERSION=opt

# set GPP_OPTS according to version
ifeq ($(VERSION),debug)
    GPP_OPTS = -O0 -ggdb -DDEBUG_SYM_NAMES #-DDEBUG_DEFEQ #-DDEBUG_SYMS  -DDEBUG_APPS -DDEBUG -DDEBUG_HOLES  -DDEBUG_HOLE_NAMES #-DDEBUG_LINES  # -DDEBUG #-DDEBUG_REFCNT #-DDEBUG_DEFEQ 
else
  ifeq ($(VERSION),gprof)
    GPP_OPTS = -O4 -pg
  else
    # optimized versions
    GPP_OPTS = -O4 #-DDEBUG_LINES
  endif
endif

GPP_OPTS += -w $(CP_OPTS)

DIR=./$(VERSION)

SRC= check.cpp expr.cpp code.cpp trie.cpp main.cpp scccode.cpp sccwriter.cpp libwriter.cpp print_smt2.cpp
DEP=$(patsubst %.cpp, $(DIR)/deps/%.d, $(SRC))
OBJ=$(patsubst %.cpp, $(DIR)/%.o, $(SRC))

all: 	$(DIR)/Makefile.d
	mkdir -p $(DIR)
	$(MAKE) VERSION=$(VERSION) $(DIR)/lfsc

Opt:	
	$(MAKE) VERSION=opt


	$(MAKE) VERSION=gprof

Debug:	
	$(MAKE) VERSION=debug

$(DIR)/lfsc: $(OBJ)
	$(GPP) $(GPP_OPTS) $(LD_OPTS) -o $(DIR)/lfsc $(OBJ) -lgmp 

$(DIR)/%.o : %.cpp
	$(GPP) $(GPP_OPTS) -c $< -o $@

$(DIR)/deps/%.d : %.cpp
	$(GPP) $(CP_OPTS) -MM -MF $@ -MT $(DIR)/$*.o -c $<

$(DIR)/deps/:
	mkdir -p $(DIR)/deps

$(DIR)/Makefile.d: $(DIR)/deps/ $(DEP)
	cat $(DEP) > $(DIR)/Makefile.d

clean:
	rm -f $(DIR)/sc $(OBJ)

cleanall:
	$(MAKE) clean
	$(MAKE) VERSION=gprof clean
	$(MAKE) VERSION=debug clean
	rm -f $(DIR)/Makefile.d $(DEP)

include $(DIR)/Makefile.d
