#
# $Id: Makefile.in,v 2.0 1998/10/14 23:23:07 hender Exp $
#
#
#       Makefile for the xpbsmon GUI
#
# This program is confidential and proprietary to MRJ Technology Solutions
# and may not be reproduced, published or disclosed to others without
# written authorization from MRJ.
# 
# Copyright (c) 1998 MRJ Technology Solutions, Inc. All Rights Reserved.
# 
# This program is derived from prior work some of which was originally
# written as a joint project between the Numerical Aerospace Simulation
# (NAS) Systems Division of NASA Ames Research Center and the National
# Energy Research Supercomputer Center (NERSC) of Lawrence Livermore
# National Laboratory.
#
# the first non-comment line must be .POSIX to assure POSIX make behavior
#
@MAKE_POSIX_TARGET@


srcdir = @srcdir@
top_srcdir = @top_srcdir@
MK_VPATH = @srcdir@
INSTALL = @INSTALL@

@mk_head@
@mk_dirs@
@mk_tcl@

XPBSMON_LIB = $(libdir)/xpbsmon
XPBSMON_SCRIPTS = $(PBS_SRC)/tools/xpbsmon

TARGETS = xpbsmon xpbsmonrc buildindex

all: build

build: $(TARGETS)


#
# need to fix the problem of where the libraries are. This is because
# they are in a different place after installation, yet we want to be able to
# run before installation.
#
xpbsmon: $(srcdir)/xpbsmon.src
	@echo Processing xpbsmon
	@sed -e 's,#\!.*pbs_wish.*$$,#\!../pbs_wish -f,' \
	    -e 's,set  *libdir.*$$,set libdir $(srcdir),' \
	    -e 's,set  *appdefdir.*$$,set appdefdir .,' \
	    $? > $@
	@chmod +x $@

xpbsmonrc: $(srcdir)/xpbsmonrc.src
	@echo Processing xpbsmonrc 
	@$(SHELL) $(srcdir)/patch_scripts "$(PBS_MACH)" "$(PBS_DEFAULT_SERVER)" "$?" "$@"

buildindex: $(srcdir)/buildindex.src
	@echo Processing buildindex
	@sed 's,#\!.*tclsh.*$$,#\!${TCLSH_PATH},' $? > $@
	@chmod +x $@
	@echo Running buildindex \(locally\)
	@./buildindex $(srcdir) .


install: build
	test -d $(XPBSMON_LIB) || $(INSTALL) -m 755 -d $(XPBSMON_LIB)
	test -d $(XPBSMON_LIB)/bitmaps || \
	    $(INSTALL) -m 755 -d $(XPBSMON_LIB)/bitmaps
	test -d $(XPBSMON_LIB)/help || \
	    $(INSTALL) -m 755 -d $(XPBSMON_LIB)/help
	#
	for f in $(srcdir)/bitmaps/*; do \
	    test -f $$f && $(INSTALL) -m 644 $$f $(XPBSMON_LIB)/bitmaps; \
	done
	#
	for f in $(srcdir)/help/*.hlp; do \
	    $(INSTALL) -m 644 $$f $(XPBSMON_LIB)/help; \
	done
	#
	for f in $(srcdir)/*.tcl $(srcdir)/*.tk; do \
	    $(INSTALL) -m 644 $$f $(XPBSMON_LIB); \
	done
	#
	# install xpbsmon changing the location of pbs_tclsh and libdir
	#
	sed -e 's,#\!.*pbs_wish.*$$,#\!$(PBS_UBIN)/pbs_wish -f,' \
	    -e 's,set  *libdir.*$$,set libdir ${XPBSMON_LIB},' \
	    -e 's,set  *appdefdir.*$$,set appdefdir ${XPBSMON_LIB},' \
	    xpbsmon > $(bindir)/xpbsmon
	chmod 755 $(bindir)/xpbsmon 2> /dev/null
	#
	$(INSTALL) -m 755 buildindex $(XPBSMON_LIB)
	$(INSTALL) -m 644 xpbsmonrc $(XPBSMON_LIB)
	#
	cd $(XPBSMON_LIB) && ./buildindex $(XPBSMON_LIB) && chmod 644 tclIndex

clean::
	$(RM) tclIndex; exit 0

@mk_cleanup@
