SRC_DIR = $(SRC_TREE)/condor_$(SYSCALL_LIB)


#
# For some reason checkpointing doesn't work on the RT's unless compiled
# with "-g".  
# 		-- mike
#

#if DOES_CHECKPOINTING
CKPT_FLAGS = 
#else
CKPT_FLAGS = -DNO_CKPT
#endif

#if IS_IBM032_BSD43
CFLAGS = $(STD_C_FLAGS) -g -DCONDOR $(CKPT_FLAGS)
#else
CFLAGS = $(STD_C_FLAGS) -DCONDOR $(CKPT_FLAGS)
#endif

TO_UPPER = $(PLATFORM_DIR)/condor_$(SYSCALL_LIB)/ToUpper

#if NEEDS_GROW_STACK
#define GROW_STACK grow_stack.o
#else
#define GROW_STACK
#endif

#if NEEDS_SPECIAL_SIGVEC
#define SPECIAL_SIGVEC _SIGVEC.o
#else
#define SPECIAL_SIGVEC
#endif

#if HAS_ADJTIME
#define ADJTIME_SRC adjtime.c
#define ADJTIME_OBJ adjtime.o
#else
#define ADJTIME_SRC
#define ADJTIME_OBJ
#endif

#if HAS_FLOCK
#define FLOCK_SRC flock.c
#define FLOCK_OBJ flock.o
#else
#define FLOCK_SRC
#define FLOCK_OBJ
#endif

#if HAS__UTSSYS
#define _UTSSYS_SRC _utssys.c
#define _UTSSYS_OBJ _utssys.o
#else
#define _UTSSYS_SRC
#define _UTSSYS_OBJ
#endif

#if HAS_GETDTABLESIZE
#define GETDTABLESIZE_SRC getdtablesize.c
#define GETDTABLESIZE_OBJ getdtablesize.o
#else
#define GETDTABLESIZE_SRC
#define GETDTABLESIZE_OBJ
#endif

#if HAS_GETPAGESIZE
#define GETPAGESIZE_SRC getpagesize.c
#define GETPAGESIZE_OBJ getpagesize.o
#else
#define GETPAGESIZE_SRC
#define GETPAGESIZE_OBJ
#endif

#if HAS_GETPGRP
#define GETPGRP_SRC getpgrp.c
#define GETPGRP_OBJ getpgrp.o
#else
#define GETPGRP_SRC
#define GETPGRP_OBJ
#endif

#if HAS_GETPGRP2
#define GETPGRP2_SRC getpgrp2.c
#define GETPGRP2_OBJ getpgrp2.o
#else
#define GETPGRP2_SRC
#define GETPGRP2_OBJ
#endif

#if HAS_KILLPG
#define KILLPG_SRC killpg.c
#define KILLPG_OBJ killpg.o
#else
#define KILLPG_SRC
#define KILLPG_OBJ
#endif

#if HAS_SETHOSTNAME
#define SETHOSTNAME_SRC sethostname.c
#define SETHOSTNAME_OBJ sethostname.o
#else
#define SETHOSTNAME_SRC
#define SETHOSTNAME_OBJ
#endif

#if HAS_GETHOSTNAME
#define GETHOSTNAME_SRC gethostname.c
#define GETHOSTNAME_OBJ gethostname.o
#else
#define GETHOSTNAME_SRC
#define GETHOSTNAME_OBJ
#endif

#if HAS_SETREGID
#define SETREGID_SRC setregid.c
#define SETREGID_OBJ setregid.o
#else
#define SETREGID_SRC
#define SETREGID_OBJ
#endif

#if HAS_SETREUID
#define SETREUID_SRC setreuid.c
#define SETREUID_OBJ setreuid.o
#else
#define SETREUID_SRC
#define SETREUID_OBJ
#endif

#if HAS_SETRESUID
#define SETRESUID_SRC setresuid.c
#define SETRESUID_OBJ setresuid.o
#else
#define SETRESUID_SRC
#define SETRESUID_OBJ
#endif

