#############################################################################
#       $Id: GNUmakefile.std,v 2.30 1997/03/02 07:16:32 josullvn Exp $
#   $Source: /afs/cs/project/robocomp/Master/xavier/etc/GNUmakefile.std,v $
# $Revision: 2.30 $
#     $Date: 1997/03/02 07:16:32 $
#   $Author: josullvn $
#    $State: Exp $
#   $Locker:  $
#
# PROJECT:	Task Control Architecture.
#
# FILE:		GNUmakefile.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
#		depend
#		update add commit
#
# HISTORY:
#
# $Log: GNUmakefile.std,v $
# Revision 2.30  1997/03/02 07:16:32  josullvn
# Split PROJECT_DIR into PROJECT_DIR and RELEASE_DIR, so that the afs
# capable linux machines aren't confused.
#
# Revision 2.29  1996/02/14  02:44:02  rich
# "privs" require .force files as well.
#
# Revision 2.28  1996/02/14  00:58:03  rich
# Changes for old version of gmake on pmax.
#
# Revision 2.27  1996/02/12  23:34:41  rich
# Changed GNUmakefile for faster compiles.
#
# Revision 2.26  1996/01/29  19:36:20  rich
# Saving changes for FAST_COMPILE.
#
# Revision 2.25  1995/10/25  19:51:52  rich
# Fixed problem when using a non-afs directory on a machine with afs.
# This problem was due to a new afs release, I believe.
#
# Revision 2.24  1995/10/07  19:32:50  rich
# Use umask 002.
#
# Revision 2.23  1995/09/29  04:43:31  rich
# Can now sync with wolverine or noonan.  Clock skew accounted for.
# Fixed problem with compiling bins.
#
# Revision 2.22  1995/09/20  19:06:29  rich
# Added recursive target for install_bins.
#
# Revision 2.21  1995/07/30  01:52:20  rich
# Moved common defines to etc/GNUmakefile.defs.
#
# Revision 2.20  1995/07/19  17:53:10  rich
# Export fix for old gmake on gs8.
#
# Revision 2.19  1995/07/19  01:59:01  rich
# Changes for sync target.
#
# Revision 2.18  1995/05/20  19:27:10  rich
# Moved the clean_depends into the veryclean target.
# Added support for C++ and man files.
#
# Revision 2.17  1995/05/08  21:59:14  rich
# Fixed problem with export of shell variables.
#
# Revision 2.16  1995/01/12  03:44:01  rich
# Change path to cs so it works with new release in /usr/local/bin/cvs.
#
# Revision 2.15  1994/11/02  23:33:49  rich
# Changes for linux on an i486 and OSF1 on an alpha.
#
# Revision 2.14  1994/10/11  02:16:57  rich
# When commiting, only checkout the changed directory in the release directory.
#
# Revision 2.13  1994/10/04  23:38:50  rich
# Putting $(LIBDEP) in the dependencies now works for linked files.
#
# Revision 2.12  1994/10/04  18:14:32  rich
# Changed For -> for.  Now prints comments as it goes through the sub
# directories.
#
# Revision 2.11  1994/10/04  17:45:42  rich
# Fixed mistake in release target.
#
# Revision 2.10  1994/10/04  17:04:51  rich
# Fixed bug in BASE_DIR and added some support for linux.
# Have gmake release do a checkout rather than an update, so it gets new
# modules.
# Fix makeTAGS so it does not include bin/params/GNUmakefile, which is the
# same as params/GNUmakefile.
#
# Revision 2.9  1994/10/03  21:15:52  rich
# Fixed a problem where setupXavier would ignore the user input.
# Change the GNUmakefile.std to check if directories exist before doing a cd.
#
# Revision 2.8  1994/10/03  04:16:32  rich
# Added a new target: ftp, to create a tar file.
#
# Revision 2.7  1994/09/30  04:58:22  rich
# Give full path to cvs.
#
# Revision 2.6  1994/09/30  04:40:42  rich
# Made all = install.  Added an everything target.
# Added defines for customizing CFLAGS.
#
# Revision 2.5  1994/09/28  20:14:27  rich
# Have to run from the shell to do a commit.
#
# Revision 2.4  1994/09/28  19:15:37  rich
# Removed dependency files from the archive.
#
# Revision 2.3  1994/09/28  04:42:32  rich
# Don't have to clean/remake dependencies on a commit.
#
# Revision 2.2  1994/09/28  03:45:14  rich
# ls on mach machines does not direct errors to stderr.
#
# Revision 2.1  1994/09/28  03:16:47  rich
# Force revision number to be 2.1
#
# Revision 1.1  1994/09/28  01:33:32  rich
# /afs/cs.cmu.edu -> /afs/cs.  Also forced calculation of STD_FILE in
# GNUmakefile.
#
#
#############################################################################

