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

LT_objs=cmd_errors.lo cmd.lo config_file.lo AFS_component_version_number.lo
LT_deps=$(top_builddir)/src/comerr/liboafs_comerr.la
LT_libs=

LIB64OBJS=cmd_errors64.o cmd64.o

all: ${TOP_LIBDIR}/libcmd.a ${TOP_LIBDIR}/libcmd_pic.a \
     ${TOP_INCDIR}/afs/cmd.h liboafs_cmd.la

all64: all ${TOP_LIBDIR}/libcmd64.a

generated: cmd.h cmd_errors.c

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

${TOP_LIBDIR}/libcmd_pic.a: libcmd_pic.la
	$(INSTALL_DATA) .libs/libcmd_pic.a $@

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

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

cmd_errors.c: cmd_errors.et
	${COMPILE_ET_C} -p ${srcdir} cmd_errors

cmd.h: cmd_errors.et cmd.p.h
	${COMPILE_ET_H} -p ${srcdir} cmd_errors -h cmd

cmd.lo: cmd.h
config_file.lo: cmd.h

config_file.lo: $(TOP_SRCDIR)/external/heimdal/krb5/config_file.c krb5_locl.h
	$(LT_CCRULE) $(TOP_SRCDIR)/external/heimdal/krb5/config_file.c

cmd_errors64.o: cmd_errors.c
	${CC} $(COMMON_CFLAGS) $(CPPFLAGS) ${XCFLAGS64} \
		-c -o cmd_errors64.o cmd_errors.c

cmd64.o: cmd.c cmd.h
	${CC} $(COMMON_CFLAGS) $(CPPFLAGS) ${XCFLAGS64} \
		-c -o cmd64.o ${srcdir}/cmd.c

libcmd64.a: ${LIB64OBJS} AFS_component_version_number64.o
	-$(RM) -f $@
	$(AR) crv $@ ${LIB64OBJS} AFS_component_version_number64.o
	$(RANLIB) $@

libcmd.a: $(LT_objs)
	$(LT_LDLIB_static) $(LT_objs)

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

liboafs_cmd.la: $(LT_objs) $(LT_deps)
	$(LT_LDLIB_shlib) $(LT_objs) $(LT_deps) $(LT_libs)

AFS_component_version_number64.o: AFS_component_version_number.c
	${CC} $(COMMON_CFLAGS) $(CPPFLAGS) ${XCFLAGS64} \
		-c -o AFS_component_version_number64.o \
		AFS_component_version_number.c

#
# Install targets
#
install: libcmd.a cmd.h
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} libcmd.a ${DESTDIR}$(libdir)/afs/libcmd.a
	${INSTALL_DATA} cmd.h ${DESTDIR}${includedir}/afs/cmd.h

install64: install libcmd64.a
	${INSTALL_DATA} libcmd64.a ${DESTDIR}${libdir}/afs/libcmd64.a

dest: libcmd.a cmd.h
	${INSTALL} -d ${DEST}/lib/afs
	${INSTALL} -d ${DEST}/include/afs
	${INSTALL_DATA} libcmd.a ${DEST}/lib/afs/libcmd.a
	${INSTALL_DATA} cmd.h ${DEST}/include/afs/cmd.h

dest64: dest libcmd64.a
	${INSTALL_DATA} libcmd64.a ${DEST}/lib/afs/libcmd64.a

#
# Misc targets
#
test tests:
	(cd test; $(MAKE) )

clean:
	$(LT_CLEAN)
	$(RM) -f  *.a *.o ctest dtest cmd.h cmd_errors.c core \
		  AFS_component_version_number.c

include ../config/Makefile.version
