#
# 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-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 chMatrix.h \
	dColVector.h dDiagMatrix.h dMatrix.h dRowVector.h dbleAEPBAL.h \
	dbleCHOL.h dbleDET.h dbleGEPBAL.h dbleHESS.h dbleLU.h dbleQR.h \
	dbleQRP.h dbleSCHUR.h dbleSVD.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-hist.h data-conv.h \
	dbleBessel.h dir-ops.h file-ops.h getopt.h idx-vector.h \
	lo-ieee.h lo-mappers.h lo-specfun.h lo-utils.h mach-info.h \
	oct-alloc.h oct-cmplx.h oct-glob.h oct-math.h oct-term.h \
	pathsearch.h prog-args.h statdefs.h str-vec.h sun-utils.h \
	sysdir.h \
	$(MATRIX_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 chMatrix.cc dColVector.cc \
	dDiagMatrix.cc dMatrix.cc dRowVector.cc dbleAEPBAL.cc \
	dbleCHOL.cc dbleDET.cc dbleGEPBAL.cc dbleHESS.cc dbleLU.cc \
	dbleQR.cc dbleQRP.cc dbleSCHUR.cc dbleSVD.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-hist.cc \
	data-conv.cc dir-ops.cc f2c-main.c file-ops.cc filemode.c \
	getopt.c getopt1.c idx-vector.cc lo-ieee.cc lo-mappers.cc \
	lo-specfun.cc lo-utils.cc mach-info.cc mkdir.c oct-alloc.cc \
	oct-glob.cc oct-term.cc pathsearch.cc prog-args.cc rename.c \
	rmdir.c str-vec.cc tempname.c tempnam.c \
	$(TEMPLATE_SRC) \
	$(TI_SRC) \
	$(MATRIX_SRC)

EXTRAS := mx-inlines.cc

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

ifeq ($(SHARED_LIBS), true)
  BINDISTFILES = liboctave.$(SHLEXT)
  BINDISTLIBS = liboctave/liboctave.$(SHLEXT)
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

LIBOCTAVE_DEPEND := $(patsubst %, liboctave.a(%), $(OBJECTS))

all: libraries
.PHONY: all

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

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

liboctave.$(LIBEXT): $(OBJECTS)
	$(AR) $(ARFLAGS) $@ $^
	$(RANLIB) $@

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

$(PICOBJ): pic

check: all
.PHONY: check

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

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); \
	  $(INSTALL_PROGRAM) \
	    liboctave.$(SHLEXT) $(octlibdir)/liboctave.$(SHLEXT); \
	fi
	$(mk-libdir-link)
.PHONY: install-lib

install-inc:
	$(top_srcdir)/mkinstalldirs $(octincludedir)
	for f in $(INCLUDES) $(TEMPLATE_SRC) ; 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)
	for f in $(INCLUDES); do rm -f $(octincludedir)/$$f; done
.PHONY: uninstall

tags: $(SOURCES)
	ctags $(SOURCES)

TAGS: $(SOURCES)
	etags $(SOURCES)

clean:
	rm -f *.a *.o *.d pic/*.o
	-rmdir pic
	if $(SHARED_LIBS); then rm -f *.$(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
