# file: GNUmakefile.in
#

# setup the environment
#

# ISIP_PROTO_INSTALL points to the install point for the ISIP prototype
# system
#
ISIP_PROTO_INSTALL=@prefix@
ifeq ($(ISIP_PROTO_INSTALL),.)
	ISIP_PROTO_INSTALL := $(shell pwd)
endif

ifndef ISIP_PROTO_INSTALL
	ISIP_PROTO_INSTALL := $(shell pwd)
endif
export ISIP_PROTO_INSTALL

# ISIP_PROTO points to the base of the ISIP prototype source tree
#
ISIP_PROTO=

ifndef ISIP_PROTO
	ISIP_PROTO := $(shell pwd)
endif
export ISIP_PROTO

# define the C++ compiler
# define the location of g++ as the default compiler
#
ifndef ISIP_CPLUS_COMPILER
	ISIP_CPLUS_COMPILER = @CXX@
	export ISIP_CPLUS_COMPILER
endif

# define a binary directory. if uname does not work on your system,
# you need to create some arbitrary string which will be unique across
# each architecture you use. our values for ISIP_BINARY are
# i386_SunOS_5.6 or sparc_SunOS_5.6. 
#
ifndef ISIP_BINARY
	ISIP_BINARY := @target@
export ISIP_BINARY
endif

# ----------------------------------------
# you shouldn't need to edit anything below this line
# ----------------------------------------

ifndef ISIP_INCLUDE
	ISIP_INCLUDE := -I$(ISIP_PROTO)/include
	export ISIP_INCLUDE
endif

ifndef ISIP_LIBS
	ISIP_LIBS = -L$(ISIP_PROTO)/lib/$(ISIP_BINARY) -l_proto -lm
	export ISIP_LIBS
endif	

# if a partial ISIP envioronment is running, it could cause problems. 
# unset a few variables
#
unexport ISIP_WORK

# force our default compilation options: optimize
#

# if the install directory and source directory are the same then 
# we should take care when running make clean and make install
#
ifeq "$(ISIP_PROTO)" "$(ISIP_PROTO_INSTALL)"
	DISTCLEAN_DIRECTIVE = distclean-careful
	CLEAN_DIRECTIVE = clean-careful
	INSTALL_DIRECTIVE = install-careful
else
	DISTCLEAN_DIRECTIVE = distclean-normal
	CLEAN_DIRECTIVE = clean-normal
	INSTALL_DIRECTIVE = install-normal
endif

# make operations quiet
#
.SILENT:

# we need the make scripts to be in place before we proceed so we define
# one of them as a dependency for all targets. we make a recursive make 
# call to traverse the directories with the appropriate rules
#
all: $(ISIP_PROTO)/lib/scripts/make/traverse.make
	$(MAKE) --directory $(ISIP_PROTO)/scripts -f $(ISIP_PROTO)/lib/scripts/make/traverse.make
	$(MAKE) --directory $(ISIP_PROTO)/class -f $(ISIP_PROTO)/lib/scripts/make/traverse.make
	$(MAKE) --directory $(ISIP_PROTO)/util -f $(ISIP_PROTO)/lib/scripts/make/traverse.make

# define install rules to build a stand-alone environment
#
install: all install-local $(INSTALL_DIRECTIVE)

install-normal: install-path
	echo "installing the isip prototype include files to $(ISIP_PROTO_INSTALL)/include";
	cp -rf $(ISIP_PROTO)/include $(ISIP_PROTO_INSTALL)/;
	echo "installing the isip prototype library files to $(ISIP_PROTO_INSTALL)/lib";
	cp -rf $(ISIP_PROTO)/lib $(ISIP_PROTO_INSTALL)/;
	echo "installing the isip prototype binary files to $(ISIP_PROTO_INSTALL)/bin";
	cp -rf $(ISIP_PROTO)/bin $(ISIP_PROTO_INSTALL)/;
	echo "installing the isip prototype help files to $(ISIP_PROTO_INSTALL)/doc";
	cp -rf $(ISIP_PROTO)/doc $(ISIP_PROTO_INSTALL)/;
	cp -rf ISIP_ENV.sh $(ISIP_PROTO_INSTALL)/;
	echo "installing the ISIP_ENV.sh file in $(ISIP_PROTO_INSTALL)/bin";
	cp -f $(ISIP_PROTO)/ISIP_ENV.sh $(ISIP_PROTO_INSTALL)/bin

install-careful:
	echo "installing the isip prototype include files to $(ISIP_PROTO_INSTALL)/include";
	echo "installing the isip prototype library files to $(ISIP_PROTO_INSTALL)/lib";
	echo "installing the isip prototype binary files to $(ISIP_PROTO_INSTALL)/bin";
	echo "installing the isip prototype help files to $(ISIP_PROTO_INSTALL)/doc";

