# file: $isip/scripts/make/scripts.make

# this makefile contains a standard set of dependencies and targets
# that are used by all makefiles in the environment.
#

#------------------------------------------------------------------------------
#
# define variables section
#
#------------------------------------------------------------------------------

# define location of library
#
ifneq "$(ISIP_LIB_FILES)" ""
	BASE_LIB_MAIN = $(ISIP_PROTO)/lib
	BASE_LIB = $(BASE_LIB_MAIN)/scripts
	LIB_DIR = $(BASE_LIB)/$(ISIP_LIB)
	LIB_FILES := $(foreach file,$(wildcard $(ISIP_LIB_FILES)),$(LIB_DIR)/$(file))
endif
# define location of binary
#
ifneq "$(ISIP_BIN_FILES)" ""
	BASE_BIN_MAIN = $(ISIP_PROTO)/bin
	BASE_BIN = $(BASE_BIN_MAIN)/scripts
	BIN_DIR = $(BASE_BIN)/$(ISIP_BIN)
	BINE_FILES = $(patsubst %$(BIN_EXT),%,$(wildcard $(ISIP_BIN_FILES)))
	BIN_FILES := $(foreach file,$(BINE_FILES),$(BIN_DIR)/$(file))
endif

# extrapolate dependency list from filenames
#

# define dependencies: note that we include, by default, a makefile
#  located in the current directory, so that changes to the makefile
#  will trigger a make.
#
ALL_DEPS = ./GNUmakefile $(ISIP_DEPS)

# make sure we clean up
#  note: this code is executed ALL the time
#
.DONE:

# make everything silent
#
.SILENT:

.PHONY: all clean
#------------------------------------------------------------------------------
#
# define targets and dependencies
#
#------------------------------------------------------------------------------

# make all directories
#
all: $(ALL_DEPS) depend $(LIB_FILES) $(BIN_FILES)

# define rules for library installation. currently we only support
# perl and make libraries
#
$(LIB_DIR)/%.pm: %.pm 
	echo "$< -> $@"
	cp $< $@

$(LIB_DIR)/%.make: %.make
	echo "$< -> $@"
	cp $< $@

$(LIB_DIR)/%.tcl: %.tcl
	echo "$< -> $@"
	cp $< $@

$(LIB_DIR)/%: % 
	echo "$< -> $@"
	cp $< $@

# define rules for executable installation. currently we only support
# perl, tcl, and sh executables
#
$(BIN_DIR)/%: %.pl
	echo "$< -> $@"
	cp $< $@
	chmod a+x $@

$(BIN_DIR)/%: %.tcl
	echo "$< -> $@"
	cp $< $@
	chmod a+x $@

$(BIN_DIR)/%: %.sh
	echo "$< -> $@"
	cp $< $@
	chmod a+x $@

# automatic directory creation
#
$(LIB_DIR):
	-if ( test ! -d $(LIB_DIR)); then echo "creating directory" $(LIB_DIR); mkdir -p $(LIB_DIR); fi

$(BIN_DIR):
	-if ( test ! -d $(BIN_DIR)); then echo "creating directory" $(BIN_DIR); mkdir -p $(BIN_DIR); fi

# depend directive: this directive is called by recursive make before
# any other, so header files will be in place before any code is
# compiled. for this makefile only create needed directories
#
depend: $(LIB_DIR) $(BIN_DIR)

# clean up (has no meaning for scripts)
#
clean:

test: 
	echo "bin_dir = "$(BIN_DIR)"
	echo "base_bin = "$(BASE_BIN)"
	echo "base_bin_main = "$(BASE_BIN_MAIN)"
	echo "bin_dir = "$(BIN_DIR)"
	echo "lib_files = $(LIB_FILES)"
	echo "bin_files = $(BIN_FILES)"
	echo "bine_files = $(BINE_FILES)"

# diagnostics (meaningless for utilities right now)
#
diagnose:
run-diagnose:

# install target: just here for convenience
#
install: all

#
# end of file
