# 
# 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=ckpt_lib

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

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

#
#	Each file in the CSRC list should be prepended by $(SRCDIR).
#
CSRC=$(SRCDIR)/condor_lib/finfo.c $(SRCDIR)/condor_lib/ckpt_main.c \
	$(SRCDIR)/condor_lib/syscalls.c $(SRCDIR)/condor_lib/chdir.c \
	$(SRCDIR)/condor_lib/close.c $(SRCDIR)/condor_lib/dup.c \
	$(SRCDIR)/condor_lib/dup2.c $(SRCDIR)/condor_lib/open.c \
	$(SRCDIR)/condor_lib/ckpt.c $(SRCDIR)/condor_lib/_mkckpt.c \
	$(SRCDIR)/condor_lib/CONDOR_sysnames.c \
	$(SRCDIR)/util_lib/perror.c $(SRCDIR)/util_lib/condor_errlst.c
SSRC=

SRC=$(CSRC) $(SSRC)

OBJ=CONDOR_syscalls.o _mkckpt.o ckpt.o ckpt_main.o \
	../condor_lib/finfo.o ../condor_lib/syscalls.o ../condor_lib/chdir.o \
	../condor_lib/close.o ../condor_lib/dup.o ../condor_lib/dup2.o \
	../condor_lib/open.o ../condor_lib/CONDOR_sysnames.o ../util_lib/except.o \
	../util_lib/dprintf.o ../util_lib/strdup.o ../util_lib/perror.o \
	../util_lib/condor_errlst.o

LIB=../util_lib/util_lib.a ../xdr_lib/xdr_lib.a

PROGRAMS=libckpt.a ckptrt0.o
CLEANUP=$(OBJ) $(PROGRAMS) $(PDIR)/Makefile.bak ToUpper

all: $(PROGRAMS)

ALWAYS:

release: $(DSTDIR)/lib/libckpt.a $(DSTDIR)/lib/ckptrt0.o
	cd $(DSTDIR)/lib ; chmod -w $(PROGRAMS)

$(DSTDIR)/lib/libckpt.a: libckpt.a
	rm -f $(DSTDIR)/lib/libckpt.a
	cp libckpt.a $(DSTDIR)/lib
	cd $(DSTDIR)/lib ; ranlib libckpt.a

$(DSTDIR)/lib/ckptrt0.o: ckptrt0.o
	rm -f $(DSTDIR)/lib/ckptrt0.o
	cp ckptrt0.o $(DSTDIR)/lib

lint: ALWAYS
	lint -Cckpt -DLINT -I$(SRCDIR)/h $(IDENT) $(CSRC)

clean: ALWAYS
	rm -f $(CLEANUP)

tags: ALWAYS
	cd $(PDIR) ; ctags $(TFLAGS) $(CSRC)

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

libckpt.a: $(OBJ)
	ar crv libckpt.a $?
	ranlib libckpt.a

ckptrt0.o: /lib/crt0.o ToUpper
	ToUpper /lib/crt0.o ckptrt0.o main

ToUpper: $(SRCDIR)/condor_lib/ToUpper.c
	cc -o ToUpper $(SRCDIR)/condor_lib/ToUpper.c

CONDOR_syscalls.o: $(SRCDIR)/condor_lib/CONDOR_syscalls.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/CONDOR_syscalls.c

_mkckpt.o: $(SRCDIR)/condor_lib/_mkckpt.c \
	$(SRCDIR)/condor_lib/_updateckpt.mips.c \
	$(SRCDIR)/condor_lib/_updateckpt.other.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/_mkckpt.c

ckpt.o: $(SRCDIR)/condor_lib/ckpt.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/ckpt.c

#ckpt.o: $(SRCDIR)/condor_lib/ckpt.c
#	/lib/cpp $(IDENT) $(SRCDIR)/condor_lib/ckpt.sed \
#								| egrep -v '^#' > ckpt.sed.mach
#	cc -S $(CFLAGS) $(SRCDIR)/condor_lib/ckpt.c
#	sed -f ckpt.sed.mach ckpt.s > ckpt.s.sed
#	as ckpt.s.sed -o ckpt.o
#	as $(CFLAGS) ckpt.s.sed -o ckpt.o
#	rm -f ckpt.s ckpt.s.sed ckpt.sed.mach

#ckpt_main.o: $(SRCDIR)/condor_lib/ckpt_main.c
#	cc -S $(CFLAGS) $(SRCDIR)/condor_lib/ckpt_main.c
#	echo "#define _ckptM ckptM" > tmp.s
#	cat ckpt_main.s | sed -e 's/^#.*//' >> tmp.s
#	/lib/cpp tmp.s | sed -e 's/^#.*//' > tmp2.s
#	as -o ckpt_main.o tmp2.s
#	rm -f tmp.s tmp2.s ckpt_main.s

ckpt_main.o: $(SRCDIR)/condor_lib/ckpt_main.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/ckpt_main.c

../util_lib/perror.o: $(SRCDIR)/util_lib/perror.c
	cc -c $(CFLAGS) $(SRCDIR)/util_lib/perror.c
	mv perror.o ../util_lib

../util_lib/condor_errlist.o: $(SRCDIR)/util_lib/condor_errlist.c
	cc -c $(CFLAGS) $(SRCDIR)/util_lib/condor_errlist.c
	mv condor_errlist.o ../util_lib

