# Copyright 2000, International Business Machines Corporation and others.
# All Rights Reserved.
# 
# This software has been released under the terms of the IBM Public
# License.  For details, see the LICENSE file in the top-level source
# directory or online at http://www.openafs.org/dl/license10.html

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

HELPER_SPLINT=@HELPER_SPLINT@


objects =base64.o config_file.o ktime.o volparse.o \
	 hostparse.o exec.o \
	 hputil.o kreltime.o get_krbrlm.o uuid.o serverLog.o \
	 dirpath.o fileutil.o netutils.o flipbase64.o fstab.o \
	 afs_atomlist.o afs_lhash.o pthread_glock.o tabular_output.o \
	 pthread_threadname.o ${REGEX_OBJ}

objects_pic = \
	base64_pic.o \
	config_file_pic.o \
	ktime_pic.o \
	volparse_pic.o \
	hostparse_pic.o \
	exec_pic.o \
	hputil_pic.o \
	kreltime_pic.o \
	get_krbrlm_pic.o \
	uuid_pic.o \
	serverLog_pic.o \
	dirpath_pic.o \
	fileutil_pic.o \
	netutils_pic.o \
	flipbase64_pic.o \
	fstab_pic.o \
	afs_atomlist_pic.o \
	afs_lhash_pic.o \
	pthread_glock_pic.o \
	tabular_output_pic.o \
	pthread_threadname_pic.o \
	${REGEX_OBJ_PIC}

includes = \
	${TOP_INCDIR}/afs/dirpath.h \
	${TOP_INCDIR}/afs/pthread_nosigs.h \
	${TOP_INCDIR}/afs/errors.h \
	${TOP_INCDIR}/afs/vice.h \
	${TOP_INCDIR}/afs/ktime.h \
	${TOP_INCDIR}/afs/fileutil.h \
	${TOP_INCDIR}/afs/netutils.h \
	${TOP_INCDIR}/afs/afsutil.h \
	${TOP_INCDIR}/afs/afsutil_prototypes.h \
	${TOP_INCDIR}/afs/pthread_glock.h \
	${TOP_INCDIR}/afs/afs_atomlist.h \
	${TOP_INCDIR}/afs/afs_lhash.h \
	${TOP_INCDIR}/afs/softsig.h \
	${TOP_INCDIR}/afs/work_queue.h \
	${TOP_INCDIR}/afs/work_queue_types.h \
	${TOP_INCDIR}/afs/thread_pool.h \
	${TOP_INCDIR}/afs/thread_pool_types.h \
	${TOP_INCDIR}/afs/tabular_output.h

all: ${includes} \
	${TOP_LIBDIR}/util.a \
	${TOP_LIBDIR}/libafsutil.a \
	${TOP_LIBDIR}/libafsutil_pic.a \
	sys

buildtools: ${TOP_LIBDIR}/libafsutil.a ${TOP_INCDIR}/afs/afsutil.h
buildtools_clean: clean

depinstall: ${includes}

${TOP_INCDIR}/afs/dirpath.h: dirpath.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/pthread_nosigs.h: ${srcdir}/pthread_nosigs.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/errors.h: ${srcdir}/errors.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/vice.h: ${srcdir}/vice.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/ktime.h: ${srcdir}/ktime.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/fileutil.h: ${srcdir}/fileutil.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/netutils.h: ${srcdir}/netutils.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/afsutil.h: ${srcdir}/afsutil.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/afsutil_prototypes.h: ${srcdir}/afsutil_prototypes.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/pthread_glock.h: ${srcdir}/pthread_glock.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/afs_atomlist.h: ${srcdir}/afs_atomlist.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/afs_lhash.h: ${srcdir}/afs_lhash.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/softsig.h: ${srcdir}/softsig.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/work_queue.h: ${srcdir}/work_queue.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/work_queue_types.h: ${srcdir}/work_queue_types.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/thread_pool.h: ${srcdir}/thread_pool.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/thread_pool_types.h: ${srcdir}/thread_pool_types.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/afs/tabular_output.h: ${srcdir}/tabular_output.h
	${INSTALL_DATA} $? $@

