SRC_DIR = $(SRC_TREE)/condor_$(SYSCALL_LIB)
CFLAGS = $(STD_C_FLAGS) -DCONDOR -g

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

#define SourceFiles \
	CONDOR_sysnames.c CONDOR_syscalls.c \
	_mkckpt.c _updateckpt.c display.c ckpt.c restart.c syscall_mode.c \
	xfer_file.c finfo.c ckpt_main.c map_file.c C_getenv.c \
	stubs.c extern_path.c fake_getmnt.c nfs.c intern_path.c extern_name.c

#define UtilObjects \
	../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

#define XdrObjects \
	../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

#define ObjectFiles \
	UtilObjects XdrObjects CONDOR_sysnames.o CONDOR_syscalls.o \
	_mkckpt.o _updateckpt.o display.o ckpt.o restart.o syscall_mode.o \
	xfer_file.o finfo.o ckpt_main.rem.o map_file.o \
	extern_path.o fake_getmnt.o nfs.o intern_path.o \
	extern_name.o stubs.o condor_shr.o

all_target( libcondor.a libckpt.a condor_rt0.o syscall.shr.o syscall.exp libfort.a )
tags_target(SourceFiles,$(NULL))
depend_target(SourceFiles)
program_target(ToUpper,ToUpper.o,$(NULL),release)

#if IS_R6000_AIX32
program_target(zap,zap.o,$(NULL),norelease)
#endif

prev_library_target(UtilObjects,../condor_util_lib,$(SRC_DIR))
prev_library_target(XdrObjects,../condor_xdr_lib,$(SRC_DIR))

release::
	cp syscall.exp $(RELEASE_DIR)/lib
	cp C_getenv.o $(RELEASE_DIR)/lib

CMNT
CMNT Create a replacement for libc.a by copying it and replacing all
CMNT the system calls with our own version.
CMNT
libcondor.a:	ObjectFiles
	rm -f libcondor.a
	cp $(LIBC) libcondor.a
	chmod u+w libcondor.a
	AR_DELETE( libcondor.a, shr.o )
	AR_REPLACE( libcondor.a, ObjectFiles )
release:: libcondor.a
	cp libcondor.a  $(RELEASE_DIR)/lib
	RANLIB_TOUCH( $(RELEASE_DIR)/lib/libcondor.a )
clean::
	rm -f libcondor.a ObjectFiles

CMNT
CMNT Create a replacement for libc.a to be linked with programs for
CMNT checkpointing, but not remote execution.  N.B. This is done differently
CMNT than other libraries in that we start out with a copy of libcondor.a,
CMNT and replace ckpt_main.rem.o with ckpt_main.loc.o, (checkpointing
CMNT only, no remote system calls).  Don't use the default rule for this one!
CMNT
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 )
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

CMNT
CMNT Condor version of libc.a/shr.o.
CMNT Take the original shr.o and strip out the import from /unix.
CMNT This will force these symbols to be resolved from stubs.o which
CMNT will satisfy them with calls to syscall().
CMNT
#if IS_R6000_AIX31
condor_shr.o: $(LIBC)
	AR_EXTRACT( $(LIBC), shr.o )
	ld -o condor_shr.o \
		-bnoautoimp -r \
		shr.o
clean::
	rm -f shr.o
#else	/* IS_R6000_AIX32 */
condor_shr.o: $(LIBC) zap
	AR_EXTRACT( $(LIBC), shr.o )
	mv shr.o condor_shr.o
	zap condor_shr.o
clean::
	rm -f shr.o condor_shr.o
#endif

CMNT
CMNT Provide the syscall() routine.
CMNT Imports: all system calls from /unix
CMNT Exports: syscall() and CondorErrno
CMNT
syscall.shr.o: syscall.o syscall.exp
	ld -o syscall.shr.o \
		-bM:SRE -T512 \
		-bE:syscall.exp \
		-bI:$(SYSCALLS_EXP) \
		syscall.o
release::
	rm -f $(RELEASE_DIR)/lib/syscall.shr.o
	cp syscall.shr.o $(RELEASE_DIR)/lib
clean::
	rm -f syscall.shr.o syscall.o

CMNT
CMNT Be sure every Condor program contains one object compiled with "-g".
CMNT Otherwise there will not be a DEBUG section in the final executable,
CMNT and the checkpointing code will fail!
CMNT
CMNT In this version we compile with CONDOR defined, and get a
CMNT checkpointing plus remote system call version. 
CMNT
ckpt_main.rem.o: ckpt_main.c
	$(CC) -c $(CFLAGS) -g ckpt_main.c
	mv ckpt_main.o ckpt_main.rem.o

CMNT
CMNT Be sure every Condor program contains one object compiled with "-g".
CMNT Otherwise there will not be a DEBUG section in the final executable,
CMNT and the checkpointing code will fail!
CMNT
CMNT In this version we compile without defining CONDOR, and get a
CMNT checkpoint only, (no remote system calls) version.
CMNT
ckpt_main.loc.o: ckpt_main.c
	$(CC) -c $(STD_C_FLAGS) -g ckpt_main.c
	mv ckpt_main.o ckpt_main.loc.o

CMNT
CMNT Replaces /lib/crt0.o in programs linked for execution with Condor
CMNT
condor_rt0.o: $(CRT0) $(TO_UPPER)
	$(TO_UPPER) $(CRT0) condor_rt0.o main MAIN
release::
	cp condor_rt0.o $(RELEASE_DIR)/lib
clean::
	rm -f condor_rt0.o

CMNT
CMNT The aix fortran library libxlf.a defines a getenv() routine which takes 2
CMNT arguments, the name of the environment variable, and buffer in which to
CMNT put the associated value.
CMNT
CMNT The aix C library libc.a defines a getenv routine which takes 1 argument,
CMNT the name of the environment variable, and it returns a pointer to the
CMNT associated value.
CMNT
CMNT Condor programs need to be linked with the condor libraries, which will
CMNT end up calling getenv(), and expecting the C version.  We therefore
CMNT supply our own C version, so that we can get it linked in before the
CMNT fortran version gets linked.
CMNT 
CMNT Of course this will break any fortran programs which call getenv and expect
CMNT the fortran version!  If some AIXpert knows how to fix this, I would be
CMNT very happy to learn about it. -- mike
CMNT
library_target(libfort.a,C_getenv.o,release)
