#############################################################################
#   $Source: /afs/cs/project/robocomp/Master/xavier/etc/Makefile.std,v $
# $Revision: 2.1 $
#     $Date: 1994/09/28 01:33:34 $
#   $Author: rich $
#    $State: Exp $
#   $Locker:  $
#
# PROJECT:	Lunar Rover Demonstration
#
# FILE:		Makefile.std
#		Based on Erebus prototypical Makefile
#		Modified for FRC as FRC pre-release version
#		Makefile.std.proto,v 1.10 1992/11/15 02:29:20 jwest Exp 
#
# DESCRIPTION:
#	This file should be included at the tail of the prototypical
#	Makefile.  It provides a set of "standard" and useful targets.
#
# EXPORTS:
#	The following targets are available:
#		all bins libs privs objs
#		clean install
#		lint depend
#		update add commit
#
# HISTORY:
#
# $Log: Makefile.std,v $
# Revision 2.1  1994/09/28 01:33:34  rich
# /afs/cs.cmu.edu -> /afs/cs.  Also forced calculation of STD_FILE in
# GNUmakefile.
#
# Revision 1.3  1994/09/23  18:04:51  rich
# Version 2.1 alpha.
#
# Revision 1.2  1994/09/22  17:01:55  rich
# Release of version 2.0 of Xavier software.
#
# Revision 1.1  1994/06/09  19:25:29  rich
# Added Makefile.std.  Still experimental.
# Improved fixlinks and makeLinks.
#
# Revision 1.4  1994/02/14  17:22:45  rich
# Use the lrdcvs script rather than direct cvs commands.
#
# Revision 1.3  1994/01/29  17:04:27  rich
# Added cvs commands: add, update, diff and commit to the standard makefile.
#
# Revision 1.2  1994/01/27  18:17:31  rich
# Modified Makefile.std to work on learning suns.
# lrdcvs now makes files in the release directory group writable.
#
# Revision 1.1.1.1  1994/01/11  20:37:11  rich
# Creating Archive.
#
# Revision 1.2  1993/08/31  23:12:34  pk16
# Updated Makefiles.
# Removed unused variable.
#
#############################################################################

# C++ support
.SUFFIXES: suffixes .cc .cxx

.cc:
	$(LINK.c) -o $@ $< $(LDLIBS)
.cc.o:
	$(COMPILE.c) -o $@ $<
.cxx:
	$(LINK.c) -o $@ $< $(LDLIBS)
.cxx.o:
	$(COMPILE.c) -o $@ $<

# Automatic defs to aid install target
INS_PUBLIC_BINS	= $(PUBLIC_BINS:%=$(PUBLIC_BIN_DIR)/%)
INS_PUBLIC_LIBS	= $(PUBLIC_LIBS:%=$(PUBLIC_LIB_DIR)/%)
INS_PUBLIC_LINTS= $(PUBLIC_LINTS:%=$(PUBLIC_LINT_DIR)/%)
INS_PUBLIC_INCS	= $(PUBLIC_INCS:%=$(PUBLIC_INC_DIR)/%)
INS_PUBLIC_MANS	= $(PUBLIC_MANS:%=$(PUBLIC_MAN_DIR)/%)
INS_PUBLIC_DOCS	= $(PUBLIC_DOCS:%=$(PUBLIC_DOC_DIR)/%)

INS_MODULE_LIBS	= $(MODULE_LIBS:%=$(MODULE_LIB_DIR)/%)
INS_MODULE_LINTS= $(MODULE_LINTS:%=$(MODULE_LINT_DIR)/%)
INS_MODULE_INCS	= $(MODULE_INCS:%=$(MODULE_INC_DIR)/%)

# Automatic defs to aid cvs commands
CVS_BIN = /usr/misc/.cvs/bin
CVS_COMMIT_LOG = $(CVSROOT)/CVSROOT/commitlog

##########
# Standard Targets
##########

srcs: $(SRCS_ALL)
bins: $(PUBLIC_BINS)
libs: $(PUBLIC_LIBS) $(MODULE_LIBS) $(PUBLIC_LINTS) $(MODULE_LINTS)
privs: $(PRIVS)
objs: $(OBJS)

clean: $(SUBDIRS)
	$(RM) $(DELETES)

depend:: $(SUBDIRS)

lint: $(SRCS) $(PUBLIC_INCS) $(MODULE_INCS) $(PRIVATE_INCS)
	$(LINT.c) $(SRCS)

install: install_incs install_libs $(SUBDIRS) install_bins install_mans \
	 install_docs
install_bins: $(INS_PUBLIC_BINS)
install_libs: $(SUBDIRS) $(INS_PUBLIC_LIBS) $(INS_PUBLIC_LINTS)\
	      $(INS_MODULE_LIBS) $(INS_MODULE_LINTS)
install_incs: $(SUBDIRS) $(INS_PUBLIC_INCS) $(INS_MODULE_INCS)
install_mans: $(INS_PUBLIC_MANS)
install_docs: $(INS_PUBLIC_DOCS)

