# If this file has the name "Makefile.in" then it is a template for a
# Makefile;  to generate the actual Makefile, run "./configure", which
# is a configuration script generated by the "autoconf" program.

SHELL =   /bin/sh

LOBJS =   column.o custom.o derived.o fileio.o field.o format.o \
          handler.o persist.o remap.o std.o store.o string.o table.o \
	  univ.o view.o viewx.o

PYOBJS  = PyProperty.o PyRowRef.o PyStorage.o PyView.o PWOImp.o

TSTOBJS = regress.o tbasic1.o tbasic2.o tcusto1.o tcusto2.o tdiffer.o \
	  textend.o tformat.o tlimits.o tmapped.o tnotify.o tresize.o \
	  tstore1.o tstore2.o tstore3.o tstore4.o tstore5.o

DEMOS   = demo dump myio

LINK_SPECIAL_FLAGS	=	@LINK_SPECIAL_FLAGS@ @LIBS@
LINK_SPECIAL_FILES	=	@LINK_SPECIAL_FILES@

#---------- Autoconf settings, can be overriden as "make" args

prefix = @prefix@
exec_prefix = @exec_prefix@
includedir = @includedir@
libdir = @libdir@
srcdir = @srcdir@
top_builddir = .

python = python
pyincludedir = @PY_INCLUDE_DIR@
pylibdir = @PY_LIB_DIR@

tclsh = tclsh
tclincludedir = @TCL_INCLUDE_DIR@
tcllibdir = @TCL_LIB_DIR@

CXX_FLAGS = @CPPFLAGS@ @CXXFLAGS@ @MK_THREADS@ @SHLIB_CFLAGS@

# Compiling without frame pointers can play tricks with exception handling
# (e.g. in Mk4py).  This does not affect standard operation, *only* errors.
# Happens in gcc 2.95.3, it has been disabled for now (even though slower).
#CXXFLAGS = -fomit-frame-pointer $(CXX_FLAGS)
CXXFLAGS = $(CXX_FLAGS)
#CXXFLAGS = -Dq4_CHECK $(CXX_FLAGS)
#CXXFLAGS = -Wall -pedantic -Wno-unused $(CXX_FLAGS)

CXX = ${LIBTOOL} --mode=compile @CXX@
CXXLD= ${LIBTOOL} --mode=link @CXX@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = ${LIBTOOL} --mode=install @INSTALL_PROGRAM@
LIB_SUFFIX = @LIB_SUFFIX@
SHLIB_SUFFIX = .la
SHLIB_LD = ${LIBTOOL} --mode=link @CXX@ -rpath ${prefix}/lib
SHLIB_LDPY = ${LIBTOOL} --mode=link @CXX@ -rpath ${PYSITELIB}
SHLIB_FLAGS = @SHLIB_FLAGS@
STRIP_FLAGS = @STRIP_FLAGS@
LIBEXT = .la
EXEEXT = @EXEEXT@
DESTDIR=

#---------- Do not change, shorthand only

CXX_SWITCHES      = $(CXXFLAGS) -I$(srcdir)/../include -I$(srcdir)/../src -I.
CXX_SWITCHES_TCL  = $(CXXFLAGS) -I$(tclincludedir)/generic -I$(tclincludedir)
CXX_SWITCHES_PY   = $(CXXFLAGS) -I$(srcdir)/../python/scxx -I$(pyincludedir)

#---------- The targets normally specified when calling "make"

all: @MK_TARGETS@

core: Makefile libmk4$(LIBEXT) $(DEMOS)

tcl: Makefile Mk4tcl$(LIBEXT)

python: Makefile Mk4py.so

test: Makefile libmk4$(LIBEXT) regress
	test -d tests || mkdir tests
	-test -d ../tests/ok/CVS && (test -d tests/CVS || mkdir tests/CVS)
	test -f reversed || cp $(srcdir)/reversed .
	./regress
	diff --exclude=.svn $(srcdir)/../tests/ok tests

test-tcl: tcl
	cd $(srcdir)/../tcl/test && $(tclsh) all.tcl

test-python: python
	$(python) $(srcdir)/../python/test/all.py

install: @MK_INSTALL@

install-mk: libmk4$(LIBEXT)
	mkdir -p $(DESTDIR)$(includedir) $(DESTDIR)$(libdir)
	$(INSTALL_DATA) $(srcdir)/../include/mk4.h \
			$(srcdir)/../include/mk4.inl \
			$(srcdir)/../include/mk4str.h \
			$(srcdir)/../include/mk4str.inl $(DESTDIR)$(includedir)
	$(INSTALL_PROGRAM) libmk4$(LIBEXT) $(DESTDIR)$(libdir)
	if [ '${LIBEXT}' = '.a' ]; then ranlib $(DESTDIR)$(libdir)/libmk4.a; fi

