#
# Makefile --
#
# Top-level makefile for the Visualization Toolkit
# 
#------------------------------------------------------------------------------
#
SHELL=/bin/sh

srcdir        = @srcdir@
VPATH         = @srcdir@

BUILD_TOOLKITS    = @BUILD_TOOLKITS@
DEPEND_TOOLKITS   = @DEPEND_TOOLKITS@
CLEAN_TOOLKITS    = @CLEAN_TOOLKITS@

#------------------------------------------------------------------------------
# Autoconfig defines that can be overridden in user.make

@MAKEINCLUDE@ @MAKEQUOTE@system.make@MAKEQUOTE@

#------------------------------------------------------------------------------
# Include user-editable defines.

@MAKEINCLUDE@ @MAKEQUOTE@user.make@MAKEQUOTE@

#------------------------------------------------------------------------------

all: targets build_wrap build_common ${BUILD_TOOLKITS} \
    ${BUILD_TCL} ${BUILD_PYTHON} ${BUILD_JAVA}

targets: ${srcdir}/targets.cxx ${srcdir}/makedepend.cxx
	${CXX} -o targets ${srcdir}/targets.cxx ${srcdir}/makedepend.cxx

build_common: targets build_wrap
	cd common;     ${MAKE} -${MAKEFLAGS} targets.make
	cd common;     ${MAKE} -${MAKEFLAGS} all

build_graphics: build_common
	cd graphics;   ${MAKE} -${MAKEFLAGS} targets.make
	cd graphics;   ${MAKE} -${MAKEFLAGS} all

build_imaging: build_common
	cd imaging;    ${MAKE} -${MAKEFLAGS} targets.make
	cd imaging;    ${MAKE} -${MAKEFLAGS} all

build_patented: build_graphics
	cd patented;    ${MAKE} -${MAKEFLAGS} targets.make
	cd patented;    ${MAKE} -${MAKEFLAGS} all

build_wrap: targets
	cd wrap;        ${MAKE} -${MAKEFLAGS} all

build_contrib: build_graphics build_imaging
	cd contrib;     ${MAKE} -${MAKEFLAGS} targets.make
	cd contrib;     ${MAKE} -${MAKEFLAGS} all

build_local: build_graphics build_imaging
	cd local;     ${MAKE} -${MAKEFLAGS} targets.make
	cd local;     ${MAKE} -${MAKEFLAGS} all

build_tcl: build_common ${BUILD_TOOLKITS} 
	cd tcl;        ${MAKE} -${MAKEFLAGS} vtk

build_python: build_common ${BUILD_TOOLKITS}
	cd python;     ${MAKE} -${MAKEFLAGS} all

build_java: build_common ${BUILD_TOOLKITS}
	cd java;       ${MAKE} -${MAKEFLAGS} vtk

#------------------------------------------------------------------------------
# generate dpend.make files

depend: ${DEPEND_TCL} ${DEPEND_TOOLKITS} 
	cd common;    ${MAKE} -${MAKEFLAGS} depend

depend_tcl:
	cd tcl;       ${MAKE} -${MAKEFLAGS} depend

depend_graphics:
	cd graphics;  ${MAKE} -${MAKEFLAGS} depend

depend_imaging:
	cd imaging;   ${MAKE} -${MAKEFLAGS} depend

depend_patented:
	cd patented;    ${MAKE} -${MAKEFLAGS} depend

depend_contrib:
	cd contrib; ${MAKE} -${MAKEFLAGS} depend

depend_local:
	cd local; ${MAKE} -${MAKEFLAGS} depend

#------------------------------------------------------------------------------
# Clean up all files that were built by make.
clean: ${CLEAN_TCL} ${CLEAN_PYTHON} ${CLEAN_JAVA} ${CLEAN_TOOLKITS}
	cd common;    ${MAKE} -${MAKEFLAGS} clean
	cd wrap;    ${MAKE} -${MAKEFLAGS} clean
	rm -f config.cache
	rm -f targets
	if [ -d vtk-doxygen ] ; then rm -rf vtk-doxygen ; fi

clean_tcl:
	cd tcl;       ${MAKE} -${MAKEFLAGS} clean

clean_python:
	cd python;    ${MAKE} -${MAKEFLAGS} clean

