# modified after /usr/include/make/commondefs
#
ROOT =
TOOLROOT =

COMMONRULES= $(ROOTDIR)/commonrules
COMMONTARGS= clobber clean count fluff rmtargets tags

#
# Make tools, i.e., programs which must exist on both native and cross
# development systems to build the software.  $(ECHO) is a make tool because
# echo usage in makefiles should be portable.
#
AR	= $(TOOLROOT)/usr/bin/ar
C++	= $(TOOLROOT)/usr/bin/CC
C++C	= $(TOOLROOT)/usr/bin/CC
CC	= $(TOOLROOT)/usr/bin/cc
LEX     = $(TOOLROOT)/usr/bin/lex -l $(ROOT)/usr/lib/lex/ncform
LD	= $(TOOLROOT)/usr/bin/ld
LINT	= $(TOOLROOT)/usr/bin/lint
NM	= $(TOOLROOT)/usr/bin/nm
SHELL	= /bin/sh
SIZE	= $(TOOLROOT)/usr/bin/size
STRIP	= $(TOOLROOT)/usr/bin/strip
TAG	= $(TOOLROOT)/usr/sbin/tag
YACC	= $(TOOLROOT)/usr/bin/yacc -p $(ROOT)/usr/lib/yaccpar
MAKE	= smake
RM	= rm -rf

#
# Old TOOLROOT-prefixed macros.  References should be replaced with
# native 'echo', 'lex', etc. since special versions shouldn't really be
# needed
#
AWK	= awk
NAWK	= nawk
ECHO	= echo
WC	= wc

#
# The native C compiler, which must be used when building programs that are
# run on the build host from a makefile.
#
HOST_CC  = TOOLROOT= /usr/bin/cc
HOST_C++ = TOOLROOT= /usr/bin/CC
HOST_CXX = $(HOST_C++)

#
# ENDIAN is defined only when cross-compiling
# it normally comes from the $(PRODUCT)defs file.
#
# The -nostdinc flag is defined to defeat searches of /usr/include in
# a cross development environment.  Where it is placed on the command line
# does not matter. This replaces the nullary -I flag.
# Turn off some silly ansi warnings:
# The $(LWOFF) allows makefiles to set local warnings to ignore
# (note that a leading ',' with no whitespace is required).
#
GCOPTS	= $(OPTIMIZER) $(MKDEPOPT)
GCDEFS	=
GCINCS	= -nostdinc -I$(ROOTDIR)/include -I$(INCLDIR) 

#
# Default C version, optimizer, and make-depend options.
#
CVERSION   = -xansi
OPTIMIZER  = -O
MKDEPOPT   = -MDupdate $(MKDEPFILE)

#
# Cc flags, composed of variable (set on the command line), local
# (defined in the makefile), and global (defined in this file) parts, in
# that order.  This ordering has been used so that the variable or
# locally specified include directories are searched before the globally
# specified ones.
#
CFLAGS	= $(CVERSION) $(VCFLAGS) $(LCFLAGS) $(GCFLAGS)

#
# Each of these three components is divided into defines (-D's and -U's),
# includes (-I's), and other options.  By segregating the different
# classes of flag to cc, the defines (CDEFS) and includes (CINCS) can be
# easily given to other programs, e.g., lint.
#
# Notes:
#   - The local assignments should be to LCOPTS, LCDEFS, and LCINCS, not to
#     LCFLAGS, although CFLAGS will be correctly set if this is done.
#   - If a program cannot be optimized, it should override the setting of
#     OPTIMIZER with a line such as "OPTIMIZER=" in its make file.
#   - If a program cannot be compiled with ANSI C, its makefile
#     should set CVERSION=-cckr
#
VCFLAGS	= $(VCDEFS) $(VCINCS) $(VCOPTS)
LCFLAGS	= $(LCDEFS) $(LCINCS) $(LCOPTS)
GCFLAGS	= $(GCDEFS) $(GCINCS) $(GCOPTS)

COPTS	= $(VCOPTS) $(LCOPTS) $(GCOPTS)
CDEFS	= $(VCDEFS) $(LCDEFS) $(GCDEFS)
CINCS	= $(VCINCS) $(LCINCS) $(GCINCS)

#
# C++ flags
#
C++FLAGS  = $(CVERSION) $(VC++FLAGS) $(LC++FLAGS) $(GC++FLAGS)

VC++FLAGS = $(VC++DEFS) $(VC++INCS) $(VC++OPTS)
LC++FLAGS = $(LC++DEFS) $(LC++INCS) $(LC++OPTS)
GC++FLAGS = $(GC++DEFS) $(GC++INCS) $(GC++OPTS)

C++OPTS   = $(VC++OPTS) $(LC++OPTS) $(GC++OPTS)
C++DEFS   = $(VC++DEFS) $(LC++DEFS) $(GC++DEFS)
C++INCS   = $(VC++INCS) $(LC++INCS) $(GC++INCS)

