###########################################################################
#
# Makefile -- common code between gsdl runtime and buildtime
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the
# University of Waikato, New Zealand.
#
# Copyright (C) 1999  The New Zealand Digital Library Project
#
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################
srcdir = @srcdir@

PACKAGE = @PACKAGE@
VERSION = @VERSION@

@SET_MAKE@
CC = @CC@
CXX = @CXX@
CFLAGS = @CFLAGS@
CXXFLAGS = @CXXFLAGS@
LIBS   = @LIBS@
MDEFINES =

GSDLOS = @gsdlos@
GSDLARCH = @gsdlarch@

COMPILE = $(CC) -c $(CFLAGS)
CXXCOMPILE = $(CXX) -c $(CXXFLAGS)

SOURCES = 

OBJECTS = 

ALLFILES = $(OBJECTS)

# indexers are treated slightly differently as we don't want to do make all/install for gs2
INDEXERSDIR = indexers

# all directories should be compiled
COMPILEDIRS = cgi-bin packages src/lib src/getpw 

# a subset of the directories get installed
INSTALLDIRS = cgi-bin packages src/getpw 


USE_GDBM=@USE_GDBM@
ifeq ($(USE_GDBM), 1)
COMPILEDIRS += src/gdbmedit/txt2db src/gdbmedit/db2txt \
  src/gdbmedit/gdbmget src/gdbmedit/gdbmset \
  src/gdbmedit/gdbmkeys src/gdbmedit/gdbmdel
INSTALLDIRS += src/gdbmedit/db2txt src/gdbmedit/txt2db \
  src/gdbmedit/gdbmget src/gdbmedit/gdbmset \
  src/gdbmedit/gdbmkeys src/gdbmedit/gdbmdel
GDBM_DEFINES = -DUSE_GDBM
else
GDBM_DEFINES =
endif

USE_JDBM=@USE_JDBM@
ifeq ($(USE_JDBM), 1)
COMPILEDIRS += src/jdbmedit
INSTALLDIRS += src/jdbmedit
JDBM_DEFINES = -DUSE_JDBM
else
JDBM_DEFINES =
endif

USE_SQLITE = @USE_SQLITE@
ifeq ($(USE_SQLITE), 1)
SQLITE_DEFINES = -DUSE_SQLITE
else
SQLITE_DEFINES =
endif

MODULEDIRS = @MODULEDIRS@
DEFS = @DEFS@ $(GDBM_DEFINES) $(JDBM_DEFINES) $(SQLITE_DEFINES)

with-jni without-jni: 
	for odir in $(INDEXERSDIR); do \
	  echo making $@ in $$odir; \
	  (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
	done
	for odir in $(COMPILEDIRS) $(MODULEDIRS); do \
	  echo making all in $$odir; \
	  (cd $$odir && $(MAKE) $(MDEFINES) all) || exit 1; \
	done

install-with-jni: 
	for odir in $(INDEXERSDIR); do \
	  echo making $@ in $$odir; \
	  (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
	done
	if test -e $(INDEXERSDIR)/lucene-gs/LuceneWrapper4.jar; then \
	  cp $(INDEXERSDIR)/lucene-gs/LuceneWrapper4.jar ../bin/java/.; \
	fi
	for idir in $(INSTALLDIRS); do \
	  echo installing $$idir; \
	  (cd $$idir && $(MAKE) install) || exit 1; \
	done

install-without-jni:
	for odir in $(INDEXERSDIR); do \
	  echo making $@ in $$odir; \
	  (cd $$odir && $(MAKE) $(MDEFINES) $@) || exit 1; \
	done
	if test -e $(INDEXERSDIR)/lucene-gs/LuceneWrapper4.jar; then \
	  cp $(INDEXERSDIR)/lucene-gs/LuceneWrapper4.jar ../bin/java/.; \
	fi
	for odir in $(COMPILEDIRS) $(MODULEDIRS); do \
	  echo making install in $$odir; \
	  (cd $$odir && $(MAKE) $(MDEFINES) install) || exit 1; \
	done

distclean: clean
	rm -f Makefile config.cache config.h config.log stamp-h config.status
	for subdir in $(COMPILEDIRS) $(INDEXERSDIR); do \
	  echo cleaning $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) distclean) || exit 1; \
	done

clean:
	for subdir in $(COMPILEDIRS) $(INDEXERSDIR); do \
	  echo cleaning $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) clean) || exit 1; \
	done


# commented out - jrm21 Dec 2004 - can get confused by cvs timestamps
# (and might run the wrong version of autoconf)
#
## For an explanation of the following Makefile rules, see node
## `Automatic Remaking' in GNU Autoconf documentation.
#Makefile: Makefile.in config.status
#	CONFIG_FILES=$@ CONFIG_HEADERS= ./config.status
#config.status: configure
#	./config.status --recheck
#configure: configure.in aclocal.m4
#	cd $(srcdir) && autoconf
#
#config.h: stamp-h
#stamp-h: config.h.in config.status
#	CONFIG_FILES= CONFIG_HEADERS=config.h ./config.status
#config.h.in: stamp-h.in
#stamp-h.in: configure.in aclocal.m4 acconfig.h
#	cd $(srcdir) && autoheader
#	$(TOUCH) $(srcdir)/stamp-h.in



