# 
# Copyright 1986, 1987, 1988, 1989 University of Wisconsin
# 
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of the University of
# Wisconsin not be used in advertising or publicity pertaining to
# distribution of the software without specific, written prior
# permission.  The University of Wisconsin makes no representations about
# the suitability of this software for any purpose.  It is provided "as
# is" without express or implied warranty.
# 
# THE UNIVERSITY OF WISCONSIN DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE UNIVERSITY OF WISCONSIN  BE LIABLE FOR
# ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# 
# Authors:  Allan Bricker and Michael J. Litzkow,
# 	         University of Wisconsin, Computer Sciences Dept.
# 
# 




#
# The following variables must be passed in to this makefile:
#
#	SRCDIR	=	The pathname (relative or absolute) of the source
#				directory (eg. ../src, /var/home/condor/CONDOR/src)
#
#	DSTDIR	=	The pathname (relative or absolute) of the directory
#				which will contain the installed binaries and libraries.
#				There must be "bin" and "lib" subdirectories within DSTDIR.
#
#	COPTS	=	Default flags to cc (eg -O, -g)
#
#	IDENT	=	Any #defines which are not automatically supplied
#				by cpp (eg. -Dsunos40 or -Dsunos32).  Note that
#				cpp provides definitions for architectures (eg.
#				vax, sun, mc68020, sparc)
#

DIRECTORY=condor_tools

PDIR=$(SRCDIR)/$(DIRECTORY)
CFLAGS=$(COPTS) -I$(SRCDIR)/h $(IDENT)

#
#	Options to 'ctags'
#
TFLAGS=-dt

#
#	Each file in the CSRC list should be prepended by $(PDIR).
#
CSRC=$(PDIR)/status.c $(PDIR)/vacate.c $(PDIR)/reschedule.c \
	$(PDIR)/summary.c $(PDIR)/config_val.c $(PDIR)/prtsegmap.c \
	$(PDIR)/preen.c $(PDIR)/history.c
#	$(PDIR)/print_core.c  $(PDIR)/print_exec.c

SSRC=

SRC=$(CSRC) $(SSRC)

OBJ=status.o vacate.o reschedule.o summary.o config_val.o prtsegmap.o preen.o \
	history.o
# 	print_core.o print_exec.o

LIB=../util_lib/util_lib.a ../xdr_lib/xdr_lib.a
LINTLIB =   ../util_lib/llib-lutil.ln ../xdr_lib/llib-lxdr.ln

PROGRAMS=condor_status condor_vacate condor_reschedule condor_summary \
			config_val prtsegmap condor_preen condor_history
# 			print_core print_exec

CLEANUP=$(OBJ) $(PROGRAMS) $(PDIR)/Makefile.bak

all: $(PROGRAMS)

ALWAYS:

release: $(PROGRAMS)
	cd $(DSTDIR)/bin ; rm -f $(PROGRAMS)
	cp $(PROGRAMS) $(DSTDIR)/bin
	cd $(DSTDIR)/bin ; chmod -w $(PROGRAMS)
#	cd $(DSTDIR)/bin ; chmod g+s $(PROGRAMS)
	cd $(DSTDIR)/bin ; chmod g+s condor_summary
	cd $(DSTDIR)/bin ; chmod g+s condor_history

lint: ALWAYS
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/status.c $(LINTLIB)
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/vacate.c $(LINTLIB)
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/reschedule.c $(LINTLIB)
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/summary.c $(LINTLIB)
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/history.c $(LINTLIB)
	lint -DLINT -I$(SRCDIR)/h $(IDENT) $(PDIR)/preen.c $(LINTLIB)

clean: ALWAYS
	rm -f $(CLEANUP)

tags: ALWAYS
	cd $(PDIR) ; ctags $(TFLAGS) $(CSRC) ; \
	cat ../h/tags ../xdr_lib/tags ../util_lib/tags ../condor_lib/tags \
			>> tags ; sort tags > tags.sorted ; mv tags.sorted tags