# All source files
SRCS_ALL	:= $(INCS) $(PRIVATE_INCS) $(SRCS) $(MANS) $(DOCS) $(MISC)

# Files never to be removed, even if Make encounters an error
.PRECIOUS: $(SRCS_ALL) $(SUBDIRS)

# make sure everyone is using the same default paths.
LPATH=:/usr/cs/lib:/usr/lib:/usr/misc/lib
CPATH=:/usr/misc/include

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

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

# Automatic defs to aid install target
INS_PUBLIC_BINS	:= $(patsubst %,$(PUBLIC_BIN_DIR)/%,$(PUBLIC_BINS))
INS_PUBLIC_LIBS	:= $(patsubst %,$(PUBLIC_LIB_DIR)/%,$(PUBLIC_LIBS))
INS_PUBLIC_LINTS:= $(patsubst %,$(PUBLIC_LINT_DIR)/%,$(PUBLIC_LINTS))
INS_PUBLIC_INCS	:= $(patsubst %,$(PUBLIC_INC_DIR)/%,$(PUBLIC_INCS))
INS_PUBLIC_MANS1:= $(patsubst %.1,$(PUBLIC_MAN_DIR)1/%.1,$(filter %.1,$(PUBLIC_MANS)))
INS_PUBLIC_MANS3:= $(patsubst %.3,$(PUBLIC_MAN_DIR)3/%.3,$(filter %.3,$(PUBLIC_MANS)))
INS_PUBLIC_DOCS	:= $(patsubst %,$(PUBLIC_DOC_DIR)/%,$(PUBLIC_DOCS))

INS_MODULE_LIBS	:= $(patsubst %,$(MODULE_LIB_DIR)/%,$(MODULE_LIBS))
INS_MODULE_LINTS:= $(patsubst %,$(MODULE_LINT_DIR)/%,$(MODULE_LINTS))
INS_MODULE_DOCS:= $(patsubst %,$(MODULE_DOC_DIR)/%,$(MODULE_DOCS))
INS_MODULE_INCS	:= $(patsubst %,$(MODULE_INC_DIR)/%,$(MODULE_INCS))

# Automatic defs to aid local target
PRIV_BINS 	:= $(patsubst %,$(BDIR)/%,$(PRIVS))

# Automatic defs to aid cvs commands
CVS_COMMIT_LOG := $(CVSROOT)/CVSROOT/commitlog
CVSROOT := $(dir $(RELEASE_DIR))/Master
RCSBIN := $(CVS_BIN)

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

srcs: $(SRCS_ALL)

bins: $(INS_PUBLIC_BINS)
ifdef INS_PUBLIC_BINS
$(INS_PUBLIC_BINS): $(INS_PUBLIC_LIBS)
endif

ifdef PRIV_BINS
privs:: $(INSTALL_DIR)/$(BDIR)/.force $(INSTALL_DIR)/$(LDIR)/.force
privs:: $(BDIR)/.force $(ODIR)/.force\
	$(BDIR)/params/.force $(BDIR)/params/param.std
endif
privs:: $(PRIV_BINS)
ifdef PRIV_BINS
$(PRIV_BINS): $(INS_PUBLIC_LIBS)
endif

libs: $(patsubst %,$(PUBLIC_LIB_DIR)/%,$(PUBLIC_LIBS)) \
	$(patsubst %,$(MODULE_LIB_DIR)/%,$(MODULE_LIBS))\
	$(PUBLIC_LINTS) $(MODULE_LINTS)
