# Copyright (C) 2003, 2007 International Business Machines and others.
# All Rights Reserved.
# This file is distributed under the Eclipse Public License.

## $Id: Makefile.am 3129 2013-12-10 14:22:43Z tkr $

# the idea is to use the ASL Makefiles to build a static $(AMPLSOLVER_A) library via the compile_*_ASL scripts
# from this library, we create a libcoinasl.la libtool library
# in a MS VC build, we assume static libraries are used, so we can use the usual libtool machinery via LIBADD
# in a normal build, we build the libcoinasl.la library by extracting the $(AMPLSOLVER_A) library and relinking it via libtool
#    in a shared library build, this should give a shared libcoinasl.so library
#    further, configure should have taken care of adding -fPIC -DPIC to the CFLAGS when compiling the ASL sources
#    to avoid a failure when building static libraries and a libtool warning, we additionally create .lo files for each object

AUTOMAKE_OPTIONS = foreign

EXTRA_DIST = get.ASL INSTALL.ASL

if COIN_CC_IS_CL
lib_LTLIBRARIES = libcoinasl.la

libcoinasl_la_SOURCES = 
libcoinasl_la_LIBADD = $(AMPLSOLVER_A)
libcoinasl_la_DEPENDENCIES = $(AMPLSOLVER_A)

# This is for libtool
libcoinasl_la_LDFLAGS = $(LT_LDFLAGS)

else
libcoinasl_la_LIBADD = 
libcoinasl_la_LDFLAGS =
endif

if DEPENDENCY_LINKING
libcoinasl_la_LIBADD += $(ASL_PCLIBS)
if HOST_IS_CYGWIN
libcoinasl_la_LDFLAGS += -Wl,--export-all-symbols
endif
endif

########################################################################
#                           Extra Targets                              #
########################################################################

compdir = compdir

alltargets = stdio1.h arith.h funcadd0.$(OBJEXT)

if COIN_CC_IS_CL
$(AMPLSOLVER_A):
	./compile_MS_ASL
else
$(AMPLSOLVER_A):
	./compile_Unix_ASL

libcoinasl.la : $(AMPLSOLVER_A)
	$(mkdir_p) linkdir ; cd linkdir ; \
	$(AR) x ../$(AMPLSOLVER_A) ; \
	for i in *.o ; do \
	  lofile=`echo $$i | sed -e 's/.o$$/.lo/'`; \
	  echo "# fake line" > $$lofile ; \
	  echo "# Generated by fake libtool" >> $$lofile ; \
	  echo "pic_object='$$i'" >> $$lofile ; \
	  echo "non_pic_object='$$i'" >> $$lofile ; \
	done ; cd ..
	$(LIBTOOL) --tag=CC --mode=link $(CC) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -rpath $(libdir) $(LT_LDFLAGS) linkdir/*.lo $(libcoinasl_la_LIBADD) $(libcoinasl_la_LDFLAGS)
	rm -rf linkdir

install-exec-local: libcoinasl.la
	test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
	if test -f libcoinasl.la; then \
          $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) libcoinasl.la "$(DESTDIR)$(libdir)/libcoinasl.la"; \
	fi

uninstall-local:
	$(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/libcoinasl.la"

alltargets += libcoinasl.la

endif

stdio1.h arith.h funcadd0.$(OBJEXT): $(AMPLSOLVER_A)

all-local: $(alltargets)

test:
	@echo "No test available for ASL."

thirdpartyincludedir = $(includedir)/coin/ThirdParty
thirdpartyinclude_HEADERS = \
  solvers/asl.h solvers/asl_pfg.h solvers/asl_pfgh.h solvers/psinfo.h solvers/funcadd.h \
  solvers/nlp.h solvers/nlp2.h solvers/getstub.h solvers/opcode.hd solvers/r_opn.hd \
  stdio1.h arith.h

pkgconfiglibdir = $(libdir)/pkgconfig
pkgconfiglib_DATA = coinasl.pc

CLEANFILES = $(AMPLSOLVER_A) $(alltargets)

########################################################################
#                         Maintainer Stuff                             #
########################################################################

# Files that are generated and should be cleaned with make distclean
DISTCLEANFILES =

include BuildTools/Makemain.inc