${TOP_INCDIR}/potpourri.h: ${srcdir}/potpourri.h
	${INSTALL_DATA} $? $@

${TOP_LIBDIR}/util.a: util.a
	${INSTALL_DATA} $? $@

${TOP_LIBDIR}/libafsutil.a: util.a
	${INSTALL_DATA} $? $@

${TOP_LIBDIR}/libafsutil_pic.a: util_pic.a
	${INSTALL_DATA} $? $@

# Use " as the sed boundary character because we lose anyway if that occurs
# in path names.
dirpath.h: ${srcdir}/dirpath.hin Makefile
	sed \
		-e 's"@afsconfdir"${afsconfdir}"' \
		-e 's"@viceetcdir"${viceetcdir}"' \
		-e 's"@afssrvbindir"${afssrvbindir}"' \
		-e 's"@afssrvsbindir"${afssrvsbindir}"' \
		-e 's"@afssrvlibexecdir"${afssrvlibexecdir}"' \
		-e 's"@afsdbdir"${afsdbdir}"' \
		-e 's"@afslogsdir"${afslogsdir}"' \
		-e 's"@afslocaldir"${afslocaldir}"' \
		-e 's"@afsbackupdir"${afsbackupdir}"' \
		-e 's"@afsbosconfigdir"${afsbosconfigdir}"' \
		-e 's"@afsdatadir"${afsdatadir}"' \
		${srcdir}/dirpath.hin >dirpath.h

util.a: ${objects} AFS_component_version_number.o
	$(RM) -f util.a
	$(AR) crv util.a ${objects} AFS_component_version_number.o
	$(RANLIB) util.a

util_pic.a: ${objects_pic} AFS_component_version_number_pic.o
	$(RM) -f util_pic.a
	$(AR) crv util_pic.a ${objects_pic} AFS_component_version_number_pic.o
	$(RANLIB) util_pic.a

pthread_glock.o: ${srcdir}/pthread_glock.c ${includes}
	${MT_CC} $(COMMON_CFLAGS) ${MT_CFLAGS} -c ${srcdir}/pthread_glock.c

pthread_threadname.o: ${srcdir}/pthread_threadname.c ${includes}
	${MT_CC} $(COMMON_CFLAGS) ${MT_CFLAGS} -c ${srcdir}/pthread_threadname.c

${objects}: ${includes}

AFS_component_version_number_pic.o: AFS_component_version_number.c
	$(SHD_CCRULE) AFS_component_version_number.c

config_file.o: ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c krb5_locl.h
	$(AFS_CCRULE) -c ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c 

sys.o: sys.c AFS_component_version_number.c ${includes}

sys: sys.o 
	$(AFS_LDRULE) sys.o

# PIC objects build rules
base64_pic.o: ${srcdir}/base64.c ${includes}
	$(SHD_CCRULE) ${srcdir}/base64.c

config_file_pic.o: ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c krb5_locl.h
	$(SHD_CCRULE) ${TOP_SRCDIR}/external/heimdal/krb5/config_file.c

ktime_pic.o: ${srcdir}/ktime.c ${includes}
	$(SHD_CCRULE) ${srcdir}/ktime.c

volparse_pic.o: ${srcdir}/volparse.c ${includes}
	$(SHD_CCRULE) ${srcdir}/volparse.c

hostparse_pic.o: ${srcdir}/hostparse.c ${includes}
	$(SHD_CCRULE) ${srcdir}/hostparse.c

exec_pic.o: ${srcdir}/exec.c ${includes}
	$(SHD_CCRULE) ${srcdir}/exec.c

hputil_pic.o: ${srcdir}/hputil.c ${includes}
	$(SHD_CCRULE) ${srcdir}/hputil.c

kreltime_pic.o: ${srcdir}/kreltime.c ${includes}
	$(SHD_CCRULE) ${srcdir}/kreltime.c

