# Makefile for octave's liboctave directory
#
# Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
#               2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 John W. Eaton
#
# This file is part of Octave.
# 
# Octave is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3 of the License, or (at
# your option) any later version.
# 
# Octave is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License
# along with Octave; see the file COPYING.  If not, see
# <http://www.gnu.org/licenses/>.

TOPDIR = ..

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

include $(TOPDIR)/Makeconf

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

DLL_CDEFS = @OCTAVE_DLL_DEFS@
DLL_CXXDEFS = @OCTAVE_DLL_DEFS@

LINK_DEPS = \
  -L../libcruft -L. $(RLD_FLAG) \
  $(LIBCRUFT) $(CHOLMOD_LIBS) $(UMFPACK_LIBS) $(AMD_LIBS) $(CAMD_LIBS) \
  $(COLAMD_LIBS) $(CCOLAMD_LIBS) $(CXSPARSE_LIBS) $(ARPACK_LIBS) \
  $(QRUPDATE_LIBS) $(BLAS_LIBS) $(FFTW_LIBS) $(LIBREADLINE) $(LIBGLOB) \
  $(REGEX_LIBS) $(LIBS) $(FLIBS) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)

MATRIX_INC := Array.h Array2.h Array3.h ArrayN.h DiagArray2.h \
	Array-util.h MArray-decl.h MArray-defs.h \
	MArray.h MArray2.h MDiagArray2.h Matrix.h MArrayN.h \
	base-lu.h base-aepbal.h dim-vector.h mx-base.h mx-op-decl.h \
	mx-op-defs.h mx-defs.h mx-ext.h CColVector.h CDiagMatrix.h \
	CMatrix.h CNDArray.h CRowVector.h CmplxAEPBAL.h CmplxCHOL.h \
	CmplxGEPBAL.h CmplxHESS.h CmplxLU.h CmplxQR.h CmplxQRP.h \
	CmplxSCHUR.h CmplxSVD.h EIG.h fEIG.h boolMatrix.h boolNDArray.h \
	chMatrix.h chNDArray.h dColVector.h dDiagMatrix.h dMatrix.h \
	dNDArray.h dRowVector.h dbleAEPBAL.h dbleCHOL.h DET.h \
	dbleGEPBAL.h dbleHESS.h dbleLU.h dbleQR.h dbleQRP.h dbleSCHUR.h \
	dbleSVD.h boolSparse.h CSparse.h dSparse.h MSparse-defs.h MSparse.h \
	Sparse.h sparse-base-lu.h SparseCmplxLU.h SparsedbleLU.h \
	sparse-base-chol.h SparseCmplxCHOL.h SparsedbleCHOL.h \
	SparseCmplxQR.h SparseQR.h Sparse-op-defs.h Sparse-diag-op-defs.h \
	Sparse-perm-op-defs.h MatrixType.h PermMatrix.h \
	int8NDArray.h uint8NDArray.h int16NDArray.h uint16NDArray.h \
	int32NDArray.h uint32NDArray.h int64NDArray.h uint64NDArray.h \
	intNDArray.h \
	fCColVector.h fCRowVector.h fCDiagMatrix.h fCMatrix.h fCNDArray.h \
	fColVector.h fRowVector.h fDiagMatrix.h fMatrix.h fNDArray.h \
	fCmplxAEPBAL.h fCmplxGEPBAL.h fCmplxHESS.h fCmplxCHOL.h \
	fCmplxLU.h fCmplxSCHUR.h fCmplxSVD.h fCmplxQR.h \
	fCmplxQRP.h floatAEPBAL.h \
	floatCHOL.h floatGEPBAL.h floatHESS.h floatLU.h \
	floatSCHUR.h floatSVD.h floatQR.h floatQRP.h

MX_OP_INC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=mx list_h_files=1 $(srcdir)/mx-ops)

VX_OP_INC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=vx list_h_files=1 $(srcdir)/vx-ops)

SPARSE_MX_OP_INC := $(shell $(AWK) -f $(srcdir)/sparse-mk-ops.awk prefix=smx list_h_files=1 $(srcdir)/sparse-mx-ops)