install-tcl: Mk4tcl$(LIBEXT)
	mkdir -p $(DESTDIR)$(tcllibdir)/Mk4tcl
	$(INSTALL_PROGRAM) Mk4tcl$(LIBEXT) $(DESTDIR)$(tcllibdir)/Mk4tcl
	if [ '${LIBEXT}' = '.a' ]; then ranlib $(DESTDIR)$(tcllibdir)/Mk4tcl/Mk4tcl.a; fi
	echo 'package ifneeded Mk4tcl 2.4.9.7 [list load [file join $$dir Mk4tcl$(LIBEXT)] Mk4tcl]' >$(DESTDIR)$(tcllibdir)/Mk4tcl/pkgIndex.tcl

install-python: Mk4py.so
	$(INSTALL_PROGRAM) Mk4py.so $(DESTDIR)$(pylibdir)
	$(INSTALL_DATA) $(srcdir)/../python/metakit.py $(DESTDIR)$(pylibdir)

clean:
	rm -f *$(LIBEXT) *.o
	rm -f $(DEMOS) struct regress myfile.dat secret.dat
	rm -rf tests/[a-z]*

distclean: clean
	rm -f Makefile config.h config.status config.log config.cache

#---------- This defines what each of the targets does

Makefile: $(srcdir)/Makefile.in config.status
	$(SHELL) ./config.status

config.status: $(srcdir)/configure
	$(SHELL) ./config.status --recheck

$(srcdir)/configure: $(srcdir)/configure.in
	cd $(srcdir) && autoconf

libmk4$(LIB_SUFFIX): $(LOBJS)
	ar rcu $@ $(LOBJS)
	ranlib $@

libmk4$(SHLIB_SUFFIX): $(LOBJS:.o=.lo) $(LINK_SPECIAL_FILES)
	$(SHLIB_LD) -o $@ $(LOBJS:.o=.lo) $(LINK_SPECIAL_FLAGS)

Mk4tcl$(LIB_SUFFIX): mk4tcl.o mk4too.o $(LOBJS)
	ar rcu $@ mk4tcl.o mk4too.o $(LOBJS)
	ranlib $@

Mk4tcl$(SHLIB_SUFFIX): mk4tcl.o mk4too.o $(LOBJS) $(LINK_SPECIAL_FILES)
	$(SHLIB_LD) -o $@ mk4tcl.o mk4too.o $(LOBJS) $(LINK_SPECIAL_FLAGS)

Mk4py$(LIB_SUFFIX): $(PYOBJS) $(LOBJS)
	ar cru $@ $(PYOBJS) $(LOBJS)
	ranlib $@

Mk4py.so: $(PYOBJS:.o=.lo) $(LINK_SPECIAL_FILES)
	$(SHLIB_LDPY) -o libMk4py.la $(PYOBJS:.o=.lo) $(LINK_SPECIAL_FLAGS) -L${prefix}/lib -lmk4
	cp .libs/libMk4py.so $@

Mk4lua$(SHLIB_SUFFIX): mk4lua.o $(LOBJS) $(LINK_SPECIAL_FILES)
	$(SHLIB_LD) -o $@ mk4lua.o $(LOBJS) $(LINK_SPECIAL_FLAGS)

demo.lo dump.lo myio.lo: $(srcdir)/../demos/${@:.lo=.cpp}
	$(CXX) -c $(CXX_SWITCHES) $?

demo: demo.lo libmk4$(LIBEXT)
	$(CXXLD) $(CXX_SWITCHES) -o $@$(EXEEXT) \
		demo.lo libmk4$(LIBEXT) @LIBS@

dump: dump.lo libmk4$(LIBEXT)
	$(CXXLD) $(CXX_SWITCHES) -o $@$(EXEEXT) \
		dump.lo libmk4$(LIBEXT) @LIBS@

myio: myio.lo libmk4$(LIBEXT)
	$(CXXLD) $(CXX_SWITCHES) -o $@$(EXEEXT) \
		myio.lo libmk4$(LIBEXT) @LIBS@

struct: $(srcdir)/../demos/struct.cpp
	$(CXX) $(CXX_SWITCHES) -o $@$(EXEEXT) \
		$(srcdir)/../demos/struct.cpp -lmk4 @LIBS@

regress: $(TSTOBJS:.o=.lo) libmk4$(LIBEXT)
	$(CXXLD) $(CXX_SWITCHES) -o $@$(EXEEXT) $(TSTOBJS:.o=.lo) libmk4$(LIBEXT) @LIBS@

