# Copyright (C) 2007, 2009 Peter Carbonetto. All Rights Reserved.
# This code is published under the Eclipse Public License.
#
# Author: Peter Carbonetto
#         Dept. of Computer Science
#         University of British Columbia
#         May 19, 2007

# INSTRUCTIONS: Please modify the following few variables. See the
# readme.html file for more information.

# This variable corresponds to the base directory of your MATLAB
# installation. This is the directory so that in its 'bin/'
# subdirectory you see all the matlab executables (such as 'matlab',
# 'mex', etc.)
MATLAB_HOME = @MATLAB_HOME@

# Set the suffix for matlab mex files. The contents of the
# $(MATLAB_HOME)/extern/examples/mex directory might be able to help
# you in your choice.
MEXSUFFIX   = @MEXSUFFIX@

# This is the command used to call the mex program. Usually, it is
# just "mex". But it also may be something like
# /user/local/R2006b/bin/mex if "mex" doesn't work.
MEX = $(MATLAB_HOME)/bin/mex

#############################################################################
# Do not modify anything below unless you know what you're doing.

CXX           = @CXX@
CXXFLAGS      = @CXXFLAGS@ -DMATLAB_MEXFILE # -DMWINDEXISINT
libdir        = @libdir@
exec_prefix   = @exec_prefix@
prefix        = @prefix@

# Include directories (we use the CYGPATH_W variables to allow compilation with Windows compilers)
@COIN_HAS_PKGCONFIG_TRUE@INCL = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --cflags ipopt`
@COIN_HAS_PKGCONFIG_FALSE@INCL = -I`$(CYGPATH_W) @abs_include_dir@/coin` @IPOPTLIB_CFLAGS_INSTALLED@

# Linker flags
@COIN_HAS_PKGCONFIG_TRUE@LIBS = `PKG_CONFIG_PATH=@COIN_PKG_CONFIG_PATH@ @PKG_CONFIG@ --libs ipopt`
@COIN_HAS_PKGCONFIG_FALSE@@COIN_CXX_IS_CL_TRUE@LIBS = -link -libpath:`$(CYGPATH_W) @abs_lib_dir@` libipopt.lib @IPOPTLIB_LIBS_INSTALLED@
@COIN_HAS_PKGCONFIG_FALSE@@COIN_CXX_IS_CL_FALSE@LIBS = -L@abs_lib_dir@ -lipopt @IPOPTLIB_LIBS_INSTALLED@

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

TARGET = ipopt.$(MEXSUFFIX)

OBJS   = matlabexception.@OBJEXT@ matlabscalar.@OBJEXT@ \
         matlabstring.@OBJEXT@ matlabjournal.@OBJEXT@   \
         matlabmatrix.@OBJEXT@ arrayofmatrices.@OBJEXT@ \
         sparsematrix.@OBJEXT@ matlabprogram.@OBJEXT@   \
         matlaboption.@OBJEXT@ multipliers.@OBJEXT@     \
         matlabfunctionhandle.@OBJEXT@ ipopt.@OBJEXT@

MATLAB_INCLUDE = -I$(MATLAB_HOME)/extern/include
LDFLAGS        = $(CXXFLAGS) @RPATH_FLAGS@
MEXFLAGS       = -v -cxx -O CC="$(CXX)" CXX="$(CXX)" LD="$(CXX)"       \
                 COPTIMFLAGS="$(CXXFLAGS)" CXXOPTIMFLAGS="$(CXXFLAGS)" \
                 LDOPTIMFLAGS="$(LDFLAGS)" 

SRCDIR = @srcdir@
VPATH = $(SRCDIR)

all: $(TARGET)

%.@OBJEXT@: %.cpp
	$(CXX) $(CXXFLAGS) $(INCL) $(MATLAB_INCLUDE) -o $@ -c $^

$(TARGET): $(OBJS)
	$(MEX) $(MEXFLAGS) $(LIBS) -output $@ $^

install: $(TARGET)
	if test -d $(libdir); then : ; else mkdir $(libdir); fi
	cp $(SRCDIR)/../ipopt.m $(TARGET) $(libdir)

uninstall:
	rm -f $(libdir)/ipopt.m $(libdir)/ipopt.$(MEXSUFFIX)

clean:
	rm -f $(OBJS) $(TARGET)

distclean: clean