#############################################################################
# Put program specific things here
#############################################################################

condor_summary: summary.o  $(LIB)
	cc $(CFLAGS) -o condor_summary summary.o $(LIB)

condor_history: history.o  $(LIB)
	cc $(CFLAGS) -o condor_history history.o $(LIB)

condor_status: status.o  $(LIB)
	cc $(CFLAGS) -o condor_status status.o $(LIB)

condor_reschedule: reschedule.o $(LIB)
	cc $(CFLAGS) -o condor_reschedule reschedule.o $(LIB)

condor_preen: preen.o $(LIB)
	cc $(CFLAGS) -o condor_preen preen.o $(LIB) $(LIBDBM)

condor_vacate: vacate.o $(LIB)
	cc $(CFLAGS) -o condor_vacate vacate.o $(LIB)

config_val: config_val.o $(LIB)
	cc $(CFLAGS) -o config_val config_val.o $(LIB)

prtsegmap: prtsegmap.o $(LIB)
	cc $(CFLAGS) -o prtsegmap prtsegmap.o $(LIB)

print_exec: print_exec.o $(LIB)
	cc $(CFLAGS) -o print_exec print_exec.o $(LIB)

print_core: print_core.o $(LIB)
	cc $(CFLAGS) -o print_core print_core.o $(LIB)

summary.o: $(PDIR)/summary.c
	cc -c $(CFLAGS) $(PDIR)/summary.c

history.o: $(PDIR)/history.c
	cc -c $(CFLAGS) $(PDIR)/history.c

status.o: $(PDIR)/status.c
	cc -c $(CFLAGS) $(PDIR)/status.c

reschedule.o: $(PDIR)/reschedule.c
	cc -c $(CFLAGS) $(PDIR)/reschedule.c

preen.o: $(PDIR)/preen.c
	cc -c $(CFLAGS) $(PDIR)/preen.c

config_val.o: $(PDIR)/config_val.c
	cc -c $(CFLAGS) $(PDIR)/config_val.c

vacate.o: $(PDIR)/vacate.c
	cc -c $(CFLAGS) $(PDIR)/vacate.c

prtsegmap.o: $(PDIR)/prtsegmap.c
	cc -c $(CFLAGS) $(PDIR)/prtsegmap.c

print_exec.o: $(PDIR)/print_exec.c
	cc -c $(CFLAGS) $(PDIR)/print_exec.c

print_core.o: $(PDIR)/print_core.c
	cc -c $(CFLAGS) $(PDIR)/print_core.c

depend: ALWAYS
	grep '^#include' $(CSRC) $(PDIR)/Makefile | grep -v '<' | \
	      sed 's/:[^"]*"\([^"]*\)".*/: \1/' | \
	      sed 's/\.c/.o/' | \
		  sed 's;$(PDIR)/;;' | \
		  sed 's;: ;: $$\(SRCDIR)/h/;' | \
	awk ' { if ($$1 != prev) { print rec; rec = $$0; prev = $$1; } \
		else { if (length(rec $$2) > 78) { print rec; rec = $$0; } \
		       else rec = rec " " $$2 } } \
	      END { print rec } ' > makedep
	echo '$$r makedep' >>eddep
	echo '/^# DO NOT DELETE THIS LINE/+1,$$d' >eddep
	echo '$$r makedep' >>eddep
	echo 'w' >>eddep
	/bin/cp $(PDIR)/Makefile $(PDIR)/Makefile.bak
	ed - $(PDIR)/Makefile < eddep
	rm eddep makedep

# DO NOT DELETE THIS LINE -- make depend uses it

status.o: $(SRCDIR)/h/debug.h $(SRCDIR)/h/except.h $(SRCDIR)/h/trace.h
status.o: $(SRCDIR)/h/expr.h $(SRCDIR)/h/sched.h $(SRCDIR)/h/manager.h