objs: $(OBJS)

clean::
	$(RM) $(DELETES);
	$(RM) $(wildcard .nse_dep*)
	$(RM) $(wildcard *.CKP)
	$(RM) $(wildcard \#*\#)
	$(RM) $(wildcard *~)
	$(RM) $(wildcard .*~)
	$(RM) $(wildcard *.CKP)
	$(RM) $(wildcard *.BAK)
	$(RM) $(wildcard .*.BAK)
	$(RM) $(wildcard .\#*)

sync::
	$(SYNC_FILE)

ifdef SUBDIRS
clean:: 
	for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	   echo "Cleaning $$sub";\
	   cd $$sub; $(MAKE) clean; fi;) \
	done;

veryclean::
	for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	   echo "Cleaning $$sub";\
	   cd $$sub; $(MAKE) clean; fi;) \
	done;

sync:: 
	for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	   echo "Syncing $$sub";\
	   cd $$sub; $(MAKE) sync; fi;) \
	done;
endif

veryclean:: clean clean_depend

veryclean::
	$(RM) $(INS_PUBLIC_BINS);
	$(RM) $(INS_PUBLIC_LIBS);
	$(RM) $(INS_PUBLIC_LINTS);
	$(RM) $(INS_PUBLIC_INCS);
	$(RM) $(INS_PUBLIC_MANS1);
	$(RM) $(INS_PUBLIC_MANS3);
	$(RM) $(INS_PUBLIC_DOCS);
	$(RM) $(INS_MODULE_LIBS);
	$(RM) $(INS_MODULE_LINTS);
	$(RM) $(INS_MODULE_DOCS);
	$(RM) $(INS_MODULE_INCS);

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

MAKEDEPEND = makedepend

MDFLAGS = $(CPPFLAGS) $(DEPEND_FLAGS)

ifdef DEPEND_FILE
  ifdef DEPEND_PREFIX
# Should really be 
# $(DEPEND_FILE): $(SRCS) $(INCS) $(PRIVATE_INCS)
# But that causes the depend file to be rebuilt every time.
depend:: 
	-$(RM) $(DEPEND_FILE)
	echo "# DO NOT DELETE THIS LINE -- make depend depends on it." > $(DEPEND_FILE)
	-for pre in $(DEPEND_PREFIX); do \
	  $(MAKEDEPEND) -p$$pre -f$(DEPEND_FILE) -- $(MDFLAGS) -- $(SRCS); \
	done;
  else
depend::
	-$(RM) $(DEPEND_FILE)
	echo "# DO NOT DELETE THIS LINE -- make depend depends on it." > $(DEPEND_FILE)
	-$(MAKEDEPEND) -f$(DEPEND_FILE) -- $(MDFLAGS) -- $(SRCS)
  endif
endif

ifdef SUBDIRS
depend:: 
	-(for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	    echo "Making depend for: $$sub";\
	    cd $$sub; $(MAKE) depend; fi;) \
	done;)
endif

# Method of removing dependancies that vary from machine to machine.

ifdef SUBDIRS
clean_depend:: 
	for sub in $(SUBDIRS); do \
	( if [ -d $$sub ]; then \
	  echo "Cleaning depend for: $$sub";\
	  cd $$sub; $(MAKE) clean_depend; fi;) \
	done;
endif

ifdef DEPEND_FILE
clean_depend:: 
	-$(RM) $(DEPEND_FILE)
endif

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

everything:: install srcs libs bins privs

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

install:: $(INSTALL_DIR)/$(BDIR)/.force $(INSTALL_DIR)/$(LDIR)/.force

install:: $(INSTALL_DIR)/$(BDIR)/params/.force\
	  $(INSTALL_DIR)/$(BDIR)/params/param.std

install:: install_incs install_libs install_bins install_mans install_docs

install:: srcs

