# Downloading and compiling extra libraries
# -----------------------------------------

# $Id$
include Makefile.inc

all-local: Ipopt

# Downloading and compiling mumps
# ------------------------------

DIR=$(DOWNLOADFF)/ipopt
DIRPKG=../pkg
SRCDIR=Ipopt-$(VERSION)
PACKAGE=$(DIRPKG)/Ipopt-$(VERSION).tgz
INSTALL=../..
VERSION=3.10.2
# 3.10.2
URL=http://www.coin-or.org/download/source/Ipopt
FHSL=#$(DIRPKG)/ddeps.f $(DIRPKG)/ma27ad.f  $(DIRPKG)/mc19d.f 
LIBMUMPS=-L$(DOWNLOADFF)/lib  -ldmumpsFREEFEM-SEQ -lzmumpsFREEFEM-SEQ -lmumps_commonFREEFEM-SEQ -lpordFREEFEM-SEQ -lmpiseqFREEFEM-SEQ
INCMUMPS=$(DOWNLOADFF)/include/libseq 
#/Ipopt-3.10.2.tgz
Ipopt: $(SRCDIR)/FAIRE
#  --enable-static  --disable-shared  
$(SRCDIR)/FAIT: $(SRCDIR)/tag-tar
#	FFCS - disable dependency tracking like in FFCS itself for MinGW compilation (problem with backslashes, see
#	[[file:../../../../configure.ac::enable_dependency_tracking]])
	cd $(SRCDIR) ; \
	 ./configure --disable-dependency-tracking \
		   --disable-shared --enable-static \
                  --with-mumps='$(LIBMUMPS)' \
	          --without-hsl \
	          --with-mumps-incdir='$(INCMUMPS)' \
	  CXX='$(CXX)' CXXFLAGS='$(CXXFLAGS) -I$(INCMUMPS)' \
	  CC='$(CC)' CFLAGS='$(CFLAGS) -I$(INCMUMPS)' \
	  F77='$(FC)' FFLAGS='$(FCFLAGS)' \
	  CXXCPP='$(CXXCPP)'  CPP='$(CXXCPP)' \
	 --with-blas='$(LIBBLAS)' --with-lapack='$(LIBLAPACK)' --prefix='$(DOWNLOADFF)'
	touch $(SRCDIR)/FAIT	

# FFCS - avoid remaking install every time
install.done: $(SRCDIR)/FAIT
	$(MAKE)  -C  $(SRCDIR) install	
	touch $@
clean-local::
	-rm *.done

# FFCS - install and WHERE need to be sequential
WHERE.done: install.done
	echo Ipopt LD -L@DIR@/lib   -lipopt   >$(SRCDIR)/$(INSTALL)/lib/WHERE.Ipopt;
	echo Ipopt INCLUDE -I@DIR@/include/coin  >> $(SRCDIR)/$(INSTALL)/lib/WHERE.Ipopt ;
	touch $@

Makefile.inc:
	../../config.status  --file="Makefile.inc:Makefile.inc.in"

# FFCS - install and WHERE need to be sequential
$(SRCDIR)/FAIRE: install.done WHERE.done
	touch $@


$(SRCDIR)/$(INSTALL): $(SRCDIR)/tag-tar

$(SRCDIR)/tag-tar:$(PACKAGE) $(FHSL) 
	tar xvzf $(PACKAGE)
	patch -p0 <patch-IpBlas
	touch $(SRCDIR)/tag-tar

$(PACKAGE):
	cd `dirname $@`; $(WGET)   $(URL)/`basename $(PACKAGE)`
clean-local::
	rm -rf  $(SRCDIR)  *~ Makefile.inc

clean: clean-local
	-rm -rf ../include/coin
	-rm ../lib/libipopt* ../lib/liblcoinhsl* 
	-rm $(PACKAGE)

.PHONY:$(SRCDIR)/$(INSTALL)
