# Copyright (C) 2007, 2011 International Business Machines and others.
# All Rights Reserved.
# This file is distributed under the Eclipse Public License.
#
# Author: Andreas Waechter     2007-10-08     IBM

# $Id: Makefile.in 2221 2013-04-14 18:14:55Z stefan $

## Installation of JDK
#JAVA_HOME = @JAVA_HOME@

# Java compiler
JAVAC = $(JAVA_HOME)/bin/javac

# JNI header file generator
JAVAH = $(JAVA_HOME)/bin/javah -jni

# Jar utility
JAR = $(JAVA_HOME)/bin/jar

# Java runtime
JAVA = $(JAVA_HOME)/bin/java

# Java documentation utility
JAVADOC = $(JAVA_HOME)/bin/javadoc

# C++ Compiler command
CXX = @CXX@

# C++ Compiler options
CXXFLAGS = `echo @CXXFLAGS@ | sed -e s'|-pedantic-errors||'`

# additional C++ Compiler options for linking
LINKFLAGS = $(CXXFLAGS) @RPATH_FLAGS@ @SHARED_FLAGS@

# 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` -I`$(CYGPATH_W) $(JAVA_HOME)/include` -I.
@COIN_HAS_PKGCONFIG_FALSE@INCL = -I`$(CYGPATH_W) @abs_include_dir@/coin` @IPOPTLIB_CFLAGS_INSTALLED@ -I`$(CYGPATH_W) $(JAVA_HOME)/include` -I.

# 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@

SRCDIR = @srcdir@
VPATH = @srcdir@

##########################################################################

ORGDIR = org/coinor
JNIHEADER = org_coinor_Ipopt.h

JIPOPTOBJ = jipopt.@OBJEXT@
JIPOPTDLL = @JIPOPTDLL@
LIBJIPOPT = lib/$(JIPOPTDLL)

IPOPTCLASS = $(ORGDIR)/Ipopt.class
HS071 = $(ORGDIR)/examples/HS071
SCALABLE = $(ORGDIR)/examples/scalable/SolveProblem

HS071CLASSES = $(ORGDIR)/examples/HS071.class

SCALCLASSES = \
	$(ORGDIR)/examples/scalable/LuksanVlcek1.class \
	$(ORGDIR)/examples/scalable/Scalable.class \
	$(ORGDIR)/examples/scalable/SolveProblem.class

SCALJAR = ScalableProblems.jar

$(LIBJIPOPT): $(JIPOPTOBJ) lib
	$(CXX) $(LINKFLAGS) -o $(LIBJIPOPT) $(JIPOPTOBJ) $(LIBS)

$(JNIHEADER): $(IPOPTCLASS)
	$(JAVAH) `echo $(IPOPTCLASS) | sed -e 's|/|.|g' -e 's|.class||'`

$(JIPOPTOBJ): $(JNIHEADER) 

lib:
	mkdir lib

.java.class:
	$(JAVAC) $<

.SUFFIXES: .cpp .o .obj .java .class

$(SCALJAR): $(SCALCLASSES)
	$(JAR) cfm $(SCALJAR) $(SRCDIR)/manifest.txt $(IPOPTCLASS) $(SCALCLASSES)

test: $(LIBJIPOPT) $(HS071CLASSES) $(SCALJAR)
	$(JAVA) $(HS071)
	$(JAVA) -jar $(SCALJAR) LukVlI1 100

clean:
	rm -rf $(LIBJIPOPT) $(JIPOPTOBJ) $(JNIHEADER) $(IPOPTCLASS) $(HS071CLASSES) $(SCALCLASSES) $(SCALJAR)

doc:
	$(JAVADOC) -d javadoc -windowtitle "JIpopt API documentation" org/coinor/Ipopt.java

.cpp.o:
	$(CXX) $(CXXFLAGS) $(INCL) -c -o $@ `test -f '$<' || echo '$(SRCDIR)/'`$<

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