#if HAS_SETRESGID
#define SETRESGID_SRC setresgid.c
#define SETRESGID_OBJ setresgid.o
#else
#define SETRESGID_SRC
#define SETRESGID_OBJ
#endif

#if HAS_UTIMES
#define UTIMES_SRC utimes.c
#define UTIMES_OBJ utimes.o
#else
#define UTIMES_SRC
#define UTIMES_OBJ
#endif

#if HAS_UTIME
#define UTIME_SRC utime.c
#define UTIME_OBJ utime.o
#else
#define UTIME_SRC
#define UTIME_OBJ
#endif

#if HAS_VHANGUP
#define VHANGUP_SRC vhangup.c
#define VHANGUP_OBJ vhangup.o
#else
#define VHANGUP_SRC
#define VHANGUP_OBJ
#endif

#if NEEDS_FAKE_GETMNT
#define FAKE_GETMNT_SRC fake_getmnt.c
#define FAKE_GETMNT_OBJ fake_getmnt.o
#else
#define FAKE_GETMNT_SRC
#define FAKE_GETMNT_OBJ
#endif

#if NEEDS_SPECIAL_SETJMP
#define SETJMP_SRC condor_setjmp_vax.c
#define SETJMP_OBJ condor_setjmp_vax.o
#else
#define SETJMP_SRC
#define SETJMP_OBJ
#endif

#if DOES_CHECKPOINTING
CKPT_OBJ = \
	CONDOR_sysnames.o CONDOR_syscalls.o _mkckpt.o _updateckpt.o ckpt.o \
	restart.o ckpt_main.rem.o syscall_mode.o GROW_STACK SETJMP_OBJ
#else
CKPT_OBJ = \
	CONDOR_sysnames.o ckpt_main.rem.o syscall_mode.o CONDOR_syscalls.o \
	fake_ckpt.o
#endif

#if IS_HPPAR_HPUX8
SPEC_OBJ = \
	statfs.o GETEUID.o GETEGID.o getppid.o sigvector.o SIGVEC.o wait3.o \
	_start.o KILLPG.o
#else
SPEC_OBJ = \
	STATFS.o GETEUID.o GETEGID.o GETPPID.o SIGVEC.o SPECIAL_SIGVEC WAIT3.o \
	MMAP.o
#endif

LIBDIRS = ../condor_util_lib ../condor_xdr_lib

CKPT_SRC = \
	CONDOR_sysnames.c CONDOR_syscalls.c _mkckpt.c _updateckpt.c ckpt.c \
	restart.c ckpt_main.c syscall_mode.c SETJMP_SRC

OTHER_SRC = \
	xfer_file.c extern_name.c extern_path.c FAKE_GETMNT_SRC intern_path.c \
	nfs.c glue.c

SRC_1 = \
	_exit.c accept.c access.c acct.c ADJTIME_SRC async_daemon.c bind.c \
	chdir.c chmod.c chown.c chroot.c close.c connect.c creat.c dup.c \
	dup2.c execv.c execve.c exportfs.c fchmod.c fchown.c fcntl.c \
	finfo.c FLOCK_SRC fork.c fstat.c fstatfs.c fsync.c ftruncate.c \
	getdirentries.c getdomainname.c getdopt.c GETDTABLESIZE_SRC getegid.c \
	geteuid.c getfh.c getgid.c getgroups.c gethostid.c GETHOSTNAME_SRC \
	getitimer.c GETPAGESIZE_SRC getpeername.c getpid.c getppid.c \
	getpriority.c getrlimit.c getrusage.c getsockname.c getsockopt.c \
	gettimeofday.c getuid.c ioctl.c isatty.c kill.c KILLPG_SRC link.c \
	listen.c lseek.c lstat.c madvise.c mincore.c mkdir.c mknod.c mmap.c \
	_UTSSYS_SRC GETPGRP_SRC GETPGRP2_SRC