GC++OPTS  = $(OPTIMIZER) $(MKDEPOPT)
GC++DEFS  =
GC++INCS  = -nostdinc -I$(INCLDIR)/CC -I$(INCLDIR)

#
# Loader flags, composed of library (-l's) and option parts, with
# the libraries appearing last.  Both of these are divided into variable,
# local, and global parts.  The composition of LDFLAGS is done in the
# other "direction" from CFLAGS so that all the -L's, which are part of
# LDOPTS, appear before any of the -l's, which are part of LDLIBS.
# Another benefit of segregating the libraries from the remaining of the
# loader options is that the libraries alone can easily be given to
# another program, e.g., lint.
#
# Notes:
#   - -s belongs in GCOPTS or in the IDB program that does the actual
#     installation.
#

# Note: To turn off -quickstart_info for specific Makefile add:
#		LD_QUICKSTART_INFO=
LD_QUICKSTART_INFO=-quickstart_info


LDFLAGS	= $(LDOPTS) $(LDLIBS) $(ENDIAN)

LDOPTS	= $(VLDOPTS) $(LLDOPTS) $(GLDOPTS)
LDLIBS	= $(VLDLIBS) $(LLDLIBS) $(GLDLIBS)
LDOPTS_ABI = -abi $(VLDOPTS) $(LLDOPTS) -nostdlib -L$(ROOT)/usr/lib/abi

GLDOPTS= $(LD_QUICKSTART_INFO)  -nostdlib -L$(ROOTDIR)/lib -L$(ROOT)/lib -L$(ROOT)/usr/lib
GLDLIBS= 

#
# Loader options for making shared objects. By default, shared objects
# are quick started which means using one global share object location file.
# Redefine $(DSOSTARTOPT) to not quick start.
# By default the DT_SONAME section is set to the name of the target shared
# object. Redefine $(DSONAMEOPT) to allow the DT_SONAME section to be
# something other than the targeted shared object name.
#
DSOSTARTOPT = -update_registry $(DSOREGFILE)
DSONAMEOPT  = -soname $@

#
# SGI specific versioning. Redefine $(DSOVERSION) to change version number.
# Redefine $(DSOVERSIONOPT) to skip versioning.
#
DSOVERSION  = sgi1.0
DSOVERSIONOPT  = -set_version $(DSOVERSION)

LDDSOOPTS = -elf -shared -all $(VLDDSOOPTS) $(LLDDSOOPTS) $(GLDDSOOPTS)
LDDSOOPTS_ABI = -elf -shared -all $(VLDDSOOPTS) $(LLDDSOOPTS) $(GLDDSOOPTS_ABI)

# Note:  To turn off  -no_unresolved  for a specific library Makefile, add:
#		LD_NO_UNRESOLVED=
LD_NO_UNRESOLVED=-no_unresolved

GLDDSOOPTS  = $(MKDEPOPT) $(LD_NO_UNRESOLVED) $(LD_QUICKSTART_INFO) $(DSOSTARTOPT) $(DSONAMEOPT) $(DSOVERSIONOPT)
GLDDSOOPTS_ABI  = $(MKDEPOPT) $(DSONAMEOPT)

#
# The install command to use.
#
INSTALL	= $(TOOLROOT)/etc/install

#
# MKDEPFILE is the name of the dependency database, included by commonrules.
#
MKDEPFILE = Makedepend

#
# Name of the runtime linker in /
#
# Note: this is used to set the PR_INTERP_NAME, but the DT_RPATH elf var must
# be set to the root of the $ROOTRLDNAME as well.
#
ROOTRLDNAME=/lib/libc.so.1,-rpath,/lib

#
# SOREGFILE is the name of the shared object location file, included by
# commonrules.
#
DSOREGFILE = $(ROOT)/usr/lib/so_locations

#
# Flags to handle yacc and lex automatic dependency generation
#
YACCMKDEPFLAGS=-MDtarget $*.o
LEXMKDEPFLAGS=-MDtarget $*.o

#
# Include directory shorthands, used in CFLAGS and LDFLAGS components.
#
INCLDIR	= $(ROOT)/usr/include

#
# Convenient command macros that include the flags macros.
#
# You should always invoke make in makefiles via $(MAKE), as make passes
# all command-line variables through the environment to sub-makes.
#
# Never use just $(CCF), etc. in rules that link executables; LDFLAGS
# needs to be included after your objects in the command line.
#
ASF	= $(AS) $(ASFLAGS)
C++F	= $(CXX) $(CXXFLAGS)
CXXF	= $(C++F)
CCF	= $(CC) $(CFLAGS)
F77F	= $(F77) $(FFLAGS)
LDF	= $(LD) $(LDFLAGS)
LEXF	= $(LEX) $(LFLAGS)
PCF	= $(PC) $(PFLAGS)
YACCF	= $(YACC) $(YFLAGS)

