#===========================================================================#
#                                                                           #
# This file is part of the SYMPHONY MILP Solver Framework.                  #
#                                                                           #
# SYMPHONY was jointly developed by Ted Ralphs (ted@lehigh.edu) and         #
# Laci Ladanyi (ladanyi@us.ibm.com).                                        #
#                                                                           #
# The author of this file is Menal Guzelsoy                                 #
#                                                                           #
# (c) Copyright 2006-2015 Lehigh University. All Rights Reserved.           #
#                                                                           #
# This software is licensed under the Common Public License. Please see     #
# accompanying file for terms.                                              #
#                                                                           #
#===========================================================================#

# $Id: Makefile.Application.in 726 2006-04-17 04:16:00Z andreasw $

##########################################################################
#  Usually, you don't have to change anything in this file.              #
##########################################################################

EXE = $(MASTERNAME)@EXEEXT@

# The following is necessary under cygwin, if native compilers are used
CYGPATH_W = @CYGPATH_W@

# Directory with COIN header files
COININCDIR = @abs_include_dir@/coin

# Directory with COIN libraries
COINLIBDIR = @abs_lib_dir@

# Directory with Application files
SYMAPPLDIR = @abs_source_dir@/Applications/$(SYMAPPLNAME)

# Directory for application obj files
SYMAPPLOBJDIR = src

COIN_HAS_PKGCONFIG = @COIN_HAS_PKGCONFIG_TRUE@TRUE

SYM_COMPILE_IN_TM = @SYM_COMPILE_IN_TM_TRUE@TRUE
SYM_COMPILE_IN_LP = @SYM_COMPILE_IN_LP_TRUE@TRUE
SYM_COMPILE_IN_CP = @SYM_COMPILE_IN_CP_TRUE@TRUE
SYM_COMPILE_IN_CG = @SYM_COMPILE_IN_CG_TRUE@TRUE
USE_CGL_CUTS = @USE_CGL_CUTS_TRUE@TRUE
CLP_LP_SOLVER = @CLP_LP_SOLVER_TRUE@TRUE
GLPK_LP_SOLVER = @GLPK_LP_SOLVER_TRUE@TRUE
CPLEX_LP_SOLVER = @CPLEX_LP_SOLVER_TRUE@TRUE
OSL_LP_SOLVER = @OSL_LP_SOLVER_TRUE@TRUE
SOPLEX_LP_SOLVER = @SOPLEX_LP_SOLVER_TRUE@TRUE
XPRESS_LP_SOLVER = @XPRESS_LP_SOLVER_TRUE@TRUE
SYM_PARALLEL = @SYM_PARALLEL_TRUE@TRUE
CHECK_CUT_VALIDITY = @CHECK_CUT_VALIDITY_TRUE@TRUE
USE_GMPL = @USE_GMPL_TRUE@TRUE
MASTEREXT = @MASTEREXT@
LPEXT = @LPEXT@
TMEXT = @TMEXT@

##############################################################################
# This section is for listing CNRP source file names
##############################################################################

VPATH = \
        $(SYMAPPLDIR) \
	$(SYMAPPLDIR)/src/Common \
	$(SYMAPPLDIR)/src/DrawGraph \
	$(SYMAPPLDIR)/src/Master \
	$(SYMAPPLDIR)/src/CutPool \
	$(SYMAPPLDIR)/src/CutGen \
	$(SYMAPPLDIR)/src/LP

USER_COMMON_FILES += $(ADDFILES)

ALL_FILES  = $(USER_COMMON_FILES) \
	     $(USER_MASTER_FILES) \
	     $(USER_TM_FILES) \
	     $(USER_LP_FILES) \
	     $(USER_CG_FILES) \
	     $(USER_CP_FILES) \

ALL_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix .@OBJEXT@, $(ALL_FILES)))

