#
#
#  Copyright (C) 2000, 2001 Silicon Graphics, Inc.  All Rights Reserved.
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of version 2 of the GNU General Public License as
#  published by the Free Software Foundation.
#
#  This program is distributed in the hope that it would be useful, but
#  WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
#
#  Further, this software is distributed without any warranty that it is
#  free of the rightful claim of any third person regarding infringement 
#  or the like.  Any license provided herein, whether implied or 
#  otherwise, applies only to this software file.  Patent licenses, if 
#  any, provided herein do not apply to combinations of this program with 
#  other software, or any other product whatsoever.  
#
#  You should have received a copy of the GNU General Public License along
#  with this program; if not, write the Free Software Foundation, Inc., 59
#  Temple Place - Suite 330, Boston MA 02111-1307, USA.
#
#  Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pky,
#  Mountain View, CA 94043, or:
#
#  http://www.sgi.com
#
#  For further information regarding this notice, see:
#
#  http://oss.sgi.com/projects/GenInfo/NoticeExplan
#
#

#ident "$Revision: 1.1.1.1 $"
#
# Common makefile rules.
#
# Notes:
#	- After including $(ROOT)/usr/include/make/commondefs, a makefile may
#	  say ``include $(COMMONRULES)'' to get this file.
#	- It is up to the including makefile to define a default rule before
#	  including $(COMMONRULES).
#	- The parent makefile must define TARGETS in order for clobber to work.
#
#	- if BUILD_SUBDIRS is set, then iterate over that for the COMMONTARGS

#
# An always-unsatisfied target.  The name is unlikely to occur in a file tree,
# but if _force existed in a make's current directory, this target would be
# always-satisfied and targets that depended on it would not be made.
#
$(_FORCE):

#
# File removal rules: there are three.
#	- clean removes dirt
#	- clobber removes targets, dirt, and Makedepend
#	- rmtargets removes targets only
# One might 'make clean' in a large tree to reclaim disk space after targets
# are built, but before they are archived into distribution images on disk.
# One might 'make rmtargets' to remove badly-linked executables, and then
# run a 'make' to re-link the good objects.
#
CWD := $(shell pwd)

ifdef BUILD_SUBDIRS
# use separate clobber so don't recurse on each sub-target
clobber: $(_FORCE)
	rm -rf $(DIRT)
	rm -rf $(TARGETS)
	rm -rf $(MKDEPFILE)
	@for d in $(BUILD_SUBDIRS); do cd $(CWD)/$$d && $(MAKE) $@; done
else
clobber: clean rmtargets $(_FORCE)
	rm -rf $(MKDEPFILE)
endif

clean: $(_FORCE)
	rm -rf $(DIRT)
ifdef BUILD_SUBDIRS
	@for d in $(BUILD_SUBDIRS); do cd $(CWD)/$$d && $(MAKE) $@; done
endif

rmtargets: $(_FORCE)
	rm -rf $(TARGETS)
ifdef BUILD_SUBDIRS
	@for d in $(BUILD_SUBDIRS); do cd $(CWD)/$$d && $(MAKE) $@; done
endif

#
# A better version of smake's makelib.mk rule.
# XXX fix makelib.mk in next release and remove this rule.
#
MAKELIB: .USE .PRECIOUS
	$(AR) c$(ARFLAGS) $@ $?
	rm -f $?

%.o : %.cxx
	$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

make_deps:
ifneq ($(BUILD_COMPILER), EDG)
	-@cat *.d > $(MKDEPFILE)
endif

# make dependencies be for library(foo.o) not for foo.o,
# thus we don't need to preserve intermediate .o files.
make_libdeps :
ifneq ($(BUILD_COMPILER), EDG)
	-@cat *.d > $(MKDEPFILE).tmp
	-@sed -e "s/^.*\.o/$(LIBRARY)(&)/" $(MKDEPFILE).tmp > $(MKDEPFILE)
	-@rm $(MKDEPFILE).tmp
endif

#
# Include the make dependency file if it exists.
#
-include $(MKDEPFILE)

#
# Local make rules
#
-include $(LOCALRULES)