OPT_BASE := $(addsuffix -opts, DASPK DASRT DASSL LSODE Quad)
OPT_IN := $(addsuffix .in, $(OPT_BASE))
OPT_INC := $(addsuffix .h, $(OPT_BASE))

INCLUDES := CollocWt.h DAE.h DAEFunc.h DAERT.h \
	DAERTFunc.h DASPK.h DASRT.h DASSL.h \
	LSODE.h \
	ODE.h ODEFunc.h ODES.h ODESFunc.h \
	Quad.h Range.h base-dae.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 functor.h getopt.h \
	glob-match.h idx-vector.h kpse-xfns.h \
	lo-ieee.h lo-mappers.h lo-math.h lo-specfun.h lo-sysdep.h \
	lo-traits.h lo-utils.h mach-info.h md5.h oct-alloc.h oct-cmplx.h \
	oct-env.h oct-fftw.h oct-getopt.h oct-group.h oct-inttypes.h \
	oct-locbuf.h oct-md5.h oct-mutex.h oct-norm.h \
        oct-passwd.h oct-rand.h oct-rl-edit.h oct-rl-hist.h oct-shlib.h \
        oct-sort.h oct-spparms.h oct-syscalls.h oct-sparse.h oct-time.h \
        oct-uname.h pathlen.h pathsearch.h prog-args.h \
	randgamma.h randmtzig.h randpoisson.h regex-match.h \
	sparse-sort.h statdefs.h str-vec.h \
	sparse-util.h sun-utils.h sysdir.h systime.h syswait.h \
	$(MATRIX_INC)

BUILT_INCLUDES := oct-types.h mx-ops.h \
	$(OPT_INC) \
	$(MX_OP_INC) \
	$(VX_OP_INC) \
	$(SPARSE_MX_OP_INC)

TEMPLATE_SRC := Array.cc ArrayN.cc eigs-base.cc DiagArray2.cc \
	MArray.cc MArray2.cc MArrayN.cc MDiagArray2.cc \
	base-lu.cc oct-sort.cc sparse-base-lu.cc \
	sparse-base-chol.cc sparse-dmsolve.cc

TI_SRC := Array-C.cc Array-b.cc Array-ch.cc Array-i.cc Array-d.cc \
	Array-f.cc Array-fC.cc Array-s.cc Array-str.cc Array-voidp.cc \
	Array-idx-vec.cc MArray-C.cc MArray-ch.cc MArray-i.cc MArray-d.cc \
	MArray-f.cc MArray-fC.cc MArray-s.cc MSparse-C.cc MSparse-d.cc \
	Sparse-C.cc Sparse-b.cc Sparse-d.cc oct-inttypes.cc

MATRIX_SRC := Array-util.cc CColVector.cc \
	CDiagMatrix.cc CMatrix.cc CNDArray.cc CRowVector.cc \
	CmplxAEPBAL.cc CmplxCHOL.cc CmplxGEPBAL.cc CmplxHESS.cc \
	CmplxLU.cc CmplxQR.cc CmplxQRP.cc CmplxSCHUR.cc CmplxSVD.cc \
	EIG.cc fEIG.cc boolMatrix.cc boolNDArray.cc chMatrix.cc \
	chNDArray.cc dColVector.cc dDiagMatrix.cc dMatrix.cc \
	dNDArray.cc dRowVector.cc dbleAEPBAL.cc dbleCHOL.cc \
	dbleGEPBAL.cc dbleHESS.cc dbleLU.cc dbleQR.cc dbleQRP.cc \
	dbleSCHUR.cc dbleSVD.cc boolSparse.cc CSparse.cc dSparse.cc \
	MSparse.cc Sparse.cc SparseCmplxLU.cc SparsedbleLU.cc \
	SparseCmplxCHOL.cc SparsedbleCHOL.cc \
	SparseCmplxQR.cc SparseQR.cc MatrixType.cc PermMatrix.cc \
	int8NDArray.cc uint8NDArray.cc int16NDArray.cc uint16NDArray.cc \
	int32NDArray.cc uint32NDArray.cc int64NDArray.cc uint64NDArray.cc \
	fCColVector.cc fCRowVector.cc fCDiagMatrix.cc fCMatrix.cc fCNDArray.cc \
	fColVector.cc fRowVector.cc fDiagMatrix.cc fMatrix.cc fNDArray.cc \
	fCmplxAEPBAL.cc fCmplxCHOL.cc fCmplxGEPBAL.cc \
	fCmplxHESS.cc fCmplxLU.cc fCmplxSCHUR.cc fCmplxSVD.cc fCmplxQR.cc \
	fCmplxQRP.cc floatAEPBAL.cc floatCHOL.cc \
	floatGEPBAL.cc floatHESS.cc floatLU.cc \
	floatSCHUR.cc floatSVD.cc floatQR.cc floatQRP.cc