install-local: 
	$(MAKE) --directory $(ISIP_PROTO)/scripts -f $(ISIP_PROTO)/lib/scripts/make/traverse.make install
	$(MAKE) --directory $(ISIP_PROTO)/class -f $(ISIP_PROTO)/lib/scripts/make/traverse.make install 
	$(MAKE) --directory $(ISIP_PROTO)/util -f $(ISIP_PROTO)/lib/scripts/make/traverse.make install

# define a rule to make the install path
#
install-path:
	-if ( test ! -d $(ISIP_PROTO_INSTALL)); then mkdir -p $(ISIP_PROTO_INSTALL); fi

# define rules to clean up the build and to clean up the installation
#
clean: $(ISIP_PROTO)/lib/scripts/make/traverse.make $(CLEAN_DIRECTIVE)

clean-normal:
	$(MAKE) --directory $(ISIP_PROTO) -f $(ISIP_PROTO)/lib/scripts/make/traverse.make clean
	echo "removing local include files from $(ISIP_PROTO)/include";
	-rm -rf $(ISIP_PROTO)/include
	echo "removing local library files from $(ISIP_PROTO)/lib";
	-rm -rf $(ISIP_PROTO)/lib
	echo "removing local binary files from $(ISIP_PROTO)/bin";
	-rm -rf $(ISIP_PROTO)/bin;
	echo "removing data files if they exist";
	-rm -rf $(ISIP_PROTO)/data/output

clean-careful: 
	$(MAKE) --directory $(ISIP_PROTO) -f $(ISIP_PROTO)/lib/scripts/make/traverse.make clean

distclean: $(CLEAN_DIRECTIVE) $(DISTCLEAN_DIRECTIVE)

distclean-normal: 
	echo "removing installed include files from $(ISIP_PROTO_INSTALL)/include";
	-rm -rf $(ISIP_PROTO_INSTALL)/include
	echo "removing installed library files from $(ISIP_PROTO_INSTALL)/lib";
	-rm -rf $(ISIP_PROTO_INSTALL)/lib
	echo "removing installed binary files from $(ISIP_PROTO_INSTALL)/bin";
	-rm -rf $(ISIP_PROTO_INSTALL)/bin
	echo "removing installed doc files from $(ISIP_PROTO_INSTALL)/doc";
	-rm -rf $(ISIP_PROTO_INSTALL)/doc
	-rm -rf $(ISIP_PROTO_INSTALL)/ISIP_ENV.sh
	echo "cleaning up installation files $(ISIP_PROTO)";
	-rm -rf GNUmakefile $(ISIP_PROTO)/ISIP_ENV.sh \
	        $(ISIP_PROTO)/config.cache $(ISIP_PROTO)/config.log \
	        $(ISIP_PROTO)/config.status

distclean-careful: 
	echo "removing installed include files from $(ISIP_PROTO_INSTALL)/include";
	-rm -rf $(ISIP_PROTO_INSTALL)/include
	echo "removing installed library files from $(ISIP_PROTO_INSTALL)/lib";
	-rm -rf $(ISIP_PROTO_INSTALL)/lib
	echo "removing installed binary files from $(ISIP_PROTO_INSTALL)/bin";
	-rm -rf $(ISIP_PROTO_INSTALL)/bin
	echo "cleaning up installation files $(ISIP_PROTO)";
	-rm -rf GNUmakefile $(ISIP_PROTO)/ISIP_ENV.sh \
	        $(ISIP_PROTO)/config.cache $(ISIP_PROTO)/config.log \
	        $(ISIP_PROTO)/config.status

# define appropriate rules to build the make scripts
#
$(ISIP_PROTO)/lib/scripts/make/traverse.make: $(ISIP_PROTO)/scripts/make/traverse.make
	$(MAKE) --directory $(ISIP_PROTO)/scripts/make

test:
	echo "Running test_suite.sh.";
	chmod +w ./test_suite.sh;
	./test_suite.sh

debug_env:
	echo "ISIP_PROTO =" $(ISIP_PROTO)
	echo "ISIP_PROTO_INSTALL =" $(ISIP_PROTO_INSTALL)
	echo "ISIP_CPLUS_COMPILER =" $(ISIP_CPLUS_COMPILER)
	echo "ISIP_BINARY =" $(ISIP_BINARY)
	echo "ISIP_INCLUDE =" $(ISIP_INCLUDE)
	echo "ISIP_LIBS =" $(ISIP_LIBS)
	echo "ISIP_WORK =" $(ISIP_WORK)

#
# end of file