PUSER_MASTER_FILES  = $(USER_MASTER_FILES) $(USER_COMMON_FILES)
PUSER_TM_FILES      = $(USER_TM_FILES)
PUSER_LP_FILES      = $(USER_LP_FILES)
PUSER_CP_FILES      = $(USER_CP_FILES)
PUSER_CG_FILES      = $(USER_CG_FILES)
PUSER_LP_FILES      = $(USER_LP_FILES)

ifeq ($(SYM_COMPILE_IN_CG),TRUE)
PUSER_LP_FILES      += $(USER_CG_FILES)
else
PUSER_CG_FILES      += $(USER_COMMON_FILES)
endif

ifeq ($(SYM_COMPILE_IN_LP),TRUE)
PUSER_TM_FILES       = $(PUSER_LP_FILES) 
else
PUSER_LP_FILES      += $(USER_COMMON_FILES)
endif

ifeq ($(SYM_COMPILE_IN_CP),TRUE)
PUSER_TM_FILES      += $(PUSER_CP_FILES) 
else
PUSER_CP_FILES       += $(USER_COMMON_FILES)
endif

ifeq ($(SYM_COMPILE_IN_TM),TRUE)
PUSER_MASTER_FILES  += $(PUSER_TM_FILES)
else
PUSER_TM_FILES      += $(USER_COMMON_FILES)
endif

PUSER_MASTER_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix _p.@OBJEXT@, $(PUSER_MASTER_FILES)))
PUSER_LP_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix _p.@OBJEXT@, $(PUSER_LP_FILES)))
PUSER_CG_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix _p.@OBJEXT@, $(PUSER_CG_FILES)))
PUSER_CP_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix _p.@OBJEXT@, $(PUSER_CP_FILES)))
PUSER_TM_OBJS = $(addprefix $(SYMAPPLOBJDIR)/, $(addsuffix _p.@OBJEXT@, $(PUSER_TM_FILES)))

PALL_OBJS = $(PUSER_MASTER_OBJS) $(PUSER_LP_OBJS) $(PUSER_CP_OBJS) \
	    $(PUSER_TM_OBJS)

ifeq ($(CLP_LP_SOLVER),TRUE)
CFLAGS += -D__OSI_CLP__
endif

ifeq ($(GLPK_LP_SOLVER),TRUE)
CFLAGS += -D__OSI_GLPK__
else
ifeq ($(USE_GMPL), TRUE)
CFLAGS += -DUSE_GLPMPL
endif
endif

ifeq ($(CPLEX_LP_SOLVER),TRUE)
CFLAGS += -D__OSI_CPLEX__
endif

ifeq ($(SOPLEX_LP_SOLVER),TRUE)
CFLAGS += -D__OSI_SOPLEX__
endif

ifeq ($(XPRESS_LP_SOLVER),TRUE)
CFLAGS += -D__OSI_XPRESS__
endif

ifeq ($(CHECK_CUT_VALIDITY),TRUE)
CFLAGS += -DCHECK_CUT_VALIDITY
endif

# C++ Compiler command
CXX = @CXX@

# C++ Compiler options
CXXFLAGS = @CXXFLAGS@ 

# additional C++ Compiler options for linking
CXXLINKFLAGS = @RPATH_FLAGS@ 

#Include files
CFLAGS += -I`$(CYGPATH_W) $(SYMAPPLDIR)/include` \
	  -I`$(CYGPATH_W) @abs_source_dir@/include`

# Libraries necessary to link
ifeq ($(SYM_BUILD_APP),FALSE)
ifeq ($(COIN_HAS_PKGCONFIG),TRUE)
LIBS += `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --libs symphony`
CFLAGS += `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --cflags symphony`
else
LIBS += -L@abs_lib_dir@ -lSym @SYMPHONYLIB_LIBS_INSTALLED@
CFLAGS += -I`$(CYGPATH_W) $(COININCDIR)`
endif
else
ifeq ($(COIN_HAS_PKGCONFIG),TRUE)
LIBS += `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --libs symphony-app`
CFLAGS += `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --cflags symphony-app`
else
LIBS += -L@abs_lib_dir@ -lSymAppl @SYMPHONYLIB_LIBS_INSTALLED@
CFLAGS += -I`$(CYGPATH_W) $(COININCDIR)`
endif
endif