#---------- Dependencies

# Hack.
# Configuration: HPUX, CXX=aCC, CC=cc, cpu PA-RISC
# => Have to link this object file to satisfy symbols.
#
cpprt0_stubs.o: $(srcdir)/cpprt0_stubs.s
	as -o $@ $?

mk4tcl.o: $(srcdir)/../tcl/mk4tcl.cpp
	$(CXX) -c $(CXX_SWITCHES_TCL) $?
mk4too.o: $(srcdir)/../tcl/mk4too.cpp
	$(CXX) -c $(CXX_SWITCHES_TCL) $?

PyProperty.lo PyRowRef.lo PyStorage.lo PyView.lo: $(srcdir)/../python/${@:.lo=.cpp}
	$(CXX) -c $(CXX_SWITCHES_PY) $?

PyProperty.o: $(srcdir)/../python/PyProperty.cpp
	$(CXX) -c $(CXX_SWITCHES_PY) $?
PyRowRef.o: $(srcdir)/../python/PyRowRef.cpp
	$(CXX) -c $(CXX_SWITCHES_PY) $?
PyStorage.o: $(srcdir)/../python/PyStorage.cpp
	$(CXX) -c $(CXX_SWITCHES_PY) $?
PyView.o: $(srcdir)/../python/PyView.cpp
	$(CXX) -c $(CXX_SWITCHES_PY) $?

PWOImp.lo: $(srcdir)/../python/scxx/PWOImp.cpp \
	  $(srcdir)/../python/scxx/PWOBase.h \
	  $(srcdir)/../python/scxx/PWOCallable.h \
	  $(srcdir)/../python/scxx/PWOMSequence.h \
	  $(srcdir)/../python/scxx/PWOMapping.h \
	  $(srcdir)/../python/scxx/PWONumber.h \
	  $(srcdir)/../python/scxx/PWOSequence.h
	$(CXX) -c $(CXX_SWITCHES_PY) $(srcdir)/../python/scxx/PWOImp.cpp

$(LOBJS:.o=.lo): $(srcdir)/../src/${@:.lo=.cpp}
	$(CXX) -c $(CXX_SWITCHES) $?

column.o:  $(srcdir)/../src/column.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
custom.o:  $(srcdir)/../src/custom.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
derived.o: $(srcdir)/../src/derived.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
field.o:   $(srcdir)/../src/field.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
fileio.o:  $(srcdir)/../src/fileio.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
format.o:  $(srcdir)/../src/format.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
handler.o: $(srcdir)/../src/handler.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
persist.o: $(srcdir)/../src/persist.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
remap.o:   $(srcdir)/../src/remap.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
std.o:     $(srcdir)/../src/std.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
store.o:   $(srcdir)/../src/store.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
string.o:  $(srcdir)/../src/string.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
table.o:   $(srcdir)/../src/table.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
univ.o:    $(srcdir)/../src/univ.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
view.o:    $(srcdir)/../src/view.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
viewx.o:   $(srcdir)/../src/viewx.cpp
	$(CXX) -c $(CXX_SWITCHES) $?

mk4lua.o:  $(srcdir)/../lua/mk4lua.cpp
	$(CXX) -c $(CXX_SWITCHES) $?

$(TSTOBJS:.o=.lo): $(srcdir)/../tests/${@:.lo=.cpp}
	$(CXX) -c $(CXX_SWITCHES) $?

regress.o: $(srcdir)/../tests/regress.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tbasic1.o: $(srcdir)/../tests/tbasic1.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tbasic2.o: $(srcdir)/../tests/tbasic2.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tcusto1.o: $(srcdir)/../tests/tcusto1.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tcusto2.o: $(srcdir)/../tests/tcusto2.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tdiffer.o: $(srcdir)/../tests/tdiffer.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
textend.o: $(srcdir)/../tests/textend.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tformat.o: $(srcdir)/../tests/tformat.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tlimits.o: $(srcdir)/../tests/tlimits.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tmapped.o: $(srcdir)/../tests/tmapped.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tnotify.o: $(srcdir)/../tests/tnotify.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tresize.o: $(srcdir)/../tests/tresize.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tstore1.o: $(srcdir)/../tests/tstore1.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tstore2.o: $(srcdir)/../tests/tstore2.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tstore3.o: $(srcdir)/../tests/tstore3.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tstore4.o: $(srcdir)/../tests/tstore4.cpp
	$(CXX) -c $(CXX_SWITCHES) $?
tstore5.o: $(srcdir)/../tests/tstore5.cpp
	$(CXX) -c $(CXX_SWITCHES) $?

#---------- End