#
# Rule macros for nonterminal makefiles that iterate over subdirectories,
# making the current target.  Set *SUBDIRS to the relevant list of kids.
#
# Set NOSUBMESG to any value to supress a warning that subdirectories 
# are not present. This is useful with mandefs/rules
#
SUBDIR_MAKERULE= \
	if test ! -d $$d; then \
		if test "$(NOSUBMESG)" = "" ; then \
			echo "SKIPPING $$d: No such directory."; \
		fi \
	else \
		echo "\t(cd $$d; $(MAKE) $${RULE:=$@})"; \
		(cd $$d; ${MAKE} $${RULE:=$@}); \
	fi

SUBDIRS_MAKERULE= \
	@for d in $(SUBDIRS); do $(SUBDIR_MAKERULE); done

HEADERS_SUBDIRS_MAKERULE= \
	@for d in $(HEADERS_SUBDIRS); do $(SUBDIR_MAKERULE); done

EXPORTS_SUBDIRS_MAKERULE= \
	@for d in $(EXPORTS_SUBDIRS); do $(SUBDIR_MAKERULE); done

#
# Library .c.o rule macros -- someday, cc -r will do the right thing and
# the G-number will be happily forgotten.
#
LIBRARY_AS_MAKERULE= \
	$(ASF) -o $*.o $< && \
	$(LD) $(LIBGNUM) -r $*.o -o $$$$.o && \
	mv $$$$.o $*.o

LIBRARY_CC_MAKERULE= \
	$(CCF) -c $< && \
	$(LD) $(LIBGNUM) -r $*.o -o $$$$.o && \
	mv $$$$.o $*.o

LIBRARY_CXX_MAKERULE= \
	$(CXXF) -c $< && \
	$(LD) $(LIBGNUM) -r $*.o -o $$$$.o && \
	mv $$$$.o $*.o

LIBRARY_C++_MAKERULE= \
	$(C++F) -c $< && \
	$(LD) $(LIBGNUM) -r $*.o -o $$$$.o && \
	mv $$$$.o $*.o


#
# The macro naming commonrules' always-unsatisfied target, which is useful
# in directory dependencies to guarantee that even directories having future
# mtimes due to timewarps will be "made".
#
_FORCE=$(COMMONPREF)_force

#
# Convenience file list macros:
#	- Commondefs defines the following lists: SOURCES, enumerating all
#	  source files; OBJECTS, the .o files derived from compilable source;
#	  and DIRT, which lists intermediates and temporary files to be
#	  removed by clean.
#	- The including (parent) makefile may define source file lists for
#	  the standard suffixes: CFILES for .c, ASFILES for .s, YFILES for
#	  .y, etc.  We combine all such lists into SOURCES.  The including
#	  makefile need not define CFILES &c before including commondefs.
#
CXXFILES=$(C++FILES)
SOURCES=$(HFILES) $(ASFILES) $(CXXFILES) $(CFILES) $(EFILES) $(FFILES) \
	$(LFILES) $(PFILES) $(RFILES) $(SHFILES) $(YFILES)

CXXO1=$(CXXFILES:.c++=.o)
CXXO2=$(CXXO1:.cxx=.o)
CXXOALL=$(CXXO2)
YO1=$(YFILES:.y=.o)
YO2=$(YO1:.yxx=.o)
YOALL=$(YO2)
LO1=$(LFILES:.l=.o)
LO2=$(LO1:.lxx=.o)
LOALL=$(LO2)
OBJECTS=$(ASFILES:.s=.o) $(CXXOALL) $(CFILES:.c=.o) $(EFILES:.e=.o) \
	$(FFILES:.f=.o) $(LOALL) $(PFILES:.p=.o) $(RFILES:.r=.o) \
	$(YOALL) 

#
# Makefiles should set LDIRT only 
#
# Make include files that extend commondefs should set XDIRT for dirt
# generated by the extension. It should also provide an XfooDIRT macro for
# the benefit of any extensions to itself. The intent is that the user's
# Makefile will just worry about its own dirt.
#
DIRT=$(GDIRT) $(VDIRT) $(LDIRT) $(XDIRT)
GDIRT=*.[ou] a.out core lex.yy.[co] y.tab.[cho] $(_FORCE) ar.tmp.*

#
# Local definitions.  These are used for debugging purposes.  Make sure that
# the product builds properly without the local definitions, unless you check
# in the local definitions!
#
# To access a localdefs file outside the current directory, set LOCALDEFS on
# the command line, and likewise for localrules.  Or you can have localdefs
# just sinclude the appropriate other include file.
#
LOCALDEFS  = ./localdefs
LOCALRULES = ./localrules

sinclude $(LOCALDEFS)
