# Main Makefile for MG
# Copyright (C) 1994, 1995 Free Software Foundation, Inc.

# 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, 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.

PACKAGE = @PACKAGE@
VERSION = @VERSION@

@SET_MAKE@
SHELL = /bin/sh
VPATH = @srcdir@
exec_prefix = @exec_prefix@
prefix = @prefix@
srcdir = @srcdir@


CC = @CC@
CFLAGS = @CFLAGS@ @ARCH_DEP_FLAGS@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
LDFLAGS = @LDFLAGS@ 
LIBS = @LIBS@  
TOUCH = echo timestamp >

bindir = $(exec_prefix)/bin
infodir = $(prefix)/info
libexecdir = $(exec_prefix)/libexec

MDEFINES = 
#CC='$(CC)' CFLAGS='$(CFLAGS)' LDFLAGS='$(LDFLAGS)' LIBS='$(LIBS)' \
#prefix='$(prefix)' exec_prefix='$(exec_prefix)' \
#bindir='$(bindir)' libexecdir='$(libexecdir)' \
#infodir='$(infodir)' infodir='$(infodir)' libexecdir='$(libexecdir)'

#SUBDIRS = lib src/text src/images src/scripts 
SUBDIRS = lib src/text
JAVADIRS = java/org/greenstone/mg 
JNIDIRS = jni
.SUFFIXES:

all install uninstall execinstall execuninstall maninstall manuninstall: config.h
	for subdir in $(SUBDIRS) $(JAVADIRS) $(JNIDIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MDEFINES) $@) || exit 1; \
	done

nojava: 
	for subdir in $(SUBDIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MDEFINES) all) || exit 1; \
	done

install-nojava: 
	for subdir in $(SUBDIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MDEFINES) install) || exit 1; \
	done

javaonly:
	for subdir in $(JAVADIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MDEFINES) all) || exit 1; \
	done

install-javaonly:
	for subdir in $(JAVADIRS); do \
	  echo making $@ in $$subdir; \
	  (cd $$subdir && $(MAKE) $(MDEFINES) install) || exit 1; \
	done


check: all
	echo making $@ in ./test directory
	(cd ./test && $(MAKE) all) || exit 1
	./test/testmg `pwd`

mostlyclean: mostlyclean-recursive mostlyclean-local

clean: clean-recursive clean-local

distclean: distclean-recursive distclean-local

maintainer-clean: maintainer-clean-recursive maintainer-clean-local
	rm -f config.status

mostlyclean-recursive clean-recursive distclean-recursive maintainer-clean-recursive:
	for subdir in $(SUBDIRS) $(JAVADIRS) $(JNIDIRS); do \
	  target=`echo $@ | sed 's/-recursive//'`; \
	  echo making $$target in $$subdir; \
	  (cd $$subdir && $(MAKE) $$target) || exit 1; \
	done

mostlyclean-local:

clean-local: mostlyclean-local

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

maintainer-clean-local: distclean-local
	@echo "This command is intended only for maintainers to use;"
	@echo "rebuilding the deleted files may require special tools."

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

distdir = $(PACKAGE)-$(VERSION)

distname = $(distdir)

DISTFILES = \
INSTALL.mg INSTALL README README.port COPYING MODIFICATIONS about_mg.html \
Makefile.in acconfig.h aclocal.m4 configure.in install-sh mkinstalldirs \
config.guess config.sub \
config.h.in configure stamp-h.in sysfuncs.h

dist: $(DISTFILES)
#-----------------------------------------------------------------
	#create distribution directory
	-rm -rf $(distdir)
	mkdir $(distdir)
#
	#link in local distribution files
	ln $(DISTFILES) $(distdir)
#
	#link in SampleData
	mkdir $(distdir)/SampleData
	(cd SampleData; $(MAKE) "distdir=../$(distdir)/SampleData" dist)
	# link in davinci stuff
	mkdir $(distdir)/SampleData/davinci
	(cd SampleData/davinci; \
	$(MAKE) "distdir=../../$(distdir)/SampleData/davinci" dist)
	# link in bible stuff
	mkdir $(distdir)/SampleData/bible
	(cd SampleData/bible; \
	$(MAKE) "distdir=../../$(distdir)/SampleData/bible" dist)
#
	#link in tests
	mkdir $(distdir)/test
	(cd test; $(MAKE) "distdir=../$(distdir)/test" dist)
#
	#link in docs directory
	mkdir $(distdir)/docs
	(cd docs; $(MAKE) "distdir=../$(distdir)/docs" dist)
#
	#link in lib directory
	mkdir $(distdir)/lib
	(cd lib; $(MAKE) "distdir=../$(distdir)/lib" dist)
#
	#link in src distribution files
	mkdir $(distdir)/src
	for dir in src/text src/images src/scripts; do \
	  echo makeing $@ in $$dir ; \
	  mkdir $(distdir)/$$dir; \
	  (cd $$dir; $(MAKE) "distdir=../../$(distdir)/$$dir" $@) ; \
	done
#
	# archive and compress
	tar -chf - $(distdir) | gzip -9 > $(distname).tar.gz
	tar -chf - $(distdir) | compress > $(distname).tar.Z
#
	# cleanup
	rm -rf $(distdir)
#-----------------------------------------------------------------

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