MX_OP_SRC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=mx list_cc_files=1 $(srcdir)/mx-ops)

VX_OP_SRC := $(shell $(AWK) -f $(srcdir)/mk-ops.awk prefix=vx list_cc_files=1 $(srcdir)/vx-ops)

SPARSE_MX_OP_SRC := $(shell $(AWK) -f $(srcdir)/sparse-mk-ops.awk prefix=smx list_cc_files=1 $(srcdir)/sparse-mx-ops)

LIBOCTAVE_CXX_SOURCES := oct-locbuf.cc CollocWt.cc DASPK.cc DASRT.cc \
	DASSL.cc LSODE.cc ODES.cc \
	Quad.cc Range.cc data-conv.cc dir-ops.cc \
	file-ops.cc file-stat.cc glob-match.cc idx-vector.cc \
	lo-ieee.cc lo-mappers.cc lo-specfun.cc lo-sysdep.cc \
	lo-utils.cc mach-info.cc oct-alloc.cc oct-env.cc \
	oct-fftw.cc oct-group.cc oct-mutex.cc oct-md5.cc \
	oct-norm.cc oct-passwd.cc oct-rand.cc \
	oct-shlib.cc oct-spparms.cc oct-syscalls.cc oct-time.cc oct-uname.cc \
	prog-args.cc regex-match.cc \
	sparse-sort.cc sparse-util.cc str-vec.cc \
	$(TI_SRC) \
	$(MATRIX_SRC)

BUILT_LIBOCTAVE_CXX_SOURCES := \
	$(MX_OP_SRC) \
	$(VX_OP_SRC) \
	$(SPARSE_MX_OP_SRC)

LIBOCTAVE_C_SOURCES := f2c-main.c filemode.c getopt.c getopt1.c \
	lo-cieee.c lo-cutils.c md5.c mkdir.c oct-getopt.c \
	randgamma.c randmtzig.c randpoisson.c rename.c \
	rmdir.c strftime.c strptime.c strcasecmp.c strncase.c \
	tempname.c tempnam.c

LIBOCTAVE_SOURCES := $(LIBOCTAVE_CXX_SOURCES) $(BUILT_LIBOCTAVE_CXX_SOURCES) \
	$(LIBOCTAVE_C_SOURCES)

LIBOCT_READLINE_CXX_SOURCES := cmd-edit.cc cmd-hist.cc

LIBOCT_READLINE_C_SOURCES := oct-rl-edit.c oct-rl-hist.c

LIBOCT_READLINE_SOURCES := $(LIBOCT_READLINE_CXX_SOURCES) $(LIBOCT_READLINE_C_SOURCES)

LIBOCT_PATHSEARCH_CXX_SOURCES := pathsearch.cc

LIBOCT_PATHSEARCH_C_SOURCES := kpse-xfns.c

LIBOCT_PATHSEARCH_SOURCES := \
	$(LIBOCT_PATHSEARCH_C_SOURCES) $(LIBOCT_PATHSEARCH_CXX_SOURCES)

SOURCES := \
	$(LIBOCTAVE_SOURCES) \
	$(LIBOCT_READLINE_SOURCES) \
	$(LIBOCT_PATHSEARCH_SOURCES)

EXTRAS := mx-inlines.cc kpse.cc intNDArray.cc

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

