# 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

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

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

SPYOBJS = PyProperty.lo PyRowRef.lo PyStorage.lo PyView.lo PWOImp.lo

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@
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@

CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@

# 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 @CXXFLAGS@ @MK_THREADS@
CXXFLAGS = @CXXFLAGS@ @MK_THREADS@
#CXXFLAGS = -Dq4_CHECK @CXXFLAGS@ @MK_THREADS@
#CXXFLAGS = -Wall -pedantic -Wno-unused @CXXFLAGS@ @MK_THREADS@

CXX = @CXX@
L = @LIBTOOL@
INSTALL = @INSTALL@
INSTALL_DATA = $L --mode=install @INSTALL_DATA@
INSTALL_PROGRAM = $L --mode=install @INSTALL_PROGRAM@

LIBTOOL_SHLIB_FLAGS = $(LDFLAGS) @LIBTOOL_SHLIB_FLAGS@
LIBTOOL_MODULE_FLAGS = $(LDFLAGS) @LIBTOOL_MODULE_FLAGS@

STRIP_FLAGS = @STRIP_FLAGS@

DESTDIR =

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

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

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

all: @MK_TARGETS@

core: Makefile libmk4.la $(DEMOS)

tcl: Makefile Mk4tcl@SHLIB_SUFFIX@

python: Makefile Mk4py@MODULE_SUFFIX@

test: Makefile libmk4.la 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 $(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.la
	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.la $(DESTDIR)$(libdir)

install-tcl: Mk4tcl@SHLIB_SUFFIX@
	mkdir -p $(DESTDIR)$(tcllibdir)/Mk4tcl
	$(INSTALL_PROGRAM) Mk4tcl@SHLIB_SUFFIX@ $(DESTDIR)$(tcllibdir)/Mk4tcl
	echo 'package ifneeded Mk4tcl 2.4.9.3 [list load [file join $$dir Mk4tcl@SHLIB_SUFFIX@] Mk4tcl]' >$(DESTDIR)$(tcllibdir)/Mk4tcl/pkgIndex.tcl

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

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

distclean: clean
	rm -f Makefile libtool 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.la: $(LOBJS) $(LINK_SPECIAL_FILES)
	$L --mode=link $(CXX) -o $@ $(CXX_SWITCHES) $(LIBTOOL_SHLIB_FLAGS) \
		-avoid-version $(SHLOBJS) $(LINK_SPECIAL_FLAGS)

Mk4tcl@SHLIB_SUFFIX@: libmk4tcl.la
	cp .libs/libmk4tcl@SHLIB_SUFFIX@ $@
	-strip $(STRIP_FLAGS) $@ 2>/dev/null

libmk4tcl.la: mk4tcl.o mk4too.o $(LOBJS) $(LINK_SPECIAL_FILES)
	$L --mode=link $(CXX) -o $@ $(CXX_SWITCHES) $(LIBTOOL_SHLIB_FLAGS) \
		-avoid-version -rpath $(libdir) \
		mk4tcl.lo mk4too.lo $(SHLOBJS) $(LINK_SPECIAL_FLAGS)

Mk4py@MODULE_SUFFIX@: libmk4py.la
	cp .libs/libmk4py@MODULE_SUFFIX@ $@
	-strip $(STRIP_FLAGS) $@ 2>/dev/null

libmk4py.la: $(PYOBJS) $(LOBJS)
	$L --mode=link $(CXX) -o $@ $(CXX_SWITCHES) $(LIBTOOL_MODULE_FLAGS) \
		-avoid-version -rpath $(libdir) \
		$(SPYOBJS) $(SHLOBJS)

Mk4lua@SHLIB_SUFFIX@: mk4lua.o libmk4.la
	$(CXX) -o $@ $(CXX_SWITCHES) -shared mk4lua.lo $(SHLOBJS) \
		-L$(libdir) -llua -llualib

demo: $(srcdir)/../demos/demo.cpp libmk4.la
	$L --mode=link $(CXX) $(CXX_SWITCHES) -static -o $@@EXEEXT@ \
		$(srcdir)/../demos/demo.cpp libmk4.la

dump: $(srcdir)/../demos/dump.cpp libmk4.la
	$L --mode=link $(CXX) $(CXX_SWITCHES) -static -o $@@EXEEXT@ \
		$(srcdir)/../demos/dump.cpp libmk4.la

myio: $(srcdir)/../demos/myio.cpp libmk4.la
	$L --mode=link $(CXX) $(CXX_SWITCHES) -o $@@EXEEXT@ \
		$(srcdir)/../demos/myio.cpp libmk4.la

struct: $(srcdir)/../demos/struct.cpp
	$L --mode=link $(CXX) $(CXX_SWITCHES) -o $@@EXEEXT@ \
		$(srcdir)/../demos/struct.cpp -lmk4

regress: $(TSTOBJS) libmk4.la
	$L --mode=link $(CXX) -static -o $@@EXEEXT@ $(TSTOBJS) libmk4.la

#---------- 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
	$L --mode=compile $(CXX) -c $(CXX_SWITCHES_TCL) $?
mk4too.o: $(srcdir)/../tcl/mk4too.cpp
	$L --mode=compile $(CXX) -c $(CXX_SWITCHES_TCL) $?

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

PWOImp.o: $(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
	$L --mode=compile $(CXX) -c $(CXX_SWITCHES_PY) \
	     $(srcdir)/../python/scxx/PWOImp.cpp

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

mk4lua.o: $(srcdir)/../lua/mk4lua.cpp
	$L --mode=compile $(CXX) -c $(CXX_SWITCHES_LUA) $?

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

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