#
# $Id: Makefile.in,v 2.0 1998/10/14 22:54:26 hender Exp $
#
#
# Makefile for PBS commands
#

# 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@

PBS_MKDIRS = $(SHELL) @top_builddir@/@PBS_MKDIRS@

INCS = -I@top_builddir@/src/include -I$(PBS_SRCINC) $(TCL_INCS)
CFLAGS = @CFLAGS@ $(INCS) @DEFS@

PBS_LIBS = ../lib/Libcmds/libcmds.a \
           ../lib/Libnet/libnet.a   \
           ../lib/Libpbs/libpbs.a

CMDLIBS = $(PBS_LIBS) $(LIBS)


USER = qalter qdel qhold qmove qorder qmsg qrerun qrls qselect qsig qstat \
	qsub pbsdsh
OPER = qdisable qenable qrun qstart qstop qterm pbsnodes
ADMN = qmgr

EXES = $(USER) $(OPER) $(ADMN) $(SUPP)
SCRIPTS = nqs2pbs
SCRIPT_STAMPS = nqs2pbs-stamp
SUPP = pbs_demux

OBJS = pbs_demux.o pbsdsh.o qalter.o qdel.o qdisable.o qenable.o qhold.o \
       qmgr.o qmove.o qmsg.o qorder.o qrerun.o qrls.o qrun.o \
       qselect.o qsig.o qstart.o qstat.o qstop.o qsub.o qterm.o pbsnodes.o

TARGET = $(EXES)


all: autodepend
	@MAKE_POSIX_PLUS@@$(MAKE) build

build: $(TARGET) $(SCRIPT_STAMPS)


install:
	$(PBS_MKDIRS) clients
	$(PBS_MKDIRS) aux
	$(PBS_MKDIRS) default
	$(INSTALL) -d -m 755 $(bindir) && \
	for f in $(USER) $(OPER) $(ADMN) $(SCRT) ; do \
	    $(INSTALL) -m 755 $$f $(bindir)/$$f ; \
	done
	for f in $(SUPP) ; do \
	    $(INSTALL) -m 755 $$f $(sbindir)/$$f ; \
	done

#
# (almost) all commands depend on the regular libraries
#
$(TARGET): $(PBS_LIBS)


#
# unfortunately, some brain damaged makes are unable to handle 
# automatic generation of the various commands. Thus, we list them
# here.
#
DFLT_ACTION = $(CC) $(CFLAGS) $@.o -o $@ $(LDFLAGS) $(CMDLIBS)

pbs_demux: pbs_demux.o;   $(DFLT_ACTION)
pbsdsh: pbsdsh.o;         $(DFLT_ACTION)
pbsnodes: pbsnodes.o;     $(DFLT_ACTION)
qalter: qalter.o;         $(DFLT_ACTION)
qdel: qdel.o;             $(DFLT_ACTION)
qdisable: qdisable.o;     $(DFLT_ACTION)
qenable: qenable.o;       $(DFLT_ACTION)
qhold: qhold.o;           $(DFLT_ACTION)
qmgr: qmgr.o;             $(DFLT_ACTION)
qmove: qmove.o;           $(DFLT_ACTION)
qmsg: qmsg.o;             $(DFLT_ACTION)
qorder: qorder.o;         $(DFLT_ACTION)
qrerun: qrerun.o;         $(DFLT_ACTION)
qrls: qrls.o;             $(DFLT_ACTION)
qrun: qrun.o;             $(DFLT_ACTION)
qselect: qselect.o;       $(DFLT_ACTION)
qsig: qsig.o;             $(DFLT_ACTION)
qstart: qstart.o;         $(DFLT_ACTION)
qstop: qstop.o;           $(DFLT_ACTION)
qsub: qsub.o;             $(DFLT_ACTION)
qterm: qterm.o;           $(DFLT_ACTION)


EXTRA_QSTAT_LIBS = $(TCL_LIBS)
QSTAT_LIBS = $(PBS_LIBS) @EXTRA_QSTAT_LIBS@ $(LIBS)
qstat: qstat.o
	$(CC) $(CFLAGS) $@.o -o $@ $(LDFLAGS) $(QSTAT_LIBS)

#
# scripts are handled differently, the complexity arises from
# not knowing whether srcdir and builddir are the same
# always try to copy, and then touch a stamp. We assume that
# the only reason a copy will fail is because they are identical.
# if it fails due to permissions, the touch will probably 
# fail for the same reason.
# the test for srcdir being dot can certainly be fooled.
#
nqs2pbs-stamp: $(srcdir)/nqs2pbs
	-(test "$(srcdir)" != "." && cp $(srcdir)/nqs2pbs .; exit 0)
	touch $@

clean::
	-rm -f $(SCRIPT_STAMPS)

@mk_cleanup@
@mk_tail@