ifneq ($(SYM_PARALLEL),TRUE)
WHATTOMAKE = $(EXE)
else
WHATTOMAKE =
endif

ifeq ($(SYM_PARALLEL),TRUE)
WHATTOMAKE += $(MASTERNAME)$(MASTEREXT)
endif

ifneq ($(SYM_COMPILE_IN_LP),TRUE)
WHATTOMAKE  += $(MASTERNAME)_lp$(LPEXT)
endif

ifneq ($(SYM_COMPILE_IN_CP),TRUE)
WHATTOMAKE += $(MASTERNAME)_cp
endif

ifneq ($(SYM_COMPILE_IN_CG),TRUE)
WHATTOMAKE += $(MASTERNAME)_cg
endif

ifneq ($(SYM_COMPILE_IN_TM),TRUE)
WHATTOMAKE += $(MASTERNAME)_tm$(TMEXT)
endif

ADDFLAGS += $(CFLAGS) @SYMDEFS@
ADDPFLAGS += $(CFLAGS) @SYMPDEFS@

CFLAGS += -I`$(CYGPATH_W) $(PVM_ROOT)/include`
PLIBS = -L$(PVM_ROOT)/lib/@ARCH@ -lgpvm3 -lpvm3 $(LIBS) 

all: $(APPL_PARALLEL) $(WHATTOMAKE)

$(SYMAPPLOBJDIR)/%.o : %.c
	mkdir -p $(SYMAPPLOBJDIR)
	$(CXX) $(CXXFLAGS) $(INCL) $(ADDFLAGS) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<

$(SYMAPPLOBJDIR)/%.obj : %.c
	mkdir -p $(SYMAPPLOBJDIR)
	$(CXX) $(CXXFLAGS) $(INCL) $(ADDFLAGS) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`

$(SYMAPPLOBJDIR)/%_p.o : %.c
	mkdir -p $(SYMAPPLOBJDIR)
	$(CXX) $(CXXFLAGS) $(INCL) $(ADDPFLAGS) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<

$(SYMAPPLOBJDIR)/%_p.obj : %.c
	mkdir -p $(SYMAPPLOBJDIR)
	$(CXX) $(CXXFLAGS) $(INCL) $(ADDFLAGS) -c -o $@ `if test -f '$<'; then $(CYGPATH_W) '$<'; else $(CYGPATH_W) '$(SRCDIR)/$<'; fi`

$(EXE): $(ALL_OBJS)
	bla=;\
	for file in $(ALL_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  $(LIBS)

$(MASTERNAME)$(MASTEREXT) : $(PUSER_MASTER_OBJS)
	bla=;\
	for file in $(PUSER_MASTER_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  \
	-lSymAppl$(MASTEREXT) $(PLIBS)

$(MASTERNAME)_lp$(LPEXT) : $(PUSER_LP_OBJS)
	bla=;\
	for file in $(PUSER_LP_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  \
	-lSymAppl_lp$(LPEXT) $(PLIBS)

$(MASTERNAME)_cp : $(PUSER_CP_OBJS)
	bla=;\
	for file in $(PUSER_CP_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  \
	-lSymAppl_cp $(PLIBS)

$(MASTERNAME)_cg : $(PUSER_CG_OBJS)
	bla=;\
	for file in $(PUSER_CG_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  $(PLIBS) \
	-lSymAppl_cg

$(MASTERNAME)_tm$(TMEXT) : $(PUSER_TM_OBJS)
	bla=;\
	for file in $(PUSER_TM_OBJS); do bla="$$bla `$(CYGPATH_W) $$file`"; \
	done; \
	$(CXX) $(CXXLINKFLAGS) $(CXXFLAGS) -o $@ $$bla  \
	-lSymAppl_tm$(TMEXT) $(PLIBS)

.SUFFIXES: .cpp .c .o .obj .oo .objo

clean:
	rm -rf $(WHATTOMAKE) $(ALL_OBJS) $(PALL_OBJS)