SRC_2 = \
	mount.c mprotect.c mremap.c munmap.c nfssvc.c open.c pipe.c profil.c \
	ptrace.c quotactl.c read.c readlink.c readv.c reboot.c recv.c \
	recvfrom.c recvmsg.c rename.c rmdir.c select.c send.c sendmsg.c \
	sendto.c setdomainname.c setdopt.c setgroups.c sethostid.c \
	SETHOSTNAME_SRC setitimer.c setpgrp.c setpriority.c SETREGID_SRC \
	SETREUID_SRC setrlimit.c setsockopt.c settimeofday.c shutdown.c \
	sigblock.c sigpause.c sigreturn.c sigsetmask.c sigstack.c sigvec.c \
	socket.c socketpair.c sstk.c stat.c statfs.c swapon.c symlink.c \
	sync.c truncate.c umask.c unlink.c unmount.c UTIMES_SRC VHANGUP_SRC \
	wait.c wait3.c write.c writev.c SETRESUID_SRC SETRESGID_SRC UTIME_SRC

#
# This is broken into two parts because some cpp's can't handle such a
# long line.
#
CLIB_SRC = $(SRC_1) $(SRC_2)

SOURCE_FILES = $(CKPT_SRC) $(OTHER_SRC) $(CLIB_SRC)


OTHER_OBJ = \
	xfer_file.o extern_name.o extern_path.o FAKE_GETMNT_OBJ intern_path.o \
	nfs.o glue.o

OBJ_1 = \
	_exit.o accept.o access.o acct.o ADJTIME_OBJ async_daemon.o \
	bind.o chdir.o chmod.o chown.o chroot.o close.o connect.o \
	creat.o dup.o dup2.o execv.o execve.o exportfs.o fchmod.o \
	fchown.o fcntl.o finfo.o FLOCK_OBJ fork.o fstat.o fstatfs.o \
	fsync.o ftruncate.o getdirentries.o getdomainname.o getdopt.o \
	GETDTABLESIZE_OBJ getegid.o geteuid.o getfh.o getgid.o \
	getgroups.o gethostid.o GETHOSTNAME_OBJ getitimer.o GETPAGESIZE_OBJ \
	getpeername.o getpid.o getppid.o getpriority.o \
	getrlimit.o getrusage.o getsockname.o getsockopt.o \
	gettimeofday.o getuid.o ioctl.o isatty.o kill.o KILLPG_OBJ link.o \
	GETPGRP_OBJ GETPGRP2_OBJ

OBJ_2 = \
	_UTSSYS_OBJ listen.o lseek.o lstat.o madvise.o mincore.o mkdir.o mknod.o \
	mmap.o mount.o mprotect.o mremap.o munmap.o nfssvc.o open.o \
	pipe.o profil.o ptrace.o quotactl.o read.o readlink.o readv.o \
	reboot.o recv.o recvfrom.o recvmsg.o rename.o rmdir.o select.o \
	send.o sendmsg.o sendto.o setdomainname.o setdopt.o setgroups.o \
	sethostid.o SETHOSTNAME_OBJ setitimer.o setpgrp.o setpriority.o \
	SETREGID_OBJ SETREUID_OBJ setrlimit.o setsockopt.o settimeofday.o \
	shutdown.o sigblock.o sigpause.o sigreturn.o sigsetmask.o \
	sigstack.o sigvec.o socket.o socketpair.o sstk.o stat.o \
	statfs.o swapon.o symlink.o sync.o truncate.o umask.o unlink.o \
	unmount.o UTIMES_OBJ VHANGUP_OBJ wait.o wait3.o write.o writev.o \
	SETRESUID_OBJ SETRESGID_OBJ UTIME_OBJ

#
# This is broken into two parts because some cpp's can't handle such a
# long line.
#
CLIB_OBJ = $(OBJ_1) $(OBJ_2)

