srcdir		= @srcdir@
include @TOP_OBJDIR@/src/config/Makefile.config
include @TOP_OBJDIR@/src/config/Makefile.lwp

SHELL		= /bin/sh

all: run-tests OpenAFS/Dirpath.pm $(TEST_PROGRAMS) OpenAFS/Dirpath.sh
	@chmod +x run-tests

SYS_LIBS	= ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/util.a

AUTH_LIBS	= ${TOP_LIBDIR}/libauth.a ${SYS_LIBS}

INT_LIBS	= ${TOP_LIBDIR}/libafsint.a ${TOP_LIBDIR}/libsys.a ${TOP_LIBDIR}/librxkad.a ${TOP_LIBDIR}/librx.a ${TOP_LIBDIR}/liblwp.a ${TOP_LIBDIR}/libafscom_err.a ${TOP_LIBDIR}/util.a ${TOP_LIBDIR}/libafsrfc3961.a

TEST_PROGRAMS = write-ro-file hello-world read-vs-mmap read-vs-mmap2	 \
		mmap-and-read large-dir large-dir2 large-dir3 mountpoint \
		test-setgroups test-setpag hardlink1 hardlink2 mkdir2	 \
		create-files create-symlinks create-dirs dup2-and-unlog	 \
		readdir-vs-lstat read-write create-remove mkdir3         \
		symlink echo-n test-parallel1 test-parallel2 create-stat \
		kill-softly kill-softer rm-rf exit-wo-close	         \
		mmap-vs-read mmap-vs-read2 strange-characters-c pine	 \
		append-over-page write-ucc utime-dir mmap-shared-write	 \
		rename5 rename-under-feet write-closed write-closed2	 \
		truncate fchmod make-page utime-file rename6 	         \
		write3 still-there-p write-large afscp hardlink4         \
		intr-read asu truncate-files mmap-cat blocks-new-file 	 \
		fsx write-rand

TEST_OBJS     = write-ro-file.o read-vs-mmap.o read-vs-mmap2.o		   \
		mmap-and-read.o large-dir.o large-dir2.o large-dir3.o	   \
		test-setgroups.o test-setpag.o hardlink1.o hardlink2.o	   \
		mkdir2.o create-files.o create-symlinks.o create-dirs.o	   \
		dup2-and-unlog.o readdir-vs-lstat.o read-write.o           \
		create-remove.o symlink.o echo-n.o test-parallel1.o	   \
		test-parallel1.o mkdir3.o rename6.o			   \
		create-stat.o kill-softly.o kill-softer.o rm-rf.o          \
		exit-wo-close.o mmap-vs-read.o mmap-vs-read2.o		   \
		strange-characters-c.o pine.o append-over-page.o	   \
		write-ucc.o utime-dir.o mmap-shared-write.o rename5.o	   \
		rename-under-feet.o write-closed.o write-closed2.o	   \
		truncate.o fchmod.o make-page.o utime-file.o	           \
		write3.o still-there-p.o write-large.o hardlink4.o         \
		intr-read.o asu.o truncate-files.o mmap-cat.o		   \
		blocks-new-file.o fsx.o afscp.o afscp_callback.o	   \
		write-rand.o

TEST_SRCS     = write-ro-file.c read-vs-mmap.c read-vs-mmap2.c		   \
		mmap-and-read.c large-dir.c large-dir2.c large-dir3.c	   \
		test-setgroups.c test-setpag.c hardlink1.c hardlink2.c	   \
		mkdir2.c create-files.c create-symlinks.c create-dirs.c	   \
		dup2-and-unlog.c readdir-vs-lstat.c read-write.c           \
		create-remove.c symlink.c echo-n.c test-parallel1.c	   \
		test-parallel2.c mkdir3.c rename6.c			   \
		create-stat.c kill-softly.c kill-softer.c rm-rf.c          \
		exit-wo-close.c mmap-vs-read.c mmap-vs-read2.c		   \
		strange-characters-c.c pine.c append-over-page.c	   \
		write-ucc.c utime-dir.c mmap-shared-write.c rename5.c	   \
		rename-under-feet.c write-closed.c write-closed2.c	   \
		truncate.c fchmod.c make-page.c utime-file.c	           \
		write3.c still-there-p.c write-large.c hardlink4.c         \
		intr-read.c asu.c truncate-files.c mmap-cat.c		   \
		blocks-new-file.c fsx.c afscp.c afscp_callback.c	   \
		write-rand.c