DISTFILES := $(addprefix $(srcdir)/, Makefile.in ChangeLog mk-ops.awk \
	mx-ops vx-ops sparse-mk-ops.awk sparse-mx-ops oct-types.h.in \
	$(TEMPLATE_SRC) \
	$(LIBOCTAVE_CXX_SOURCES) \
	$(LIBOCT_READLINE_SOURCES) \
	$(LIBOCT_PATHSEARCH_SOURCES) \
	$(LIBOCTAVE_C_SOURCES) \
	$(INCLUDES) $(EXTRAS) $(OPT_IN)) \
	$(BUILT_LIBOCTAVE_CXX_SOURCES) $(BUILT_INCLUDES)

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

LIBOCTAVE_OBJECTS := \
	$(LIBOCTAVE_CXX_SOURCES:.cc=.o) \
	$(BUILT_LIBOCTAVE_CXX_SOURCES:.cc=.o) \
	$(LIBOCTAVE_C_SOURCES:.c=.o) \
	$(LIBOCT_READLINE_CXX_SOURCES:.cc=.o) \
	$(LIBOCT_READLINE_C_SOURCES:.c=.o) \
	$(LIBOCT_PATHSEARCH_CXX_SOURCES:.cc=.o) \
	$(LIBOCT_PATHSEARCH_C_SOURCES:.c=.o)

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

all: libraries
.PHONY: all

objects: $(LIBOCTAVE_OBJECTS)

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

PREREQ := $(OPT_INC) $(VX_OP_INC) $(VX_OP_SRC) \
	$(MX_OP_INC) $(MX_OP_SRC) mx-ops.h \
	$(SPARSE_MX_OP_INC) $(SPARSE_MX_OP_SRC)

ifeq ($(SHARED_LIBS), true)
  ifeq ($(STATIC_LIBS), true)
    LIBRARIES = $(LIBPRE)octave.$(LIBEXT) $(SHLPRE)octave.$(SHLEXT_VER)
  else
    LIBRARIES = $(SHLPRE)octave.$(SHLEXT_VER)
  endif
else
  ifeq ($(STATIC_LIBS), true)
    LIBRARIES = $(LIBPRE)octave.$(LIBEXT)
  else
    LIBRARIES =
  endif
endif

libraries: $(LIBRARIES)
.PHONY: libraries

$(LIBPRE)octave.$(LIBEXT): $(LIBOCTAVE_OBJECTS)
	rm -f $@
	$(TEMPLATE_AR) $(TEMPLATE_ARFLAGS) $@ $(LIBOCTAVE_OBJECTS)
	$(RANLIB) $@

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

$(SHLPRE)octave.$(SHLEXT): $(LIBOCTAVE_PICOBJ)
	rm -f $@
	$(SH_LD) $(SH_LDFLAGS) $(SONAME_FLAGS) -o $@ \
	$(LIBOCTAVE_PICOBJ) $(LINK_DEPS)

$(LIBOCTAVE_PICOBJ): stmp-pic

ifndef omit_deps
$(MAKEDEPS): $(PREREQ)
endif

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 $(DESTDIR)$(octlibdir)
	if $(STATIC_LIBS); then \
	  rm -f $(DESTDIR)$(octlibdir)/$(LIBPRE)octave.$(LIBEXT); \
	  $(INSTALL_DATA) $(LIBPRE)octave.$(LIBEXT) \
	    $(DESTDIR)$(octlibdir)/$(LIBPRE)octave.$(LIBEXT); \
	  $(RANLIB) $(DESTDIR)$(octlibdir)/$(LIBPRE)octave.$(LIBEXT); \
	fi
	if $(SHARED_LIBS); then \
	  rm -f $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB_VER); \
	  $(INSTALL) \
	    $(SHLLIBPRE)octave.$(SHLLIB) $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB_VER); \
	  rm -f $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB); \
	  (cd $(DESTDIR)$(octlibdir) ; $(LN_S) $(SHLLIBPRE)octave.$(SHLLIB_VER) $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB)); \
	  if  test x$(SHLBIN) != x ; then \
	    rm -f $(DESTDIR)$(bindir)/$(SHLBINPRE)octave.$(SHLBIN); \
	    $(INSTALL_PROGRAM) \
	      $(SHLBINPRE)octave.$(SHLBIN) $(DESTDIR)$(bindir)/$(SHLBINPRE)octave.$(SHLBIN); \
	  fi; \
	fi