get_krbrlm_pic.o: ${srcdir}/get_krbrlm.c ${includes}
	$(SHD_CCRULE) ${srcdir}/get_krbrlm.c

uuid_pic.o: ${srcdir}/uuid.c ${includes}
	$(SHD_CCRULE) ${srcdir}/uuid.c

serverLog_pic.o: ${srcdir}/serverLog.c ${includes}
	$(SHD_CCRULE) ${srcdir}/serverLog.c

dirpath_pic.o: ${srcdir}/dirpath.c ${includes}
	$(SHD_CCRULE) ${srcdir}/dirpath.c

fileutil_pic.o: ${srcdir}/fileutil.c ${includes}
	$(SHD_CCRULE) ${srcdir}/fileutil.c

netutils_pic.o: ${srcdir}/netutils.c ${includes}
	$(SHD_CCRULE) ${srcdir}/netutils.c

flipbase64_pic.o: ${srcdir}/flipbase64.c ${includes}
	$(SHD_CCRULE) ${srcdir}/flipbase64.c

fstab_pic.o: ${srcdir}/fstab.c ${includes}
	$(SHD_CCRULE) ${srcdir}/fstab.c

afs_atomlist_pic.o: ${srcdir}/afs_atomlist.c ${includes}
	$(SHD_CCRULE) ${srcdir}/afs_atomlist.c

afs_lhash_pic.o: ${srcdir}/afs_lhash.c ${includes}
	$(SHD_CCRULE) ${srcdir}/afs_lhash.c

pthread_glock_pic.o: ${srcdir}/pthread_glock.c ${includes}
	$(SHD_CCRULE) ${srcdir}/pthread_glock.c

pthread_threadname_pic.o: ${srcdir}/pthread_threadname.c ${includes}
	$(SHD_CCRULE) ${srcdir}/pthread_threadname.c

tabular_output_pic.o: ${srcdir}/tabular_output.c ${includes}
	$(SHD_CCRULE) ${srcdir}/tabular_output.c

regex_pic.o: ${srcdir}/regex.c ${includes}
	$(SHD_CCRULE) ${srcdir}/regex.c

#
# Install targets
#
KDIR=../libafs/afs
UKDIR=../libuafs/afs