EXTRA_OBJS = err.o errx.o warn.o warnx.o vwarn.o vwarnx.o verr.o verrx.o warnerr.o snprintf.o

fsx: fsx.o $(EXTRA_OBJS)
	$(AFS_LDRULE) fsx.o $(EXTRA_OBJS) $(LIBS)

write-rand: write-rand.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-rand.o $(EXTRA_OBJS) $(LIBS)

write-ro-file: write-ro-file.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-ro-file.o $(EXTRA_OBJS) $(LIBS)

write-large: write-large.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-large.o $(EXTRA_OBJS) $(LIBS)

read-vs-mmap: read-vs-mmap.o $(EXTRA_OBJS)
	$(AFS_LDRULE) read-vs-mmap.o $(EXTRA_OBJS) $(LIBS)

read-vs-mmap2: read-vs-mmap2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) read-vs-mmap2.o $(EXTRA_OBJS) $(LIBS)

mmap-vs-read: mmap-vs-read.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mmap-vs-read.o $(EXTRA_OBJS) $(LIBS)

mmap-vs-read2: mmap-vs-read2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mmap-vs-read2.o $(EXTRA_OBJS) $(LIBS)

read-write: read-write.o $(EXTRA_OBJS)
	$(AFS_LDRULE) read-write.o $(EXTRA_OBJS) $(LIBS)

mmap-and-read: mmap-and-read.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mmap-and-read.o $(EXTRA_OBJS) $(LIBS)

large-dir: large-dir.o $(EXTRA_OBJS)
	$(AFS_LDRULE) large-dir.o $(EXTRA_OBJS) $(LIBS)

large-dir2: large-dir2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) large-dir2.o $(EXTRA_OBJS) $(LIBS)

large-dir3: large-dir3.o $(EXTRA_OBJS)
	$(AFS_LDRULE) large-dir3.o $(EXTRA_OBJS) $(LIBS)

fchmod: fchmod.o $(EXTRA_OBJS)
	$(AFS_LDRULE) fchmod.o $(EXTRA_OBJS) $(LIBS)

truncate: truncate.o $(EXTRA_OBJS)
	$(AFS_LDRULE) truncate.o $(EXTRA_OBJS) $(LIBS)

make-page: make-page.o $(EXTRA_OBJS)
	$(AFS_LDRULE) make-page.o $(EXTRA_OBJS) $(LIBS)

still-there-p: still-there-p.o $(EXTRA_OBJS)
	$(AFS_LDRULE) still-there-p.o $(EXTRA_OBJS) $(LIBS)

intr-read: intr-read.o $(EXTRA_OBJS)
	$(AFS_LDRULE) intr-read.o $(EXTRA_OBJS) $(LIBS)

blocks-new-file: blocks-new-file.o $(EXTRA_OBJS)
	$(AFS_LDRULE) blocks-new-file.o $(EXTRA_OBJS) $(LIBS)

asu: asu.o $(EXTRA_OBJS)
	$(AFS_LDRULE) asu.o $(EXTRA_OBJS) $(LIBS)

test-setgroups: test-setgroups.o $(EXTRA_OBJS)
	$(AFS_LDRULE) test-setgroups.o $(EXTRA_OBJS) $(SYS_LIBS) $(LIBS)

test-setpag: test-setpag.o $(EXTRA_OBJS)
	$(AFS_LDRULE) test-setpag.o $(EXTRA_OBJS) $(SYS_LIBS) $(LIBS)

hardlink1: hardlink1.o $(EXTRA_OBJS)
	$(AFS_LDRULE) hardlink1.o $(EXTRA_OBJS) $(LIBS)

hardlink2: hardlink2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) hardlink2.o $(EXTRA_OBJS) $(LIBS)