install_incs:: $(INS_PUBLIC_INCS) $(INS_MODULE_INCS)
ifdef SUBDIRS
install_incs:: 
	for sub in $(SUBDIRS); do \
	(if [ -d $$sub ]; then \
	    echo "Making install_incs for: $$sub";\
	    cd $$sub; $(MAKE) install_incs; fi;) \
	done;
endif

ifdef INS_PUBLIC_LIBS
install_libs:: $(LDIR)/.force $(ODIR)/.force
endif
install_libs:: $(INSTALL_DIR)/$(LDIR)/.force
install_libs:: $(INS_PUBLIC_LIBS) $(INS_PUBLIC_LINTS)\
	      $(INS_MODULE_LIBS) $(INS_MODULE_LINTS)
ifdef SUBDIRS
install_libs:: 
	for sub in $(SUBDIRS); do \
	(if [ -d $$sub ]; then \
	    echo "Making install_libs for: $$sub";\
	    cd $$sub; $(MAKE) install_libs; fi;) \
	done;
endif

ifdef INS_PUBLIC_BINS
install_bins:: $(BDIR)/.force $(ODIR)/.force\
	$(BDIR)/params/.force $(BDIR)/params/param.std
endif
install_bins:: $(INSTALL_DIR)/$(BDIR)/.force\
	  $(INSTALL_DIR)/$(BDIR)/params/.force\
	  $(INSTALL_DIR)/$(BDIR)/params/param.std
install_bins:: $(INS_PUBLIC_BINS) install_mans install_docs
ifdef SUBDIRS
install_bins:: 
	for sub in $(SUBDIRS); do \
	(if [ -d $$sub ]; then \
	    echo "Making install_bins for: $$sub";\
	    cd $$sub; $(MAKE) install_bins; fi;) \
	done;
endif

install_mans: $(INS_PUBLIC_MANS1) $(INS_PUBLIC_MANS3)

install_docs: $(INS_PUBLIC_DOCS) $(INS_MODULE_DOCS)

.PHONY: srcs bins libs privs objs clean depend clean_depend lint tags \
	install install_bins install_libs install_incs install_mans \
	install_docs msg link_tar ftp tar lib_dep_force

#install rules for public and module files.

ifdef INS_PUBLIC_LINTS
$(INS_PUBLIC_LINTS): $(PUBLIC_LINT_DIR)/%: %
	-mkdir $(PUBLIC_LINT_DIR)
	$(INSTALL) $(INS_LINT_FLAGS) $(@F) $(PUBLIC_LINT_DIR)
endif

ifdef INS_PUBLIC_INCS
$(INS_PUBLIC_INCS): $(PUBLIC_INC_DIR)/%: %
	-mkdir $(PUBLIC_INC_DIR)
	$(INSTALL) $(INS_INC_FLAGS) $(@F) $(PUBLIC_INC_DIR)
endif

ifdef INS_PUBLIC_MANS1
$(INS_PUBLIC_MANS1): $(PUBLIC_MAN_DIR)1/%: %
	-mkdir -p $(PUBLIC_MAN_DIR)1
	$(INSTALL) $(INS_MAN_FLAGS) $(@F) $(PUBLIC_MAN_DIR)1
endif

ifdef INS_PUBLIC_MANS3
$(INS_PUBLIC_MANS3): $(PUBLIC_MAN_DIR)3/%: %
	-mkdir -p $(PUBLIC_MAN_DIR)3
	$(INSTALL) $(INS_MAN_FLAGS) $(@F) $(PUBLIC_MAN_DIR)3
endif

ifdef INS_PUBLIC_DOCS
$(INS_PUBLIC_DOCS): $(PUBLIC_DOC_DIR)/%: %
	-mkdir $(PUBLIC_DOC_DIR)
	$(INSTALL) $(INS_DOC_FLAGS) $(@F) $(PUBLIC_DOC_DIR)
endif

ifdef INS_MODULE_DOCS
$(INS_MODULE_DOCS): $(MODULE_DOC_DIR)/%: %
	-mkdir -p $(MODULE_DOC_DIR)
	$(INSTALL) $(INS_DOC_FLAGS) $(@F) $(MODULE_DOC_DIR)
endif

