# 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


LIBOBJS=cmd_errors.o cmd.o 
LIBPICOBJS=cmd_errors_pic.o cmd_pic.o
LIB64OBJS=cmd_errors64.o cmd64.o 

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

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

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

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

cmd.h: cmd_errors.et cmd.p.h
	$(RM) -f cmd.h cmd_errors.c
	${COMPILE_ET} -p ${srcdir} cmd_errors -h cmd

cmd_errors.c: cmd.h 

cmd_errors.o: cmd_errors.c

cmd.o: cmd.c cmd.h

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

cmd_errors_pic.o: cmd_errors.c
	$(SHD_CCRULE) cmd_errors.c

cmd_pic.o: cmd.c cmd.h
	$(SHD_CCRULE) ${srcdir}/cmd.c

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

libcmd.a: ${LIBOBJS} AFS_component_version_number.o
	-$(RM) -f $@
	$(AR) crv $@ ${LIBOBJS} AFS_component_version_number.o
	$(RANLIB) $@

libcmd_pic.a: ${LIBPICOBJS} AFS_component_version_number_pic.o
	-$(RM) -f $@
	$(AR) crv $@ ${LIBPICOBJS} AFS_component_version_number_pic.o
	$(RANLIB) $@

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

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

#
# Install targets
#
install: libcmd.a libcmd_pic.a cmd.h
	${INSTALL} -d ${DESTDIR}${libdir}/afs
	${INSTALL} -d ${DESTDIR}${includedir}/afs
	${INSTALL_DATA} libcmd.a ${DESTDIR}${libdir}/afs/libcmd.a
	${INSTALL_DATA} libcmd_pic.a ${DESTDIR}${libdir}/afs/libcmd_pic.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 libcmd_pic.a
	${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
	${INSTALL_DATA} libcmd_pic.a ${DEST}/lib/afs/libcmd_pic.a

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

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

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

include ../config/Makefile.version