hardlink4: hardlink4.o $(EXTRA_OBJS)
	$(AFS_LDRULE) hardlink4.o $(EXTRA_OBJS) $(LIBS)

mkdir2: mkdir2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mkdir2.o $(EXTRA_OBJS) $(LIBS)

mkdir3: mkdir3.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mkdir3.o $(EXTRA_OBJS) $(LIBS)

create-files: create-files.o $(EXTRA_OBJS)
	$(AFS_LDRULE) create-files.o $(EXTRA_OBJS) $(LIBS)

create-symlinks: create-symlinks.o $(EXTRA_OBJS)
	$(AFS_LDRULE) create-symlinks.o $(EXTRA_OBJS) $(LIBS)

create-dirs: create-dirs.o $(EXTRA_OBJS)
	$(AFS_LDRULE) create-dirs.o $(EXTRA_OBJS) $(LIBS)

create-remove: create-remove.o $(EXTRA_OBJS)
	$(AFS_LDRULE) create-remove.o $(EXTRA_OBJS) $(LIBS)

dup2-and-unlog: dup2-and-unlog.o $(EXTRA_OBJS)
	$(AFS_LDRULE) dup2-and-unlog.o  $(EXTRA_OBJS) $(AUTH_LIBS) $(LIBS)

readdir-vs-lstat: readdir-vs-lstat.o $(EXTRA_OBJS)
	$(AFS_LDRULE) readdir-vs-lstat.o $(EXTRA_OBJS) $(LIBS)

symlink: symlink.o $(EXTRA_OBJS)
	$(AFS_LDRULE) symlink.o $(EXTRA_OBJS) $(LIBS)

echo-n: echo-n.o $(EXTRA_OBJS)
	$(AFS_LDRULE) echo-n.o $(EXTRA_OBJS)

test-parallel1: test-parallel1.o $(EXTRA_OBJS)
	$(AFS_LDRULE) test-parallel1.o $(EXTRA_OBJS) $(LIBS)

test-parallel2: test-parallel2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) test-parallel2.o $(EXTRA_OBJS) $(LIBS)

create-stat: create-stat.o fs_lib.o $(EXTRA_OBJS)
	$(AFS_LDRULE) create-stat.o fs_lib.o $(EXTRA_OBJS) $(SYS_LIBS) $(LIBS)

kill-softly: kill-softly.o $(EXTRA_OBJS)
	$(AFS_LDRULE) kill-softly.o $(EXTRA_OBJS) $(LIBS)

kill-softer: kill-softer.o $(EXTRA_OBJS)
	$(AFS_LDRULE) kill-softer.o $(EXTRA_OBJS) $(LIBS)

rm-rf: rm-rf.o fs_lib.o $(EXTRA_OBJS)
	$(AFS_LDRULE) rm-rf.o fs_lib.o $(EXTRA_OBJS) $(SYS_LIBS) $(LIBS)

exit-wo-close: exit-wo-close.o $(EXTRA_OBJS)
	$(AFS_LDRULE) exit-wo-close.o $(EXTRA_OBJS) $(LIBS)

strange-characters-c: strange-characters-c.o $(EXTRA_OBJS)
	$(AFS_LDRULE) strange-characters-c.o $(EXTRA_OBJS) $(LIBS)

pine: pine.o $(EXTRA_OBJS)
	$(AFS_LDRULE) pine.o $(EXTRA_OBJS) $(LIBS)

append-over-page: append-over-page.o $(EXTRA_OBJS)
	$(AFS_LDRULE) append-over-page.o $(EXTRA_OBJS) $(LIBS)

write-ucc: write-ucc.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-ucc.o $(EXTRA_OBJS) $(LIBS)

utime-dir: utime-dir.o $(EXTRA_OBJS)
	$(AFS_LDRULE) utime-dir.o $(EXTRA_OBJS) $(LIBS)

utime-file: utime-file.o $(EXTRA_OBJS)
	$(AFS_LDRULE) utime-file.o $(EXTRA_OBJS) $(LIBS)

mmap-shared-write: mmap-shared-write.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mmap-shared-write.o $(EXTRA_OBJS) $(LIBS)

