# 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
include @TOP_OBJDIR@/src/config/Makefile.lwptool

HELPER_SPLINT=@HELPER_SPLINT@

LT_rpc_objs     = base64.lo

LT_objs =$(LT_rpc_objs) \
	 ktime.lo volparse.lo hostparse.lo exec.lo \
	 hputil.lo kreltime.lo uuid.lo serverLog.lo \
	 dirpath.lo fileutil.lo flipbase64.lo fstab.lo \
	 afs_atomlist.lo afs_lhash.lo pthread_glock.lo tabular_output.lo \
	 ${REGEX_OBJ}

LT_deps = $(top_builddir)/src/opr/liboafs_opr.la
LT_libs = $(LIB_roken) $(MT_LIBS)

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/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/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 \
	liboafs_util.la \
	libafsrpc_util.la

util.a: $(LT_objs)
	$(LT_LDLIB_lwp) $(LT_objs)

libafsutil_pic.la: $(LT_objs)
	$(LT_LDLIB_pic) $(LT_objs)

liboafs_util.la: liboafs_util.la.sym $(LT_objs) $(LT_deps)
	$(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs)

libafsrpc_util.la: $(LT_rpc_objs)
	$(LT_LDLIB_pic) $(LT_rpc_objs)

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/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/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_LIBDIR}/util.a: util.a
	${INSTALL_DATA} $? $@

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

${TOP_LIBDIR}/libafsutil_pic.a: libafsutil_pic.la
	${INSTALL_DATA} .libs/libafsutil_pic.a $@

# 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


$(LT_objs): ${includes}

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

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

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

install: dirpath.h util.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}/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}/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_PROGRAM} sys ${DESTDIR}${bindir}/sys

dest: dirpath.h util.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}/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}/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_PROGRAM} sys ${DEST}/bin/sys

#
# Misc targets
#

clean:
	$(LT_CLEAN)
	$(RM) -f sys dirpath.h
	$(RM) -f util.a *.o core AFS_component_version_number.c

.PHONY: test
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 uuid.c serverLog.c \
	    dirpath.c fileutil.c flipbase64.c \
	    afs_atomlist.c afs_lhash.c fstab.c