UTIL_OBJ = \
	../condor_util_lib/blankline.o ../condor_util_lib/config.o \
	../condor_util_lib/do_connect.o ../condor_util_lib/dprintf.o \
	../condor_util_lib/dprintf_config.o ../condor_util_lib/except.o \
	../condor_util_lib/expr.o ../condor_util_lib/history.o \
	../condor_util_lib/job_queue.o ../condor_util_lib/ltrunc.o \
	../condor_util_lib/mkargv.o ../condor_util_lib/perror.o \
	../condor_util_lib/proc.o ../condor_util_lib/condor_config.o \
	../condor_util_lib/condor_errlst.o ../condor_util_lib/signames.o \
	../condor_util_lib/status.o ../condor_util_lib/strdup.o \
	../condor_util_lib/stricmp.o ../condor_util_lib/update_rusage.o \
	../condor_util_lib/$(GETWD_OBJ)

XDR_OBJ = \
	../condor_xdr_lib/xdr_Init.o ../condor_xdr_lib/xdr_direntries.o \
	../condor_xdr_lib/xdr_expr.o ../condor_xdr_lib/xdr_fdset.o \
	../condor_xdr_lib/xdr_io.o ../condor_xdr_lib/xdr_itimerval.o \
	../condor_xdr_lib/xdr_mach_rec.o ../condor_xdr_lib/xdr_ports.o \
	../condor_xdr_lib/xdr_prio_rec.o ../condor_xdr_lib/xdr_proc.o \
	../condor_xdr_lib/xdr_ptr.o ../condor_xdr_lib/xdr_record.o \
	../condor_xdr_lib/xdr_rlimit.o ../condor_xdr_lib/xdr_rusage.o \
	../condor_xdr_lib/xdr_stat.o ../condor_xdr_lib/xdr_statfs.o \
	../condor_xdr_lib/xdr_status.o ../condor_xdr_lib/xdr_timeval.o \
	../condor_xdr_lib/xdr_timezone.o ../condor_xdr_lib/xdr_wait.o

OBJECT_FILES = \
	$(CKPT_OBJ) $(SPEC_OBJ) $(OTHER_OBJ) $(CLIB_OBJ) $(UTIL_OBJ) $(XDR_OBJ)


#if DOES_CHECKPOINTING
all_target(libcondor.a libckpt.a condor_rt0.o)
#else
all_target(libcondor.a)
#endif

tags_target($(SOURCE_FILES),$(LIBDIRS))
depend_target($(SOURCE_FILES))
program_target($(TO_UPPER),ToUpper.o,$(NULL),release)

#if IS_HPPAR_HPUX8
uppercase_target(getegid.o,GETEGID.o,getegid)
uppercase_target(geteuid.o,GETEUID.o,geteuid)

LIB_BSD = /home/puma/condor/comp/my_bsd.a
SIGVEC.o: $(LIB_BSD) $(TO_UPPER)
	cd $(TMP_DIR); AR_EXTRACT( $(LIB_BSD), sigvec.o )
	$(TO_UPPER) $(TMP_DIR)/sigvec.o SIGVEC.o sigvec
	rm -f $(TMP_DIR)/sigvec.o

KILLPG.o: $(LIB_BSD) $(TO_UPPER)
	cd $(TMP_DIR); AR_EXTRACT( $(LIB_BSD), killpg.o )
	$(TO_UPPER) $(TMP_DIR)/killpg.o KILLPG.o killpg
	rm -f $(TMP_DIR)/killpg.o

#else
uppercase_target(statfs.o,STATFS.o,statfs)
uppercase_target(getppid.o,GETPPID.o,getppid)
uppercase_target(sigvec.o,SIGVEC.o,sigvec)
uppercase_target(_sigvec.o,_SIGVEC.o,sigvec)
uppercase_target(wait3.o,WAIT3.o,wait3)
uppercase_target(getegid.o,GETEGID.o,getegid)
uppercase_target(geteuid.o,GETEUID.o,geteuid)
uppercase_target(mmap.o,MMAP.o,mmap)
#endif