ifdef INS_MODULE_LIBS
$(INS_MODULE_LIBS): $(MODULE_LIB_DIR)/%: $(LDIR)/%
	-mkdir $(MODULE_LIB_DIR)
	$(INSTALL) $(INS_LIB_FLAGS)  $(LDIR)/$(@F) $(MODULE_LIB_DIR)
	$(RM) $(LDIR)/$(@F)
	$(RANLIB) -t $@
	chmod 444 $@
endif

ifdef INS_MODULE_LINTS
$(INS_MODULE_LINTS): $(MODULE_LINT_DIR)/%: %
	-mkdir $(MODULE_LINT_DIR)
	$(INSTALL) $(INS_LINT_FLAGS) $(@F) $(MODULE_LINT_DIR)
endif

ifdef INS_MODULE_INCS
$(INS_MODULE_INCS): $(MODULE_INC_DIR)/%: %
	-mkdir $(MODULE_INC_DIR)
	$(INSTALL) $(INS_INC_FLAGS) $(@F) $(MODULE_INC_DIR)
endif

##########
# Simple Recursion
##########

ifdef SUBDIRS
everything:: 
	for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	    echo "Making everything for: $$sub";\
	    cd $$sub; $(MAKE) everything; fi;) \
	done;
endif

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

tags::
	-etags $(SRCS_ALL) $(wildcard */*.[hc]) $(wildcard */*/*.[hc]) $(wildcard */GNUmakefile) $(wildcard */*/GNUmakefile)
	-etags -a $(wildcard *akefile) $(wildcard */GNUmakefile) $(wildcard */*/GNUmakefile)

ifdef SUBDIRS
tags::
	for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	    echo "Making tags for: $$sub";\
	    cd $$sub; $(MAKE) tags; fi;) \
	done;
endif

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

update: $(CVS_COMMIT_LOG)
	-$(CVS_BIN)/cvs update

ifdef SUBDIRS
add:: 
	echo "Ignore warnings if there are no subdirectories."
	-(for sub in $(SUBDIRS); do \
		if [ -d $$sub/CVS ] ; then echo $$sys already added; \
		else (echo "y" | $(CVS_BIN)/cvs add $$sub); fi;\
	done;)
	-(for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	    echo "Making add for: $$sub";\
	    cd $$sub; $(MAKE) add; fi;) \
	done;)
endif

add:: $(SRCS_ALL)
	echo "Ignore warnings about files already present in the archive."
	-($(CVS_BIN)/cvs add $(SRCS_ALL))

diff: $(SRCS) $(INCS) $(PRIVATE_INCS) $(CVS_COMMIT_LOG)
	echo "*********************" > /dev/null
	echo "Changes you have made" > /dev/null
	echo "*********************" > /dev/null
	-$(CVS_BIN)/cvs diff
	echo "********************************" > /dev/null
	echo "Changes you and others have made" > /dev/null
	echo "********************************" > /dev/null
	-$(CVS_BIN)/cvs diff -D now

status: $(SRCS) $(INCS) $(PRIVATE_INCS) $(CVS_COMMIT_LOG)
	echo "*********************" > /dev/null
	echo "Status of your files." > /dev/null
	echo "*********************" > /dev/null
	-$(CVS_BIN)/cvs status

do_commit: $(SRCS) $(INCS) $(PRIVATE_INCS)
	-$(CVS_BIN)/cvs commit

commit: do_commit release depend

##########
# Release
##########

update_release:
	cd $(PROJECT_DIR);\
	cd ..; umask 002; $(CVS_BIN)/cvs checkout $(PROJECT)/$(MODULE_DIR)

depend_release:
	cd $(PROJECT_DIR)/$(MODULE_DIR); $(MAKE) depend;

release: update_release depend_release
	cd $(PROJECT_DIR)/$(MODULE_DIR); $(MAKE) install;

##############
# Create the obj, bin and lib and code directories.
##############

$(ODIR)/.force $(LDIR)/.force $(BDIR)/.force:
	-(if $(IS_AFS); then \
	  (sys=$(AFS_TYPE);\
	  if (cd .$(patsubst %/.force,%,$@).$$sys); then echo .$(patsubst %/.force,%,$@).$$sys exists;\
	   else mkdir .$(patsubst %/.force,%,$@).$$sys;\
	   fi;\
	  if (cd $(patsubst %/.force,%,$@)); then echo $(patsubst %/.force,%,$@) already linked;\
	   else echo making link; ln -s .$(patsubst %/.force,%,$@).@sys $(patsubst %/.force,%,$@); \
	  fi;)\
	else \
		mkdir $(patsubst %/.force,%,$@); fi)
	echo `date` > $@

$(BDIR)/params/.force:
	if ( cd $(INSTALL_DIR)/params); then \
	  (echo "Using local params file"; \
	  ln -s ../$(INSTALL_DIR)/params $(BDIR)/params;)\
	else \
	  (echo "Using release params file"; \
	  ln -s $(PROJECT_DIR)/params $(BDIR)/params;)\
	fi;
	- echo `date` > $(INSTALL_DIR)/$(BDIR)/params/.force

ifeq ($(findstring earhart,$host),)
$(BDIR)/params/param.std:
	  -(cd $(BDIR)/params; \
	   echo "Using Xavier param file";\
            ln -s param.xavier param.std;)
else
$(BDIR)/params/param.std:
	  -(cd $(BDIR)/params; \
	   echo "Using Amelia param file";\
            ln -s param.amelia param.std;)
endif

ifneq ($(INSTALL_DIR),.)
$(INSTALL_DIR)/$(ODIR)/.force:
	-if $(IS_AFS); then \
	 (sys=$(AFS_TYPE);\
	  cd $(INSTALL_DIR);\
	  if (cd .$(ODIR).$$sys); then echo .$(ODIR).$$sys exists;\
	   else mkdir .$(ODIR).$$sys;\
	   fi;\
	  if (cd $(ODIR)); then echo $(ODIR) already linked;\
	   else echo making link; ln -s .$(ODIR).@sys $(ODIR); \
	   fi;)\
	else \
		mkdir $(INSTALL_DIR)/$(ODIR); fi;\
	echo `date` > $(INSTALL_DIR)/$(ODIR)/.force
endif

ifneq ($(INSTALL_DIR),.)
$(INSTALL_DIR)/$(BDIR)/.force:
	-if $(IS_AFS); then \
	 (sys=$(AFS_TYPE);\
	  cd $(INSTALL_DIR);\
	  if (cd .$(BDIR).$$sys); then echo .$(BDIR).$$sys exists;\
	   else mkdir .$(BDIR).$$sys;\
	   fi;\
	  if (cd $(BDIR)); then echo $(BDIR) already linked;\
	   else echo making link; ln -s .$(BDIR).@sys $(BDIR); \
	   fi;)\
	else \
		mkdir $(INSTALL_DIR)/$(BDIR); fi;\
	echo `date` > $(INSTALL_DIR)/$(BDIR)/.force
endif

ifneq ($(INSTALL_DIR),.)
$(INSTALL_DIR)/$(BDIR)/params/.force:
	if ( cd $(INSTALL_DIR)/params); then \
	  (echo "Using local params file"; \
	  cd $(INSTALL_DIR)/$(BDIR); ln -s ../params params;)\
	else \
	  (echo "Using release params file"; \
	  cd $(INSTALL_DIR)/$(BDIR); ln -s $(PROJECT_DIR)/params params;)\
	fi;
	- echo `date` > $(INSTALL_DIR)/$(BDIR)/params/.force
endif

ifneq ($(INSTALL_DIR),.)
ifeq ($(findstring earhart,$host),)
$(INSTALL_DIR)/$(BDIR)/params/param.std:
	  -(cd $(INSTALL_DIR)/$(BDIR)/params; \
	   echo "Using Xavier param file";\
            ln -s param.xavier param.std;)
else
$(INSTALL_DIR)/$(BDIR)/params/param.std:
	  -(cd $(INSTALL_DIR)/$(BDIR)/params; \
	   echo "Using Amelia param file";\
            ln -s param.amelia param.std;)
endif
endif

ifneq ($(INSTALL_DIR),.)
$(INSTALL_DIR)/$(LDIR)/.force:
	-if $(IS_AFS); then \
	 (sys=$(AFS_TYPE);\
	  cd $(INSTALL_DIR);\
	  if (cd .$(LDIR).$$sys); then echo .$(LDIR).$$sys exists;\
	   else mkdir .$(LDIR).$$sys;\
	   fi;\
	  if (cd $(LDIR)); then echo $(LDIR) already linked;\
	   else echo making link; ln -s .$(LDIR).@sys $(LDIR); \
	   fi;)\
	else \
		mkdir $(INSTALL_DIR)/$(LDIR); fi;\
	echo `date` > $(INSTALL_DIR)/$(LDIR)/.force
endif

#
# want to have code is a separate directory so we can keep multiple versions.
#

$(ODIR)/%.o: %.c
	$(COMPILE.c) -o $@ $<

$(BDIR)/%: $(ODIR)/%.o
	$(LINK.c) -o $@ $< $(LIBRARIES)

#
# want to have some output files compressed
#

..gz:
	gzip $@

#
# want to create tar files for ftp directory.
#

ftp:
	$(RM) -r $(FTP_DIR)/$(PROJECT).tar.gz $(FTP_DIR)/$(PROJECT)
	(cd $(INSTALL_DIR); $(MAKE) link_tar; $(MAKE) tar)
	$(RM) -r $(FTP_DIR)/$(PROJECT)

ifdef SRCS_ALL
link_tar:: $(SRCS_ALL)
	-mkdir $(FTP_DIR)
	-mkdir $(FTP_DIR)/$(PROJECT)
	-mkdir $(FTP_DIR)/$(PROJECT)/$(MODULE_DIR)
	-(for file in $(SRCS_ALL); do\
	  ln -s $(PWD)/$$file $(FTP_DIR)/$(PROJECT)/$(MODULE_DIR);\
	done;)
endif

ifdef SUBDIRS
link_tar::
	-(for sub in $(SUBDIRS); do \
	  (if [ -d $$sub ]; then \
	    echo "Making link_tar for: $$sub";\
	    cd $$sub; $(MAKE) link_tar; fi;) \
	done;)
endif

tar: 
	cd $(FTP_DIR); \
	$(RM) $(PROJECT).tar; \
	tar cfh - $(PROJECT) | gzip >$(PROJECT).tar.gz;

#
# want to be able to give the user a message at the end.
#

install clean all depend :: msg

msg:
	echo $(MSG_$(THIS_MACHINE))

##########
# Exports
##########

export LPATH=:/usr/cs/lib:/usr/lib:/usr/misc/lib
export CPATH=:/usr/misc/include
.EXPORT: LPATH
.EXPORT: CPATH

# other exports, that need to be force evaluated.
export MODULE_DIR := $(MODULE_DIR)
.EXPORT: MODULE_DIR
export SRCS_ALL := $(SRCS_ALL)
.EXPORT: SRCS_ALL
export TCA_DIR := $(TCA_DIR)
.EXPORT: TCA_DIR
export AFS_TYPE := $(AFS_TYPE)
.EXPORT: AFS_TYPE

#other exports.
#export   XMACHINE XBASE_DIR PROJECT_DIR STD_FILE DEFS_FILE BASE_DIR THIS_OS
#.EXPORT: XMACHINE XBASE_DIR PROJECT_DIR STD_FILE DEFS_FILE BASE_DIR THIS_OS

#export   THIS_MACHINE THIS_HOST CVS_BIN CVSROOT IS_AFS
#.EXPORT: THIS_MACHINE THIS_HOST CVS_BIN CVSROOT IS_AFS

# This should export everything.
.EXPORT_ALL_VARIABLES:

##########
# Include a dependency file, if there is one.
##########

ifneq '$(DEPEND_FILE)' ""
  ifneq '$(wildcard $(DEPEND_FILE))' ""
    include $(DEPEND_FILE)
  else
     MSG_sun4c = "*** Do 'gmake depend' to create a dependency file ***"
  endif
endif
