#######################################################################
# $Header: /cvsroot/SWIG/Makefile.in,v 1.77 2003/12/09 22:06:58 cheetah Exp $
#######################################################################

prefix      = /usr/local
exec_prefix = ${prefix}
srcdir      = .

##############################################################################
# Compiler and system configuration
##############################################################################

SHELL       = /bin/sh
SWIG_LIB    = ${exec_prefix}/lib/swig1.3
BIN_DIR     = ${exec_prefix}/bin
# TARGET      = swig.exe			# STP
TARGET      = swig
SOURCE      = Source
RUNTIME     = Runtime

swig: source swig.spec

source:
	@cd $(SOURCE); $(MAKE)

runtime:
	@cd $(RUNTIME); $(MAKE)

swig.spec: $(srcdir)/swig.spec.in config.status
	@CONFIG_HEADERS= CONFIG_LINKS= CONFIG_FILES=swig.spec $(SHELL) ./config.status

.PHONY: source runtime

#####################################################################
# All the languages SWIG speaks (when it wants to)
#####################################################################

skip-tcl	= test -n ""
skip-perl5	= test -n ""
skip-python	= test -n ""
skip-java	= test -n "1"
skip-guilescm   = test -n "1"
skip-guile	= test -n "1"
skip-mzscheme	= test -n "1"
skip-ruby	= test -n ""
skip-php4	= test -n "1"
skip-ocaml      = test -n "1"
skip-pike       = test -n "1"
skip-chicken	= test -n "1"
skip-csharp	= test -n ""

#####################################################################
# CHECK
#####################################################################

ACTION = check

chk-set-swiglib		= SWIG_LIB=e:/Dev/SWIG-1.3.21/Lib
chk-set-runtimelib	= RUNTIMEDIR=e:/Dev/SWIG-1.3.21/$(RUNTIME)/.libs
chk-set-swig		= SWIG=e:/Dev/SWIG-1.3.21/$(TARGET)

chk-set-env = $(chk-set-swiglib) $(chk-set-swig) $(chk-set-runtimelib)

chk = $(MAKE) -k -s $(chk-set-env) $(ACTION)

check-aliveness:
	test -x ./$(TARGET)
	./$(TARGET) -version
	./$(TARGET) -help
	@$(skip-tcl)      || ./$(TARGET) -tcl      -help
	@$(skip-perl5)    || ./$(TARGET) -perl     -help
	@$(skip-python)   || ./$(TARGET) -python   -help
	@$(skip-java)     || ./$(TARGET) -java     -help
	@$(skip-guile)    || ./$(TARGET) -guile    -help
	@$(skip-mzscheme) || ./$(TARGET) -mzscheme -help
	@$(skip-ruby)     || ./$(TARGET) -ruby     -help
	@$(skip-ocaml)    || ./$(TARGET) -ocaml    -help
	@$(skip-php4)     || ./$(TARGET) -php4     -help
	@$(skip-pike)     || ./$(TARGET) -pike     -help
	@$(skip-chicken)  || ./$(TARGET) -chicken  -help
	@$(skip-csharp)   || ./$(TARGET) -csharp   -help

check-examples:					\
	check-tcl-examples			\
	check-perl5-examples			\
	check-python-examples			\
	check-java-examples			\
	check-guile-examples			\
	check-mzscheme-examples			\
	check-ruby-examples			\
	check-ocaml-examples			\
	check-php4-examples			\
	check-pike-examples			\
	check-chicken-examples                  \
	check-csharp-examples

check-%-examples:
	@passed=true;						\
	dir="Examples/$*";					\
	if $(skip-$*); then					\
	  echo skipping $* $(ACTION);				\
	elif [ ! -f $$dir/check.list ]; then			\
	  echo skipping $* $(ACTION) "(no $$dir/check.list)";	\
	else							\
	  all=`sed '/^#/d' $$dir/check.list`;			\
	  for a in $$all; do					\
	    echo $(ACTION)ing $$dir/$$a;			\
	    (cd $$dir/$$a && $(chk))				\
	    || passed=false;					\
	  done;							\
	fi;							\
	test $$passed = true

# Checks testcases in the test-suite excluding those which are known to be broken
check-test-suite:				\
	check-tcl-test-suite			\
	check-perl5-test-suite			\
	check-python-test-suite			\
	check-java-test-suite			\
	check-guilescm-test-suite		\
	check-guile-test-suite			\
	check-mzscheme-test-suite		\
	check-ruby-test-suite			\
	check-ocaml-test-suite			\
	check-php4-test-suite			\
	check-pike-test-suite			\
	check-csharp-test-suite			\
#	check-chicken-test-suite

check-%-test-suite:
	@passed=true;							\
	dir="Examples/test-suite/$*";					\
	if $(skip-$*); then						\
	  echo skipping $* test-suite $(ACTION);			\
	elif [ ! -d $$dir ]; then					\
	  echo warning: cannot $(ACTION) $* test-suite "(no dir $$dir)";\
	else								\
	  (cd $$dir && $(MAKE) -k -s $(ACTION))				\
	  || passed=false;						\
	fi;								\
	test $$passed = true