rename5: rename5.o $(EXTRA_OBJS)
	$(AFS_LDRULE) rename5.o $(EXTRA_OBJS) $(LIBS)

rename6: rename6.o $(EXTRA_OBJS)
	$(AFS_LDRULE) rename6.o $(EXTRA_OBJS) $(LIBS)

write3: write3.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write3.o $(EXTRA_OBJS) $(LIBS)

rename-under-feet: rename-under-feet.o $(EXTRA_OBJS)
	$(AFS_LDRULE) rename-under-feet.o $(EXTRA_OBJS) $(LIBS)

write-closed: write-closed.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-closed.o $(EXTRA_OBJS) $(LIBS)

write-closed2: write-closed2.o $(EXTRA_OBJS)
	$(AFS_LDRULE) write-closed2.o $(EXTRA_OBJS) $(SYS_LIBS) $(LIBS)

truncate-files: truncate-files.o $(EXTRA_OBJS)
	$(AFS_LDRULE) truncate-files.o $(EXTRA_OBJS) $(LIBS)

mmap-cat: mmap-cat.o $(EXTRA_OBJS)
	$(AFS_LDRULE) mmap-cat.o $(EXTRA_OBJS) $(LIBS)

run-tests: run-tests.in
	(cd ../..; CONFIG_FILES=src/tests/run-tests CONFIG_HEADERS= $(SHELL) @TOP_OBJDIR@/config.status)
	@chmod +x run-tests

afscp: afscp.o afscp_callback.o $(EXTRA_OBJS)
	$(AFS_LDRULE) afscp.o afscp_callback.o $(EXTRA_OBJS) $(INT_LIBS) ${XLIBS}

hello-world:   hello-world.in
	sed -e "s!%CC%!$(CC)!" $(srcdir)/hello-world.in > $@
	chmod +x hello-world

mountpoint:   mountpoint.in
	sed -e "s!%bindir%!$(bindir)!" $(srcdir)/mountpoint.in > $@
	chmod +x mountpoint

dest:

install:

uninstall:

clean:
	-rm -f *.o  run-tests $(TEST_PROGRAMS) OpenAFS/Dirpath.pm \
	OpenAFS/Dirpath.sh

include ../config/Makefile.version

TAGS:	$(TEST_SRCS)
	etags $(TEST_SRCS)

check: run-tests $(TEST_PROGRAMS)
	./run-tests -all

check-fast: run-tests $(TEST_PROGRAMS)
	./run-tests -all -fast

# Note: The autoconf variables are not fully expanded
#       until make is run so we resort to creating the
#       configuration at make time.
OpenAFS/Dirpath.pm: Makefile
	@echo "Creating OpenAFS/Dirpath.pm"
	@echo "# This is -*- perl -*-"                          >$@
	@echo "# auto-generated by src/tests/Makefile"          >>$@
	@echo "# DO NOT EDIT"                                   >>$@
	@echo "package OpenAFS::Dirpath;"                       >>$@
	@echo "use strict;"                                     >>$@
	@echo "use vars qw( @ISA @EXPORT \$$openafsdirpath);"   >>$@
	@echo "@ISA = qw(Exporter);"                            >>$@
	@echo "require Exporter;"                               >>$@
	@echo "@EXPORT = qw(\$$openafsdirpath);"                >>$@
	@echo ""                                                >>$@
	@echo "\$$openafsdirpath = {"                           >>$@
	@echo "  'afsconfdir'       => '@afsconfdir@',"         >>$@
	@echo "  'viceetcdir'       => '@viceetcdir@',"         >>$@
	@echo "  'afssrvbindir'     => '@afssrvbindir@',"       >>$@
	@echo "  'afssrvsbindir'    => '@afssrvsbindir@',"      >>$@
	@echo "  'afssrvlibexecdir' => '@afssrvlibexecdir@',"   >>$@
	@echo "  'afsdbdir'         => '@afsdbdir@',"           >>$@
	@echo "  'afslogsdir'       => '@afslogsdir@',"         >>$@
	@echo "  'afslocaldir'      => '@afslocaldir@',"        >>$@
	@echo "  'afsbackupdir'     => '@afsbackupdir@',"       >>$@
	@echo "  'afsbosconfigdir'  => '@afsbosconfigdir@',"    >>$@
	@echo "  'ostype'           => '@MKAFS_OSTYPE@',"       >>$@
	@if test "@afsconfdir@" = "/usr/afs/etc" ; then \
		echo "  # transarc paths" ;\
		echo "  'cachedir'     => '/usr/vice/cache'," ;\
		echo "  'afsddir'      => '/usr/vice/etc'," ;\
		echo "  'initdir'      => '/usr/vice/etc',"  ;\
		echo "  'afskerneldir' => '/usr/vice/etc/modload'," ;\
		echo "  'afswsbindir'  => '/usr/afsws/bin'," ;\
	else \
		echo "  # modern paths" ;\
		echo "  'cachedir'     => '@localstatedir@/openafs/cache'," ;\
		echo "  'afsddir'      => '@afssrvsbindir@'," ;\
		echo "  'initdir'      => '@sysconfdir@',"  ;\
		echo "  'afskerneldir' => '@afskerneldir@'," ;\
		echo "  'afswsbindir'  => '@afssrvbindir@'," ;\
	fi >>$@
	@echo "};"                                              >>$@
	@echo ""                                                >>$@
	@echo "1;"                                              >>$@

