# ----------------------------------------------------------
# Makefile based on gmake for compiling the project
# still lacks some features (building proto and tarball)
# ----------------------------------------------------------



# ----------------------------------------------------------
# file lists
#C_SRCS = $(wilcard *.c)
C_SRCS = mersenne.c utilities.c problem.c solution.c \
         local.c local2.c genetic.c exact.c main.c

C_OBJS = $(patsubst %.c, %.o, $(C_SRCS))

EXEC = biclique


# ----------------------------------------------------------
# compiler and related options
CC     = mpicc
CFLAGS = -std=c99 -Wall
#CFLAGS =  -std=c99 -Wall -ansi -pedantic
LFLAGS =
VFLAGS = -v --tool=memcheck --leak-check=yes --show-reachable=yes

MYDATE := `date +%Y%m%d`
MYDIR  := $(notdir $(CURDIR))/


# ----------------------------------------------------------
# CPLEX include and link options
SYSTEM     = x86_RHEL3.0_3.2
LIBFORMAT  = static_pic

COPT       = -fPIC
CPLEXDIR      = /usr/ilog/cplex91
CPLEXLIBDIR   = $(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT)
CLNFLAGS      = -lm
CPLEXINCDIR   = $(CPLEXDIR)/include
CFLAGS        += $(COPT) -I$(CPLEXINCDIR)


# ----------------------------------------------------------
# conditional insertion of dependancies
ifeq (Makefile.depend, $(wildcard Makefile.depend))
  all :: $(EXEC)
  include Makefile.depend
else
  all :: depend $(EXEC)
endif


# ----------------------------------------------------------
# compilation rules

%.o : %.c
	@echo "   obj file : "$*.c
	@$(CC) -c $(CFLAGS) $*.c -o $*.o

$(EXEC) : $(C_OBJS)
	@echo "   exe file : "$(EXEC)
	@$(CC) -o  $(EXEC) $(C_OBJS) $(LFLAGS) $(CLNFLAGS)


debug: CFLAGS += -g
debug:: clean $(C_OBJS)
	@echo "   building the debug version..."
	@$(CC) -o  $(EXEC) $(C_OBJS) $(LFLAGS) $(CLNFLAGS)

#release: CFLAGS += -fvisibility
release: CFLAGS += -O2 -D __NO_CHECK__
release:: clean $(C_OBJS)
	@echo "   building the release..."
	@echo "   exe file : "$(EXEC)
	@$(CC) -o  $(EXEC) $(C_OBJS) $(LFLAGS) $(CLNFLAGS)
	strip  $(EXEC)

stddebug: $(EXEC)
	@$(MAKE) valgrind PARAMS='Gtc20-1_2.txt 4 4 0.2 0.2 1000 123 1499'

valgrind: $(EXEC)
	@echo " running memory check with "$(PARAMS)
	@valgrind $(VFLAGS) $(EXEC) $(PARAMS)

depend:: Makefile.depend

#Makefile.depend : parameters.c
Makefile.depend :
	@echo "   generating dependencies for ${EXEC}..."
	@$(CC) -MM $(C_SRCS) -I$(CPLEXINCDIR) > Makefile.depend


exclude:
	@touch exclude
	@echo $(MYDIR)DATA > exclude
	@echo $(MYDIR)DATA_PEDRO >> exclude

archive:: clean exclude
	@echo "   archiving working directory "$(MYDIR)"..."
	@cd .. ; tar zcfX $(EXEC)_$(MYDATE).tgz $(MYDIR)/exclude $(MYDIR)

full_archive:: clean
	@echo "   archiving working directory "$(MYDIR)"..."
	@cd .. ; tar zcf $(EXEC)_$(MYDATE).tgz $(MYDIR)

clean::
	@echo "   cleaning trash files"
	@rm -f core *~
	@echo "   cleaning obj files"
	@rm -f $(C_OBJS)
	@echo "   cleaning exe files"
	@rm -f $(EXEC)
	@echo "   removing the dependency file"
	@rm -f Makefile.depend

run:: $(EXEC)
	@echo "   running default command line"
	@$(EXEC) Gtc20-1_2.txt 4 4 0.2 0.2 1000 123 1499