../condor_lib/finfo.o: $(SRCDIR)/condor_lib/finfo.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/finfo.c
	mv finfo.o ../condor_lib

../condor_lib/syscalls.o: $(SRCDIR)/condor_lib/syscalls.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/syscalls.c
	mv syscalls.o ../condor_lib

../condor_lib/chdir.o: $(SRCDIR)/condor_lib/chdir.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/chdir.c
	mv chdir.o ../condor_lib

../condor_lib/close.o: $(SRCDIR)/condor_lib/close.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/close.c
	mv close.o ../condor_lib

../condor_lib/dup.o: $(SRCDIR)/condor_lib/dup.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/dup.c
	mv dup.o ../condor_lib

../condor_lib/dup2.o: $(SRCDIR)/condor_lib/dup2.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/dup2.c
	mv dup2.o ../condor_lib

../condor_lib/open.o: $(SRCDIR)/condor_lib/open.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/open.c
	mv open.o ../condor_lib

../condor_lib/CONDOR_sysnames.o: $(SRCDIR)/condor_lib/CONDOR_sysnames.c
	cc -c $(CFLAGS) $(SRCDIR)/condor_lib/CONDOR_sysnames.c
	mv CONDOR_sysnames.o ../condor_lib

../util_lib/except.o: $(SRCDIR)/util_lib/except.c
	cc -c $(CFLAGS) $(SRCDIR)/util_lib/except.c
	mv except.o ../util_lib

../util_lib/dprintf.o: $(SRCDIR)/util_lib/dprintf.c
	cc -c $(CFLAGS) $(SRCDIR)/util_lib/dprintf.c
	mv dprintf.o ../util_lib

../util_lib/strdup.o: $(SRCDIR)/util_lib/strdup.c
	cc -c $(CFLAGS) $(SRCDIR)/util_lib/strdup.c
	mv strdup.o ../util_lib

TESTS=printer tcat registers
LIBS=libckpt.a -lc

tests: $(TESTS)
	@echo All tests made...

mkckpt: $(SRCDIR)/standalone/mkckpt.c libckpt.a
	cc -o mkckpt $(CFLAGS) $(SRCDIR)/standalone/mkckpt.c $(LIBS)

registers: registers.o libckpt.a ckptrt0.o mkckpt
	ld $(LDOPTS) -o registers ckptrt0.o registers.o $(LIBS)
	mkckpt registers

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

printer: printer.o libckpt.a ckptrt0.o mkckpt
	ld $(LDOPTS) -o printer ckptrt0.o printer.o $(LIBS)
	mkckpt printer

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

tcat: tcat.o libckpt.a ckptrt0.o mkckpt
	ld -o $(LDOPTS) tcat ckptrt0.o tcat.o $(LIBS)
	mkckpt tcat

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

depend: ALWAYS
	grep '^#include' $(CSRC) $(PDIR)/Makefile | grep -v '<' | \
	      sed 's/:[^"]*"\([^"]*\)".*/: \1/' | \
	      sed 's/\.c/.o/' | \
		  sed 's;$(PDIR)/;;' | \
		  sed 's;$(SRCDIR);..;' | \
		  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

../condor_lib/finfo.o: $(SRCDIR)/h/ckpt_file.h
../condor_lib/ckpt_main.o: $(SRCDIR)/h/condor_sys.h $(SRCDIR)/h/ckpt_file.h
../condor_lib/ckpt_main.o: $(SRCDIR)/h/trace.h $(SRCDIR)/h/except.h
../condor_lib/ckpt_main.o: $(SRCDIR)/h/fileno.h $(SRCDIR)/h/debug.h
../condor_lib/syscalls.o: $(SRCDIR)/h/condor_sys.h $(SRCDIR)/h/debug.h
../condor_lib/chdir.o: $(SRCDIR)/h/ckpt_file.h $(SRCDIR)/h/condor_sys.h
../condor_lib/chdir.o: $(SRCDIR)/h/trace.h $(SRCDIR)/h/except.h
../condor_lib/close.o: $(SRCDIR)/h/condor_sys.h
../condor_lib/dup.o: $(SRCDIR)/h/condor_sys.h
../condor_lib/dup2.o: $(SRCDIR)/h/condor_sys.h $(SRCDIR)/h/ckpt_file.h
../condor_lib/open.o: $(SRCDIR)/h/condor_sys.h
../condor_lib/ckpt.o: $(SRCDIR)/h/condor_sys.h $(SRCDIR)/h/trace.h $(SRCDIR)/h/ckpt.h
../condor_lib/ckpt.o: $(SRCDIR)/h/machdep.h $(SRCDIR)/h/except.h
../condor_lib/ckpt.o: $(SRCDIR)/h/debug.h
../condor_lib/_mkckpt.o: $(SRCDIR)/h/condor_sys.h $(SRCDIR)/h/trace.h
../condor_lib/_mkckpt.o: $(SRCDIR)/h/ckpt.h $(SRCDIR)/h/machdep.h
../condor_lib/_mkckpt.o: $(SRCDIR)/h/except.h $(SRCDIR)/h/debug.h
../util_lib/condor_errlist.o: $(SRCDIR)/h/errno.h