OpenAFS/Dirpath.sh: Makefile
	@echo "Creating OpenAFS/Dirpath.sh"
	@echo "# auto-generated by src/tests/Makefile"		  >$@
	@echo "# source or '.' in this file in shell"		   >>$@
	@echo "# DO NOT EDIT"							   >>$@
	@echo "  AFSCONFDIR=@afsconfdir@"         >>$@
	@echo "  VICEETCDIR=@viceetcdir@"         >>$@
	@echo "  AFSSRVBINDIR=@afssrvbindir@"       >>$@
	@echo "  AFSSRVSBINDIR=@afssrvsbindir@"      >>$@
	@echo "  AFSSRVLIBEXECDIR=@afssrvlibexecdir@"   >>$@
	@echo "  AFSDBDIR=@afsdbdir@"           >>$@
	@echo "  AFSLOGSDIR=@afslogsdir@"         >>$@
	@echo "  AFSLOCALDIR=@afslocaldir@"        >>$@
	@echo "  AFSBACKUPDIR=@afsbackupdir@"       >>$@
	@echo "  AFSBOSCONFIGDIR=@afsbosconfigdir@"    >>$@
	@echo "  OSTYPE=@MKAFS_OSTYPE@"       >>$@
	@if test "@afsconfdir@" = "/usr/afs/etc" ;  then \
		echo "# transarc paths" ;\
		echo "  CACHEDIR=/usr/vice/cache" ;\
		echo "  AFSDDIR=/usr/vice/etc" ;\
		echo "  INITDIR=/usr/vice/etc" ; \
		echo "  AFSKERNELDIR=/usr/vice/etc/modload" ;\
		echo "  AFSWSBINDIR=/usr/afsws/bin" ;\
	else \
		echo "# modern paths" ;\
	    echo "  CACHEDIR=@localstatedir@/openafs/cache" ;\
	    echo "  AFSDDIR=@afssrvsbindir@" ;\
	    echo "  INITDIR=@sysconfdir@"  ;\
	    echo "  AFSKERNELDIR=@afskerneldir@" ;\
	    echo "  AFSWSBINDIR=@afssrvbindir@" ;\
	fi >>$@
	@echo "export AFSCONFDIR VICEETCDIR AFSSRVBINDIR AFSSRVSBINDIR" >>$@
	@echo "export AFSSRVLIBEXECDIR AFSDBDIR AFSLOGSDIR AFSLOCALDIR" >>$@
	@echo "export AFSBACKUPDIR AFSBOSCONFIGDIR OSTYPE CACHEDIR AFSDDIR" >>$@
	@echo "export INITDIR AFSKERNELDIR AFSWSBINDIR"	>>$@

.PHONY:		all install clean realclean distclean mostlyclean install uninstall check
