#
# Makefile for octave's liboctave directory
#
# John W. Eaton
# jwe@bevo.che.wisc.edu
# University of Wisconsin-Madison
# Department of Chemical Engineering

TOPDIR = ..

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

include $(TOPDIR)/Makeconf

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

LIBOCTAVE_LFLAGS = -L../libcruft -L../readline -L../kpathsea \
	-L../glob -L. $(RLD_FLAG)

LIBOCTAVE_LIBS = -lcruft -lreadline -lkpathsea -lglob

MATRIX_INC := Array.h Array2.h Array3.h DiagArray2.h Array-flags.h \
	Array-idx.h Array2-idx.h Array3-idx.h MArray-defs.h \
	MArray.h MArray2.h MDiagArray2.h Matrix.h \
	base-lu.h mx-base.h mx-op-defs.h mx-defs.h mx-ext.h \
	CColVector.h CDiagMatrix.h CMatrix.h CRowVector.h CmplxAEPBAL.h \
	CmplxCHOL.h CmplxDET.h CmplxHESS.h CmplxLU.h CmplxQR.h \
	CmplxQRP.h CmplxSCHUR.h CmplxSVD.h EIG.h boolMatrix.h chMatrix.h \
	dColVector.h dDiagMatrix.h dMatrix.h dRowVector.h dbleAEPBAL.h \
	dbleCHOL.h dbleDET.h dbleHESS.h dbleLU.h dbleQR.h \
	dbleQRP.h dbleSCHUR.h dbleSVD.h

MX_OP_INC := mx-cdm-cm.h mx-cdm-cs.h mx-cdm-dm.h mx-cdm-m.h \
	mx-cdm-s.h mx-cm-cdm.h mx-cm-dm.h mx-cm-m.h mx-cm-s.h \
	mx-cs-cdm.h mx-cs-dm.h mx-cs-m.h mx-dm-cdm.h mx-dm-cm.h \
	mx-dm-cs.h mx-dm-m.h mx-dm-s.h mx-m-cdm.h mx-m-cm.h \
	mx-m-cs.h mx-m-dm.h mx-s-cdm.h mx-s-cm.h mx-s-dm.h

INCLUDES := Bounds.h CollocWt.h DAE.h DAEFunc.h DASSL.h FEGrid.h \
	LinConst.h LP.h LPsolve.h LSODE.h NLConst.h NLEqn.h NLFunc.h \
	NLP.h ODE.h ODEFunc.h Objective.h QP.h Quad.h Range.h base-de.h \
	base-min.h byte-swap.h cmd-edit.h cmd-hist.h data-conv.h \
	dir-ops.h file-ops.h file-stat.h getopt.h glob-match.h \
	idx-vector.h lo-ieee.h lo-mappers.h lo-specfun.h lo-sysdep.h \
	lo-utils.h mach-info.h oct-alloc.h oct-cmplx.h oct-env.h \
	oct-group.h oct-passwd.h oct-syscalls.h oct-time.h pathlen.h \
	pathsearch.h prog-args.h statdefs.h str-vec.h sun-utils.h \
	sysdir.h systime.h syswait.h \
	$(MATRIX_INC) \
	$(MX_OP_INC)

TEMPLATE_SRC := Array.cc Array2.cc Array3.cc DiagArray2.cc \
	MArray.cc MArray2.cc MDiagArray2.cc base-lu.cc

TI_SRC := Array-C.cc Array-b.cc Array-ch.cc Array-i.cc Array-d.cc \
	Array-s.cc Array-str.cc \
	MArray-C.cc MArray-ch.cc MArray-i.cc MArray-d.cc MArray-s.cc

MATRIX_SRC := Array-flags.cc CColVector.cc CDiagMatrix.cc CMatrix.cc \
	CRowVector.cc CmplxAEPBAL.cc CmplxCHOL.cc CmplxDET.cc \
	CmplxHESS.cc CmplxLU.cc CmplxQR.cc CmplxQRP.cc CmplxSCHUR.cc \
	CmplxSVD.cc EIG.cc MArray-misc.cc boolMatrix.cc chMatrix.cc \
	dColVector.cc dDiagMatrix.cc dMatrix.cc dRowVector.cc \
	dbleAEPBAL.cc dbleCHOL.cc dbleDET.cc dbleHESS.cc dbleLU.cc \
	dbleQR.cc dbleQRP.cc dbleSCHUR.cc dbleSVD.cc

MX_OP_SRC := mx-cdm-cm.cc mx-cdm-cs.cc mx-cdm-dm.cc mx-cdm-m.cc \
	mx-cdm-s.cc mx-cm-cdm.cc mx-cm-dm.cc mx-cm-m.cc mx-cm-s.cc \
	mx-cs-cdm.cc mx-cs-dm.cc mx-cs-m.cc mx-dm-cdm.cc mx-dm-cm.cc \
	mx-dm-cs.cc mx-dm-m.cc mx-dm-s.cc mx-m-cdm.cc mx-m-cm.cc \
	mx-m-cs.cc mx-m-dm.cc mx-s-cdm.cc mx-s-cm.cc mx-s-dm.cc

SOURCES := Bounds.cc CollocWt.cc DAE.cc DASSL.cc FEGrid.cc LinConst.cc \
	LPsolve.cc LSODE.cc NLEqn.cc Quad.cc Range.cc cmd-edit.cc \
	cmd-hist.cc data-conv.cc dir-ops.cc f2c-main.c file-ops.cc \
	file-stat.cc filemode.c getopt.c getopt1.c glob-match.cc \
	idx-vector.cc lo-ieee.cc lo-mappers.cc lo-specfun.cc \
	lo-sysdep.cc lo-utils.cc mach-info.cc mkdir.c oct-alloc.cc \
	oct-env.cc oct-group.cc oct-passwd.cc oct-syscalls.cc \
	oct-time.cc pathsearch.cc prog-args.cc rename.c rmdir.c \
	strftime.c str-vec.cc tempname.c tempnam.c \
	$(TEMPLATE_SRC) \
	$(TI_SRC) \
	$(MATRIX_SRC) \
	$(MX_OP_SRC)