gifplot-library:
	@echo $(ACTION)ing Examples/GIFPlot/Lib
	@cd Examples/GIFPlot/Lib ; $(MAKE) -k -s $(ACTION)

check-gifplot:					\
	check-tcl-gifplot			\
	check-perl5-gifplot			\
	check-python-gifplot			\
	check-java-gifplot			\
	check-guile-gifplot			\
	check-mzscheme-gifplot			\
	check-ruby-gifplot			\
	check-ocaml-gifplot			\
	check-php4-gifplot			\
	check-pike-gifplot			\
	check-chicken-gifplot                   \
#	check-csharp-gifplot

check-%-gifplot: gifplot-library
	@passed=true;						\
	up=`$(srcdir)/Tools/capitalize $*`;			\
	dir="Examples/GIFPlot/$$up";				\
	if $(skip-$*); then					\
	  echo skipping $$up $(ACTION);				\
	elif [ ! -f $$dir/check.list ]; then			\
	  echo skipping $$up $(ACTION) "(no $$dir/check.list)";	\
	else							\
	  all=`sed '/^#/d' $$dir/check.list`;			\
	  for a in $$all; do					\
	    echo $(ACTION)ing $$dir/$$a;			\
	    (cd $$dir/$$a && $(chk))				\
	    || passed=false;					\
	  done;							\
	fi;							\
	test $$passed = true

check: check-aliveness check-examples check-gifplot check-test-suite

#####################################################################
# ALL TEST SUITE: Known broken and broken testcases in the test-suite
#####################################################################

all-test-suite:					\
	all-tcl-test-suite			\
	all-perl5-test-suite			\
	all-python-test-suite			\
	all-java-test-suite			\
	all-guilescm-test-suite			\
	all-guile-test-suite			\
	all-mzscheme-test-suite			\
	all-ruby-test-suite			\
	all-ocaml-test-suite			\
	all-php4-test-suite			\
	all-pike-test-suite			\
	all-csharp-test-suite			\
#	all-chicken-test-suite

all-%-test-suite:
	@$(MAKE) -k -s check-$*-test-suite ACTION=all

#####################################################################
# BROKEN: Known broken tests in the test-suite
#####################################################################

broken-test-suite:				\
	broken-tcl-test-suite			\
	broken-perl5-test-suite			\
	broken-python-test-suite		\
	broken-java-test-suite			\
	broken-guilescm-test-suite		\
	broken-guile-test-suite			\
	broken-mzscheme-test-suite		\
	broken-ruby-test-suite			\
	broken-ocaml-test-suite			\
	broken-php4-test-suite			\
	broken-pike-test-suite			\
	broken-csharp-test-suite		\
#	broken-chicken-test-suite

broken-%-test-suite:
	@$(MAKE) -k -s check-$*-test-suite ACTION=broken

#####################################################################
# CLEAN
#####################################################################

clean: clean-objects clean-examples clean-gifplot clean-test-suite

clean-objects: clean-source clean-runtime

clean-source:
	@echo cleaning Source
	@cd $(SOURCE); $(MAKE) -s clean
	@rm -f $(TARGET)

clean-runtime:
	@echo cleaning Runtime
	@cd $(RUNTIME); $(MAKE) -s clean

clean-examples:
	@$(MAKE) -k -s check-examples ACTION=clean

clean-gifplot:
	@$(MAKE) -k -s check-gifplot ACTION=clean

clean-test-suite:
	@echo cleaning Examples/test-suite
	@$(MAKE) -k -s check-test-suite ACTION=clean

clean-%-examples:
	@$(MAKE) -k -s check-$*-examples ACTION=clean

clean-%-test-suite:
	@$(MAKE) -k -s check-$*-test-suite ACTION=clean

clean-%-gifplot:
	@$(MAKE) -k -s check-$*-gifplot ACTION=clean

#####################################################################
# DISTCLEAN
#####################################################################

DISTCLEAN-DEAD = config.status config.log config.cache swig.spec Makefile mkmf.log libtool

distclean: distclean-objects clean-examples clean-gifplot distclean-test-suite distclean-dead

distclean-objects: distclean-source distclean-runtime

distclean-source:
	@echo dist cleaning Source
	@cd $(SOURCE); $(MAKE) -s distclean
	@rm -f $(TARGET)

distclean-runtime:
	@echo dist cleaning Runtime
	@cd $(RUNTIME); $(MAKE) -s distclean

distclean-test-suite:
	@echo dist cleaning Examples/test-suite
	@$(MAKE) -k -s noskip-test-suite ACTION=distclean

noskip-test-suite:				\
	noskip-tcl-test-suite			\
	noskip-perl5-test-suite			\
	noskip-python-test-suite		\
	noskip-java-test-suite			\
	noskip-guilescm-test-suite		\
	noskip-guile-test-suite			\
	noskip-mzscheme-test-suite		\
	noskip-ruby-test-suite			\
	noskip-ocaml-test-suite			\
	noskip-php4-test-suite			\
	noskip-pike-test-suite			\
	noskip-csharp-test-suite		\
	noskip-chicken-test-suite