clean_java:
	cd java;      ${MAKE} -${MAKEFLAGS} clean

clean_graphics:
	cd graphics;  ${MAKE} -${MAKEFLAGS} clean

clean_imaging:
	cd imaging;   ${MAKE} -${MAKEFLAGS} clean

clean_patented:
	cd patented;    ${MAKE} -${MAKEFLAGS} clean

clean_contrib:
	cd contrib;   ${MAKE} -${MAKEFLAGS} clean

clean_local:
	cd local;   ${MAKE} -${MAKEFLAGS} clean

#------------------------------------------------------------------------------
# Clean up all files that were built by make.
install: install-dirs install-libs @INSTALL_TARGET@

install-libs: @INSTALL_TOOLKITS@ 
	cd common; ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

install_graphics:
	cd graphics;   ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

install_imaging: 
	cd imaging;    ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

install_patented: 
	cd patented;    ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

install_contrib:
	cd contrib;     ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

install_local:
	cd local;     ${MAKE} -${MAKEFLAGS} install @INSTALL_TARGET@

do_install_tcl_java: do_install_tcl

install_java:
	@echo "Installing java"
	cd java; 	${MAKE} -${MAKEFLAGS} install

install_python:
	@echo "Installing python"
	cd python; ${MAKE} -${MAKEFLAGS} install

install_tcl:
	@echo "Installing vtk"
	cd tcl; ${MAKE} -${MAKEFLAGS} install

install-dirs:
	@for i in $(LIB_INSTALL_DIR) $(BIN_INSTALL_DIR) ; \
	    do \
	    if [ ! -d $$i ] ; then \
		echo "Making directory $$i"; \
		mkdir $$i; \
		chmod 755 $$i; \
		else true; \
		fi; \
	    done;

#------------------------------------------------------------
# Make the documentation - requires perl and doxygen.

doc:
	perl wrap/doc_header2doxygen.pl --to vtk-doxygen
	perl wrap/doc_version.pl --to vtk-doxygen
	perl wrap/doc_class2example.pl --to vtk-doxygen --link ../examples
	perl wrap/doc_index.pl --to vtk-doxygen --stop wrap/doc_index.stop
	doxygen wrap/doxyfile

#------------------------------------------------------------
# Rules for installing headers, examples and docs.

install_headers:
	if [ ! -d ${HEADER_INSTALL_DIR} ] ; then \
	    echo "Making directory ${HEADER_INSTALL_DIR}"; \
	    mkdir -p ${HEADER_INSTALL_DIR} ; \
	fi; \
	for i in common contrib graphics imaging local patented ; do \
		cp $$i/*.h ${HEADER_INSTALL_DIR} ; \
	done ; \
	chmod 644 ${HEADER_INSTALL_DIR}/* ;


# the following rule requires that cp support the -P option which
# creates the necessary parent directories.  It also requires a decent
# find that supports regex.
install_examples:
	if [ ! -d ${EXAMPLE_INSTALL_DIR} ] ; then \
	    echo "Making directory ${EXAMPLE_INSTALL_DIR}"; \
	    mkdir -p ${EXAMPLE_INSTALL_DIR} ; \
	fi; \
	for i in . common contrib graphics imaging local patented ; do \
	    for j in $$i/examples* ; do \
	        if [ ! -d $$j ] ; then break ; fi; \
	        echo "Installing $$j"; \
	        TMPVAR=`find $$j -regex ".*\.\(cxx\|gif\|h\|java\|ppm\|py\|sl\|so\|tcl\)"` ; \
	        if [ "$$TMPVAR" != "" ] ; then \
	            cp --parents $$TMPVAR ${EXAMPLE_INSTALL_DIR}; \
	        fi; \
	    done; \
	done; \
	find ${EXAMPLE_INSTALL_DIR} -perm -700 -regex ".*\.\(cxx\|gif\|h\|java\|ppm\|sl\|so\|tcl\)" -exec chmod 644 '{}' ';' ;


install_doc:
	if [ ! -d ${DOC_INSTALL_DIR} ] ; then \
	    echo "Making directory ${DOC_INSTALL_DIR}"; \
	    mkdir -p ${DOC_INSTALL_DIR} ; \
	fi; \
	cp -pr vtk-doxygen/html ${DOC_INSTALL_DIR} ;