EXTRAS := mx-inlines.cc

INCLUDES_FOR_INSTALL := $(INCLUDES) $(TEMPLATE_SRC) $(EXTRAS)

DISTFILES := Makefile.in ChangeLog $(SOURCES) $(INCLUDES) $(EXTRAS)

ifeq ($(SHARED_LIBS), true)
  BINDISTLIBS = liboctave/liboctave
  BINDISTFILES = liboctave.$(SHLEXT_VER)
endif

MAKEDEPS_1 := $(patsubst %.cc, %.d, $(SOURCES))
MAKEDEPS := $(patsubst %.c, %.d, $(MAKEDEPS_1))

OBJECTS_1 := $(patsubst %.cc, %.o, $(SOURCES))
OBJECTS := $(patsubst %.c, %.o, $(OBJECTS_1))

ifeq ($(SHARED_LIBS), true)
  ifdef CXXPICFLAG
    PICOBJ := $(addprefix pic/, $(OBJECTS))
  else
    PICOBJ := $(OBJECTS)
  endif
endif

all: libraries
.PHONY: all

stmp-pic: pic
	@if [ -f stmp-pic ]; then \
	  true; \
	else \
	  echo "touch stmp-pic"; \
	  touch stmp-pic; \
	fi

pic:
	@if [ -d pic ]; then \
	  true; \
	else \
	  echo "mkdir pic"; \
	  mkdir pic; \
	fi

ifeq ($(SHARED_LIBS), true)
  ifeq ($(STATIC_LIBS), true)
    libraries: liboctave.$(LIBEXT)($(OBJECTS)) liboctave.$(SHLEXT)
  else
    libraries: liboctave.$(SHLEXT)
  endif
else
  ifeq ($(STATIC_LIBS), true)
    libraries: liboctave.$(LIBEXT)($(OBJECTS))
  else
    libraries:
  endif
endif
.PHONY: libraries

liboctave.$(SHLEXT): liboctave.$(SHLEXT_VER)
	rm -f $@
	$(LN_S) $< $@

liboctave.$(SHLEXT_VER): $(PICOBJ)
	$(SH_LD) $(SH_LDFLAGS) $(SONAME_FLAGS) -o $@ $^

$(PICOBJ): stmp-pic

check: all
.PHONY: check

install: install-lib install-inc
.PHONY: install

install-strip:
	$(MAKE) INSTALL_PROGRAM="$(INSTALL_PROGRAM) -s" install
.PHONY: install-strip

install-lib:
	$(top_srcdir)/mkinstalldirs $(octlibdir)
	if $(STATIC_LIBS); then \
	  rm -f $(octlibdir)/liboctave.$(LIBEXT); \
	  $(INSTALL_DATA) liboctave.$(LIBEXT) \
	    $(octlibdir)/liboctave.$(LIBEXT); \
	  $(RANLIB) $(octlibdir)/liboctave.$(LIBEXT); \
	fi
	if $(SHARED_LIBS); then \
	  rm -f $(octlibdir)/liboctave.$(SHLEXT_VER); \
	  $(INSTALL_PROGRAM) \
	    liboctave.$(SHLEXT_VER) $(octlibdir)/liboctave.$(SHLEXT_VER); \
	  cd $(octlibdir); \
	  rm -f liboctave.$(SHLEXT); \
	  $(LN_S) liboctave.$(SHLEXT_VER) liboctave.$(SHLEXT); \
	fi
	$(mk-libdir-link)
.PHONY: install-lib

install-inc:
	$(top_srcdir)/mkinstalldirs $(octincludedir)
	for f in $(INCLUDES_FOR_INSTALL); do \
	  rm -f $(octincludedir)/$$f; \
	  $(INSTALL_DATA) $(srcdir)/$$f $(octincludedir)/$$f; \
	done
	$(mk-includedir-link)
.PHONY: install-inc

uninstall:
	rm -f $(octlibdir)/liboctave.$(LIBEXT)
	rm -f $(octlibdir)/liboctave.$(SHLEXT)
	rm -f $(octlibdir)/liboctave.$(SHLEXT_VER)
	for f in $(INCLUDES); do rm -f $(octincludedir)/$$f; done
.PHONY: uninstall

tags: $(SOURCES)
	ctags $(SOURCES)

TAGS: $(SOURCES)
	etags $(SOURCES)

clean:
	rm -f *.$(LIBEXT) *.o *.d pic/*.o
	-rmdir pic
	rm -f stmp-pic
	if $(SHARED_LIBS); then rm -f *.$(SHLEXT_VER) *.$(SHLEXT); fi
.PHONY: clean

mostlyclean: clean
.PHONY: mostlyclean

distclean: clean
	rm -f Makefile so_locations
.PHONY: distclean

maintainer-clean: distclean
	rm -f tags TAGS
.PHONY: maintainer-clean

dist:
	ln $(DISTFILES) ../`cat ../.fname`/liboctave
.PHONY: dist

bin-dist:
	if [ -n "$(BINDISTFILES)" ]; then \
	  ln $(BINDISTFILES) ../`cat ../.fname`/liboctave; \
	fi
	if [ -n "$(BINDISTLIBS)" ]; then \
	  echo $(BINDISTLIBS) >> ../`cat ../.fname`/LIBRARIES; \
	fi
.PHONY: bin-dist

ifndef omit_deps
-include $(MAKEDEPS)
endif