noskip-%-test-suite:
	dir="Examples/test-suite/$*";					\
	if [ ! -d $$dir ]; then						\
	  echo warning: cannot $(ACTION) $* test-suite "(no dir $$dir)";\
	else								\
	  (cd $$dir && $(MAKE) -k -s $(ACTION))				\
	fi;

distclean-dead:
	rm -f $(DISTCLEAN-DEAD)

#####################################################################
# TARGETS: install & friends
#####################################################################

# INSTALL         = /cygdrive/e/Dev/SWIG-1.3.21/Tools/config/install-sh -c		# STP
INSTALL         = /usr/bin/install
INSTALL_DATA    = ${INSTALL} -m 644
INSTALL_PROGRAM = ${INSTALL} -m 755
# MKINSTDIRS      = /cygdrive/e/Dev/SWIG-1.3.21/Tools/config/install-sh -m 0755 -d		# STP
MKINSTDIRS      = /usr/bin/install -m 0755 -d
M4_SOURCE_DIR   = /cygdrive/e/Dev/SWIG-1.3.21/Tools/config
M4_INSTALL_DIR  = ${prefix}/share/aclocal

install: install-main install-lib install-m4
	@echo "Installation complete"

install-main:
	@echo "Installing SWIG executable"
	@$(MKINSTDIRS) $(DESTDIR)$(BIN_DIR)
	@echo "Installing $(BIN_DIR)/$(TARGET)"
	@$(INSTALL_PROGRAM) $(TARGET) $(DESTDIR)$(BIN_DIR)/$(TARGET)

lib-languages = tcl perl5 python guile java mzscheme ruby php4 ocaml \
	pike chicken csharp

install-lib:
	@echo "Installing the SWIG library"
	@$(MKINSTDIRS) $(DESTDIR)$(SWIG_LIB)
	@cd $(srcdir)/Lib; for i in *.i *.swg; \
	    do \
	    echo "Installing $(DESTDIR)$(SWIG_LIB)/$$i"; \
            $(INSTALL_DATA) $$i $(DESTDIR)$(SWIG_LIB)/$$i; \
	    done;
	@for lang in $(lib-languages);				\
	    do							\
	    dst=$(DESTDIR)$(SWIG_LIB)/$$lang;			\
	    $(MKINSTDIRS) $$dst;				\
	    ( cd $(srcdir)/Lib/$$lang;				\
	      doti="`ls *.i 2>/dev/null`";			\
	      dotswg="`ls *.swg 2>/dev/null`";			\
	      if [ -f extra-install.list ]; then		\
		  extra="`sed '/^#/d' extra-install.list`";	\
	      fi;						\
	      files="`echo $$doti $$dotswg $$extra`";		\
	      if [ x"$$files" = x ]; then			\
		  echo "Installing nothing from Lib/$$lang";	\
	      else for file in $$doti $$dotswg $$extra;		\
		  do						\
		  echo "Installing $$dst/$$file";		\
		  $(INSTALL_DATA) $$file $$dst/$$file;	\
		  done;						\
	      fi );						\
	    done


install-runtime:
	@cd $(RUNTIME); $(MAKE) install


install-m4:
	@echo "Installing M4 macros"
	@$(MKINSTDIRS) $(M4_INSTALL_DIR)
	@echo "Installing $(M4_INSTALL_DIR)/swig.m4"
	@$(INSTALL_DATA) $(M4_SOURCE_DIR)/swig.m4 $(M4_INSTALL_DIR)/swig.m4


#####################################################################
# TARGETS: uninstall & friends
#####################################################################

uninstall: uninstall-main uninstall-lib uninstall-m4
	@echo "Uninstall complete"

uninstall-main:
	@echo "Uninstalling $(BIN_DIR)/$(TARGET)"
	rm -f $(DESTDIR)$(BIN_DIR)/$(TARGET);

uninstall-lib:
	@echo "Uninstalling the SWIG library"
	rm -rf $(DESTDIR)$(SWIG_LIB)/;

uninstall-runtime:
	@cd $(RUNTIME); $(MAKE) uninstall

uninstall-m4:
	@echo "Uninstalling $(M4_INSTALL_DIR)/swig.m4"
	rm -f $(M4_INSTALL_DIR)/swig.m4;

############################################################################
# DIST and other maintenance
############################################################################

# distribution directory
dd = swig-1.3.21
srpm = swig-1.3.21

dist:
	@echo 'Dave, what do you want to do w/ "make dist"?'
	@echo 'See Makefile.in target "dist-suggested" for an idea.'
	@echo '    --thi'
	false

dist-suggested:
	rm -rf $(dd) $(dd).tar.gz
	cvs export -d $(dd) -r HEAD SWIG
	tar cf - $(dd) | gzip --best > $(dd).tar.gz
	rm -rf $(dd)

srcrpm: swig.spec
	rm -fr $(srpm) $(srpm).src.rpm
	cvs export -d $(srpm) -r HEAD SWIG
	cp swig.spec $(srpm)
	tar -cf - $(srpm) | gzip --best > $(srpm).tar.gz
	rm -fr $(srpm)
	rpmbuild -ts $(srpm).tar.gz

# Makefile ends here