#
# This is the only file which must be compiled with the -ma flag,
# and thus has a special rule.  N.B. we also need the "-g" here as
# this file is only used by the RT's.
#
grow_stack.o: grow_stack.c
	$(CC) -c -g -ma $(CFLAGS) grow_stack.c

#
# Create a replacement for libc.a to be linked with condor programs.
# N.B. This is done differently than other libraries in that we start out
# with a copy of libc, and replace all the system calls.  Don't
# use the default rule for this one!
#
libcondor.a: $(OBJECT_FILES)
	cp $(LIBC) libcondor.a
	chmod u+w libcondor.a
	AR_REPLACE( libcondor.a, $(OBJECT_FILES) )
release:: libcondor.a
	cp libcondor.a $(RELEASE_DIR)/lib
	RANLIB_TOUCH( $(RELEASE_DIR)/lib/libcondor.a )
clean::
	rm -f libcondor.a $(OBJECT_FILES)

#
# Create a replacement for libc.a to be linked with programs for
# checkpointing, but not remote execution.  N.B. This is done differently
# than other libraries in that we start out with a copy of libcondor.a,
# and replace ckpt_main.rem.o with ckpt_main.loc.o, (checkpointing
# only, no remote system calls).  Don't use the default rule for this one!
#
#if DOES_CHECKPOINTING
libckpt.a: ../condor_$(SYSCALL_LIB)/libcondor.a ckpt_main.loc.o
	rm -f libckpt.a
	cp libcondor.a  libckpt.a
	chmod u+w libckpt.a
	AR_DELETE( libckpt.a, ckpt_main.rem.o )
	AR_REPLACE( libckpt.a, ckpt_main.loc.o )
#else
libckpt.a: ../condor_$(SYSCALL_LIB)/libcondor.a
	cp ../condor_$(SYSCALL_LIB)/libcondor.a libckpt.a
#endif
release:: libckpt.a
	cp libckpt.a $(RELEASE_DIR)/lib
	RANLIB_TOUCH( $(RELEASE_DIR)/lib/libckpt.a )
clean::
	rm -f ckpt_main.rem.o libckpt.a



#if IS_HPPAR_HPUX8
_start.o: /lib/libc.a $(TO_UPPER)
	ar x /lib/libc.a _start.o
	$(TO_UPPER) _start.o condor_start.o main
	mv condor_start.o _start.o
clean::
	rm -f condor_start.o _start.o
#else
#
# Create a replacement for crt0.o to be linked with condor programs.
# N.B. This is done differently than other objects in that we start out
# with a copy of crt0.o, and change the name of "main" to "MAIN".
#
condor_rt0.o: /lib/crt0.o $(TO_UPPER)
	$(TO_UPPER) /lib/crt0.o condor_rt0.o main
release:: condor_rt0.o
	cp condor_rt0.o $(RELEASE_DIR)/lib
clean::
	rm -f condor_rt0.o
#endif

#
# In this version we compile with CONDOR defined, and get a
# checkpointing plus remote system call version. 
#
ckpt_main.rem.o: ckpt_main.c
	$(CC) -c $(CFLAGS) ckpt_main.c
	mv ckpt_main.o ckpt_main.rem.o

#
# In this version we compile without defining CONDOR, and get a
# checkpoint only, (no remote system calls) version.
#
#if IS_IBM032_BSD43
ckpt_main.loc.o: ckpt_main.c
	$(CC) -c $(STD_C_FLAGS) -g ckpt_main.c
	mv ckpt_main.o ckpt_main.loc.o
#else
ckpt_main.loc.o: ckpt_main.c
	$(CC) -c $(STD_C_FLAGS) ckpt_main.c
	mv ckpt_main.o ckpt_main.loc.o
#endif


#
# Special dependencies
#
$(UTIL_OBJ):
	@echo The util library must be remade before the condor library.
	@false

$(XDR_OBJ):
	@echo The xdr library must be remade before the condor library.
	@false