##########
#install rules
##########

#ifdef $(INS_PUBLIC_BINS)
$(INS_PUBLIC_BINS): $$(@F)
	-mkdir -p $(PUBLIC_BIN_DIR)
	$(INSTALL) $(INS_BIN_FLAGS) $(@F) $(PUBLIC_BIN_DIR)
#endif

#ifdef $(INS_PUBLIC_LIBS)
$(INS_PUBLIC_LIBS): $$(@F)
	-mkdir -p $(PUBLIC_LIB_DIR)
	$(INSTALL) $(INS_LIB_FLAGS) $(@F) $(PUBLIC_LIB_DIR)
	ranlib -t $@
	chmod 444 $@
#endif

#ifdef $(INS_PUBLIC_LINTS)
$(INS_PUBLIC_LINTS): $$(@F)
	-mkdir -p $(PUBLIC_LINT_DIR)
	$(INSTALL) $(INS_LINT_FLAGS) $(@F) $(PUBLIC_LINT_DIR)

#endif

#ifdef $(INS_PUBLIC_INCS)
$(INS_PUBLIC_INCS): $$(@F)
	-mkdir -p $(PUBLIC_INC_DIR)
	$(INSTALL) $(INS_INC_FLAGS) $(@F) $(PUBLIC_INC_DIR)
#endif

#ifdef $(INS_PUBLIC_MANS)
$(INS_PUBLIC_MANS): $$(@F)
	-mkdir -p $(PUBLIC_MAN_DIR)
	$(INSTALL) $(INS_MAN_FLAGS) $(@F) $(PUBLIC_MAN_DIR)
#endif

#ifdef $(INS_PUBLIC_DOCS)
$(INS_PUBLIC_DOCS): $$(@F)
	-mkdir -p $(PUBLIC_DOC_DIR)
	$(INSTALL) $(INS_DOC_FLAGS) $(@F) $(PUBLIC_DOC_DIR)
#endif

#ifdef $(INS_MODULE_LIBS)
$(INS_MODULE_LIBS): $$(@F)
	-mkdir -p $(MODULE_LIB_DIR)
	$(INSTALL) $(INS_LIB_FLAGS) $(@F) $(MODULE_LIB_DIR)
	ranlib -t $@
	chmod 444 $@
#endif

#ifdef $(INS_MODULE_LINTS)
$(INS_MODULE_LINTS): $$(@F)
	-mkdir -p $(MODULE_LINT_DIR)
	$(INSTALL) $(INS_LINT_FLAGS) $(@F) $(MODULE_LINT_DIR)
#endif

#ifdef $(INS_MODULE_INCS)
$(INS_MODULE_INCS): $$(@F)
	-mkdir -p $(MODULE_INC_DIR)
	$(INSTALL) $(INS_INC_FLAGS) $(@F) $(MODULE_INC_DIR)
#endif

##########
# Source file dependencies
##########

depend:: $(SRCS) $(INCS) $(PRIVATE_INCS)
	makedepend -- $(CPPFLAGS) -- $(SRCS)

##########
# Tags files
##########

tags:: 
	etags */*.h */*/*.h */*.c */*.cpp */*/*.c */*/*.cpp ../Makefile Makefile */Makefile */*/Makefile

tags:: $(SUBDIRS)

##########
# CVS related stuff
##########

update: $(CVS_COMMIT_LOG)
	$(PROJECT_DIR)/etc/xcvs update

add:: 
	echo "Ignore warnings if there are no subdirectories."
	($(PROJECT_DIR)/etc/xcvs add $(SUBDIRS))

add:: $(SRCS_ALL)
	echo "Ignore warnings about files already present in the archive."
	$(PROJECT_DIR)/etc/xcvs add $(SRCS_ALL)

add:: $(SUBDIRS)

diff: $(SRCS) $(INCS) $(PRIVATE_INCS) $(CVS_COMMIT_LOG)
	$(PROJECT_DIR)/etc/xcvs diff

commit: $(SRCS) $(INCS) $(PRIVATE_INCS)
	$(PROJECT_DIR)/etc/xcvs commit

##########
# Recursion Rules
##########

all := RECURSE_CMD = \
	cd $@; \
	$(MAKE)

install := RECURSE_CMD = \
	cd $@; \
	$(MAKE) install

install_incs := RECURSE_CMD = \
	cd $@; \
	$(MAKE) install_incs

install_libs := RECURSE_CMD = \
	cd $@; \
	$(MAKE) install_libs

clean := RECURSE_CMD = \
	cd $@; \
	$(MAKE) clean

depend := RECURSE_CMD = \
	cd $@; \
	$(MAKE) depend

tags := RECURSE_CMD = \
	cd $@;\
	$(MAKE) tags

add := RECURSE_CMD = \
	cd $@; \
	$(MAKE) add
 
#ifdef $(SUBDIRS)
$(SUBDIRS):
	$(RECURSE_CMD)

#endif