install: dirpath.h util.a util_pic.a sys
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${bindir}
	${INSTALL_DATA} dirpath.h ${DESTDIR}${includedir}/afs/dirpath.h
	${INSTALL_DATA} ${srcdir}/pthread_nosigs.h ${DESTDIR}${includedir}/afs/pthread_nosigs.h
	${INSTALL_DATA} ${srcdir}/errors.h ${DESTDIR}${includedir}/afs/errors.h
	${INSTALL_DATA} ${srcdir}/vice.h ${DESTDIR}${includedir}/afs/vice.h
	${INSTALL_DATA} ${srcdir}/ktime.h ${DESTDIR}${includedir}/afs/ktime.h
	${INSTALL_DATA} ${srcdir}/fileutil.h ${DESTDIR}${includedir}/afs/fileutil.h
	${INSTALL_DATA} ${srcdir}/netutils.h ${DESTDIR}${includedir}/afs/netutils.h
	${INSTALL_DATA} ${srcdir}/afsutil.h ${DESTDIR}${includedir}/afs/afsutil.h
	${INSTALL_DATA} ${srcdir}/afsutil_prototypes.h ${DESTDIR}${includedir}/afs/afsutil_prototypes.h
	${INSTALL_DATA} ${srcdir}/pthread_glock.h ${DESTDIR}${includedir}/afs/pthread_glock.h
	${INSTALL_DATA} ${srcdir}/afs_atomlist.h ${DESTDIR}${includedir}/afs/afs_atomlist.h
	${INSTALL_DATA} ${srcdir}/afs_lhash.h ${DESTDIR}${includedir}/afs/afs_lhash.h
	${INSTALL_DATA} ${srcdir}/softsig.h ${DESTDIR}${includedir}/afs/softsig.h
	${INSTALL_DATA} ${srcdir}/work_queue.h ${DESTDIR}${includedir}/afs/work_queue.h
	${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DESTDIR}${includedir}/afs/work_queue_types.h
	${INSTALL_DATA} ${srcdir}/thread_pool.h ${DESTDIR}${includedir}/afs/thread_pool.h
	${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DESTDIR}${includedir}/afs/thread_pool_types.h
	${INSTALL_DATA} ${srcdir}/tabular_output.h ${DESTDIR}${includedir}/afs/tabular_output.h
	${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/util.a
	${INSTALL_DATA} util.a ${DESTDIR}${libdir}/afs/libafsutil.a
	${INSTALL_DATA} util_pic.a ${DESTDIR}${libdir}/afs/libafsutil_pic.a
	${INSTALL_PROGRAM} sys ${DESTDIR}${bindir}/sys

dest: dirpath.h util.a util_pic.a sys
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/bin
	${INSTALL_DATA} dirpath.h ${DEST}/include/afs/dirpath.h
	${INSTALL_DATA} ${srcdir}/pthread_nosigs.h ${DEST}/include/afs/pthread_nosigs.h
	${INSTALL_DATA} ${srcdir}/errors.h ${DEST}/include/afs/errors.h
	${INSTALL_DATA} ${srcdir}/vice.h ${DEST}/include/afs/vice.h
	${INSTALL_DATA} ${srcdir}/ktime.h ${DEST}/include/afs/ktime.h
	${INSTALL_DATA} ${srcdir}/fileutil.h ${DEST}/include/afs/fileutil.h
	${INSTALL_DATA} ${srcdir}/netutils.h ${DEST}/include/afs/netutils.h
	${INSTALL_DATA} ${srcdir}/afsutil.h ${DEST}/include/afs/afsutil.h
	${INSTALL_DATA} ${srcdir}/afsutil_prototypes.h ${DEST}/include/afs/afsutil_prototypes.h
	${INSTALL_DATA} ${srcdir}/pthread_glock.h ${DEST}/include/afs/pthread_glock.h
	${INSTALL_DATA} ${srcdir}/afs_atomlist.h ${DEST}/include/afs/afs_atomlist.h
	${INSTALL_DATA} ${srcdir}/afs_lhash.h ${DEST}/include/afs/afs_lhash.h
	${INSTALL_DATA} ${srcdir}/softsig.h ${DEST}/include/afs/softsig.h
	${INSTALL_DATA} ${srcdir}/work_queue.h ${DEST}/include/afs/work_queue.h
	${INSTALL_DATA} ${srcdir}/work_queue_types.h ${DEST}/include/afs/work_queue_types.h
	${INSTALL_DATA} ${srcdir}/thread_pool.h ${DEST}/include/afs/thread_pool.h
	${INSTALL_DATA} ${srcdir}/thread_pool_types.h ${DEST}/include/afs/thread_pool_types.h
	${INSTALL_DATA} ${srcdir}/tabular_output.h ${DEST}/include/afs/tabular_output.h
	${INSTALL_DATA} util.a ${DEST}/lib/afs/util.a
	${INSTALL_DATA} util.a ${DEST}/lib/afs/libafsutil.a
	${INSTALL_DATA} util_pic.a ${DEST}/lib/afs/libafsutil_pic.a
	${INSTALL_PROGRAM} sys ${DEST}/bin/sys

#
# Misc targets
#

clean:
	$(RM) -f ${objects} sys dirpath.h
	$(RM) -f util.a util_pic.a *.o core AFS_component_version_number.c

test:
	cd test; $(MAKE)

include ../config/Makefile.version

check-splint:
	sh $(HELPER_SPLINT) $(CFLAGS) \
	    base64.c ktime.c volparse.c hostparse.c \
	    hputil.c kreltime.c get_krbrlm.c uuid.c serverLog.c \
	    dirpath.c fileutil.c netutils.c flipbase64.c \
	    afs_atomlist.c afs_lhash.c fstab.c