.PHONY: install-lib

install-inc:
	$(top_srcdir)/mkinstalldirs $(DESTDIR)$(octincludedir)/octave
	for f in $(INCLUDES_FOR_INSTALL); do \
	  rm -f $(DESTDIR)$(octincludedir)/octave/$$f; \
	  if [ -f $$f ]; then \
	    $(INSTALL_DATA) $$f $(DESTDIR)$(octincludedir)/octave/$$f; \
	  else \
	    $(INSTALL_DATA) $(srcdir)/$$f $(DESTDIR)$(octincludedir)/octave/$$f; \
	  fi ; \
	done
.PHONY: install-inc

uninstall:
	rm -f $(DESTDIR)$(octlibdir)/$(LIBPRE)octave.$(LIBEXT)
	rm -f $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB)
	rm -f $(DESTDIR)$(octlibdir)/$(SHLLIBPRE)octave.$(SHLLIB_VER)
	if test x$(SHLBIN) != x; then \
	  rm -f $(DESTDIR)$(bindir)/$(SHLBINPRE)octave.$(SHLBIN); \
	  rm -f $(DESTDIR)$(bindir)/$(SHLBINPRE)octave.$(SHLBIN_VER); \
	fi
	for f in $(INCLUDES_FOR_INSTALL); do rm -f $(DESTDIR)$(octincludedir)/octave/$$f; done
.PHONY: uninstall

tags: $(SOURCES)
	ctags $(SOURCES)

TAGS: $(SOURCES)
	etags $(SOURCES)

clean:
	rm -f $(LIBPRE)octave.$(LIBEXT)
	rm -f $(SHLPRE)octave.$(SHLEXT_VER) $(SHLPRE)octave.$(SHLEXT)
	rm -f $(SHLBINPRE)octave.$(SHLBIN_VER) $(SHLBINPRE)octave.$(SHLBIN)
	rm -f $(LIBOCTAVE_OBJECTS) $(MAKEDEPS) $(LIBOCTAVE_PICOBJ) stmp-pic
	-rmdir pic
.PHONY: clean

mostlyclean: clean
.PHONY: mostlyclean

distclean maintainer-clean: clean
	rm -f tags TAGS
	rm -f Makefile so_locations oct-types.h $(PREREQ)
.PHONY: distclean maintainer-clean

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

$(OPT_INC) : %.h : %.in $(top_srcdir)/mk-opts.pl
	@echo making $@ from $<
	@perl $(top_srcdir)/mk-opts.pl --opt-class-header $< > $@-t
	@mv $@-t $@

$(VX_OP_INC) $(VX_OP_SRC) : $(srcdir)/mk-ops.awk vx-ops
	$(AWK) -f $(srcdir)/mk-ops.awk prefix=vx $(srcdir)/vx-ops

$(MX_OP_INC) $(MX_OP_SRC) : $(srcdir)/mk-ops.awk mx-ops
	$(AWK) -f $(srcdir)/mk-ops.awk prefix=mx $(srcdir)/mx-ops

$(SPARSE_MX_OP_INC) $(SPARSE_MX_OP_SRC) : $(srcdir)/sparse-mk-ops.awk sparse-mx-ops
	$(AWK) -f $(srcdir)/sparse-mk-ops.awk prefix=smx $(srcdir)/sparse-mx-ops

mx-ops.h : $(srcdir)/mk-ops.awk mx-ops
	$(AWK) -f $(srcdir)/mk-ops.awk prefix=mx make_inclusive_header=mx-ops.h $(srcdir)/mx-ops > $@-t
	$(simple-move-if-change-rule)

ifdef omit_deps
.PHONY: $(MAKEDEPS)
endif

-include $(MAKEDEPS)
