# Copyright 1990-1995 Silicon Graphics, Inc.  All rights reserved.
#
#ident "$Revision: 1.5 $"
#
# Common makefile definitions.
#
# Notes:
#   - Definitions with the same names only need to be passed on the
#     command line of recursive makes if they would be redefined by
#     the sub-makefile.  Definitions passed on the command line are
#     not reset by the environment or the definitions in the makefile.
#   - C++ style macros are deprecated and will be removed when out of use.
#     They must be interwoven in definitions to keep upward compatibility.
#
#   - The contents of this header are changed based on some variables
#     should be defined BEFORE including this file:
#     OBJECT_STYLE - define basic ABI/ISA that should be used to create product.
#	this also sets LD search paths, C/C++/Fortran/Pascal options.
#     NO_OBJECT_STYLE - disable all this new OBJECT_STYLE business.
#	Note that if one does this all the info in releasedefs about
#	compiler versions, default compilation modes etc will be ignored.
#	Only smake-files can do this.
#     NO_LSRCH - do not set any library searching rules for LD options.
#     ASTYLE  - by default, the ABI/ISA for C is used for assembler -
#	setting ASTYLE (to be assembler options) can override the OBJECT_STYLE
#	to permit fine-tuning of asm code.
#     NO_STARTOPT - don't set any of the DSO start option macros - this
#	will keep the global so_locations files from being updated.
#
COMMONRULES= $(IVDEPTH)/make/commonrules
COMMONTARGS= clobber clean rmtargets fluff tags
RELEASEDEFS= $(IVDEPTH)/make/releasedefs

# include releasedefs by default
ifndef NO_RELEASEDEFS
include $(RELEASEDEFS)
endif

# Build tools, i.e., programs which are used as part of the build
# process.  These must run on all supported build environments
# (currently IRIX 6.2 and up).

AR	= $(TOOLROOT)/usr/bin/ar
AS	= $(TOOLROOT)/usr/bin/as $(ENDIAN)
BISON   = $(TOOLROOTSAFE) $(TOOLROOT)/usr/bin/bison
C++	= $(TOOLROOT)/usr/bin/CC
C++C	= $(TOOLROOT)/usr/bin/CC
CC	= $(TOOLROOT)/usr/bin/cc
CORD    = $(TOOLROOT)/usr/bin/cord
CXX	= $(C++)
F77	= $(TOOLROOT)/usr/bin/f77
FC	= $(TOOLROOT)/usr/bin/f77
FLEX    = $(TOOLROOTSAFE) $(TOOLROOT)/usr/bin/flex
GNUM4	= $(TOOLROOTSAFE) $(TOOLROOT)/usr/bin/gnum4
LEX	= $(TOOLROOT)/usr/bin/lex -l $(ROOT)/usr/lib/lex/ncform
LD	= $(TOOLROOT)/usr/bin/ld
LIBSPEC	= $(TOOLROOT)/usr/sbin/libspec
LINT	= $(TOOLROOT)/usr/bin/lint
LORDER	= $(TOOLROOT)/usr/bin/lorder
MKF2C   = $(TOOLROOT)/usr/bin/mkf2c
NM	= $(TOOLROOT)/usr/bin/nm
PC	= $(TOOLROOT)/usr/bin/pc
SETMAGIC= $(TOOLROOT)/usr/sbin/setmagic
SIZE	= $(TOOLROOT)/usr/bin/size
STRIP	= $(TOOLROOT)/usr/bin/strip
TAG	= $(TOOLROOT)/usr/sbin/tag
TLINK	= $(TOOLROOT)/usr/sbin/tlink
YACC    = $(TOOLROOTSAFE) $(TOOLROOT)/usr/bin/yacc
ifeq ($(usingIrix), 1)
YACC	+= -P $(ROOT)/usr/lib/yaccpar
endif

# Old TOOLROOT-prefixed macros.  References should be replaced with
# native 'echo', sh, etc. since special versions shouldn't really be
# needed

SHELL	= /bin/sh
AWK	= awk
NAWK	= awk
ECHO	= echo
M4	= m4

#
# Popular ABI/ISA combinations supported here:
#
# 32_M2		- MIPS/ABI; 32 bit; mips2
# 32_ABI	- MIPS/ABI; 32 bit; mips1; ABI restrictions
# N32_M3	- new calling convention; 32 bit; mips3
# N32_M4	- new calling convention; 32 bit; mips4
# 64_M3		- new calling convention; 64 bit; mips3
# 64_M4		- new calling convention; 64 bit; mips4
# 64_ABI	- MIPS/ABI; 64 bit; mips3/4; ABI restrictions
#
# The following are 'generic' these should be used unless fine control
# over ISA is required (releasedefs decides which ISA):
#
# 32		- MIPS/ABI; 32 bit;
# N32		- new calling convention; 32 bit;
# 64		- new calling convention; 64 bit;
#
ALLSTYLES=32 32_M2 32_ABI N32 N32_M3 N32_M4 64 64_M3 64_M4 64_ABI
ALLSTYLES+=IA32

#
# 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).
#
# Criteria for adding a global woff:
#	a) it in no way could indicate a potential bug in the software.
#		This assumes that the software is required only to run on
#		SGI equipment with SGI compilers.
#	b) The infraction is ubiquitous. If only a few pieces of software
#		suffer from a given warning - they should turn it off in
#		their own Makefile (or fix it!).
#
# The ignored 3.XX compiler warnings are as followings:
#
#	515 - Constant is out of range and may be truncated
#	608 - Undefined the ANSI standard library defined macro <macro>
#	658 - bit-field <name> type required to be int, unsigned int,
#	      or signed int
#	799 - <keyword/type> is not standard ANSI
#	803 - Ignored invalid warning number(s) in -woff option
#	852 - can be const qualified (-wlint)
#
# The ignored 4.XX compiler warnings are as follows:
#	1048 - cast between pointer-to-object and pointer-to-function
#	1233 - explicit type is missing ("int" assumed)
#	1499 - -woff arguments must be in the range ...
#	1685 - The v6.02 compiler changes woff #1499 to 1685.
#	       The specific error is "invalid error number <warning number>"
ifeq ($(usingIrix), 1)
WOFF=-woff 1685,515,608,658,799,803,852,1048,1233,1499$(LWOFF)
endif

#
# Default C version, optimizer, common global options, and make-depend options.
#
CVERSION   = 
OPTIMIZER  = -O
ifeq ($(usingIrix), 1)
MKDEPOPT   = -MDupdate $(MKDEPFILE)
endif
COMMONGOPTS=$(OPTIMIZER) $(MKDEPOPT) $(ENDIAN)

#
# Pick appropriate STYLE - releasedefs defines the default
# Note that binaries that don't have absolute ISA requirements should use
# the generic OBJECT_STYLE={64, 32, N32}. This permits the default to be
# set by releasedefs
#
CSTYLE_32_M2 = -mips2 -o32
CSTYLE_32_ABI= -mips1 -o32 -D_MIPSABI_SOURCE=3
CSTYLE_N32_M3= -mips3 -n32
CSTYLE_N32_M4= -mips4 -n32
CSTYLE_R32   = -mips3 -r32
CSTYLE_64_M3 = -mips3 -64
CSTYLE_64_M4 = -mips4 -64
CSTYLE_64_ABI = -mips3 -64 -D_MIPSABI_SOURCE=3
CSTYLE_IA32  =

# 'generic' styles - per ABI. releasedefs sets what it is.
# DEF_CSTYLE's are set in releasedefs
CSTYLE_32    = $(DEF_CSTYLE_32)
CSTYLE_N32   = $(DEF_CSTYLE_N32)
CSTYLE_64    = $(DEF_CSTYLE_64)

#
# Set OBJECT_STYLE if it hasn't already been set - note that std 'make'files
# will get this value. This is somewhat convoluted to be sure that
# 'make'-files will get the 'correct' value
#
ifdef NO_OBJECT_STYLE
OBJECT_STYLE=NONE
endif

ifndef OBJECT_STYLE
OBJECT_STYLE = $(DEF_OBJECT_STYLE)
endif

# set in releasedefs
# This is the one that 'make' sees
CSTYLE=$(DEF_CSTYLE)

ifeq "$(OBJECT_STYLE)" "64"
CSTYLE=$(CSTYLE_64)
endif
ifeq "$(OBJECT_STYLE)" "64_M3"
CSTYLE=$(CSTYLE_64_M3)
endif
ifeq "$(OBJECT_STYLE)" "64_M4"
CSTYLE=$(CSTYLE_64_M4)
endif
ifeq "$(OBJECT_STYLE)" "64_ABI"
CSTYLE=$(CSTYLE_64_ABI)
endif
ifeq "$(OBJECT_STYLE)" "32_ABI"
CSTYLE=$(CSTYLE_32_ABI)
endif
ifeq "$(OBJECT_STYLE)" "N32"
CSTYLE=$(CSTYLE_N32)
endif
ifeq "$(OBJECT_STYLE)" "N32_M3"
CSTYLE=$(CSTYLE_N32_M3)
endif
ifeq "$(OBJECT_STYLE)" "N32_M4"
CSTYLE=$(CSTYLE_N32_M4)
endif
ifeq "$(OBJECT_STYLE)" "R32"
CSTYLE=$(CSTYLE_R32)
endif
ifeq "$(OBJECT_STYLE)" "32"
CSTYLE=$(CSTYLE_32)
endif
ifeq "$(OBJECT_STYLE)" "32_M2"
CSTYLE=$(CSTYLE_32_M2)
endif
ifeq "$(OBJECT_STYLE)" "IA32"
CSTYLE=$(CSTYLE_IA32)
endif
ifeq "$(OBJECT_STYLE)" "NONE"
CSTYLE=
endif

GCOPTS	= $(CSTYLE) $(OPTIMIZER) $(ENDIAN) $(MKDEPOPT) $(WOFF)
GCDEFS	=
ifeq ($(usingIrix), 1)
GCINCS	= -nostdinc -I$(INCLDIR)
endif

#
# Cc flags, composed of:
#	variable (V*) (set on the command line),
#	local (L*) (defined in the makefile),
#	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)

#
# CXX flags are decomposed using the same hierarchy as C flags.
#
C++FLAGS  = $(CVERSION) $(VCXXFLAGS) $(LCXXFLAGS) $(GCXXFLAGS)
CXXFLAGS  = $(C++FLAGS)

VCXXFLAGS = $(VCXXDEFS) $(VCXXINCS) $(VCXXOPTS) $(VC++FLAGS)
LCXXFLAGS = $(LCXXDEFS) $(LCXXINCS) $(LCXXOPTS) $(LC++FLAGS)
GCXXFLAGS = $(GC++FLAGS)

CXXOPTS   = $(VCXXOPTS) $(LCXXOPTS) $(GCXXOPTS) $(C++OPTS)
CXXDEFS   = $(VCXXDEFS) $(LCXXDEFS) $(GCXXDEFS) $(C++DEFS)
CXXINCS   = $(VCXXINCS) $(LCXXINCS) $(GCXXINCS) $(C++INCS)

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  = $(CSTYLE) $(OPTIMIZER) $(ENDIAN) $(MKDEPOPT)
ifeq ($(usingIrix), 1)
GC++INCS  = -nostdinc -I$(INCLDIR)/CC -I$(INCLDIR)
endif
GC++DEFS  = 

#
# 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

#
# locations to search for libs. We search the 'generic' locations such
# as usr/lib64 even though those are installed in a machine specific manner.
# This permits library writers that only want to have one 'least-common-
# denominator' version per ABI to install it directly in the generic location
# without having to create links. This should be OK in the build environment
# since we always search the specific directories first.
#
# Some user's may not want all this searching help - they can specify
# NO_LSRCH
#
ifndef NO_LSRCH
LSRCH_32_M2 =	-L$(ROOT)/lib -L$(ROOT)/usr/lib -L$(ROOT)/usr/lib/internal
LSRCH_N32_M3 =	-L$(ROOT)/usr/lib32/mips3 -L$(ROOT)/usr/lib32 -L$(ROOT)/usr/lib32/internal
LSRCH_N32_M4 =	-L$(ROOT)/usr/lib32/mips4 -L$(ROOT)/usr/lib32 -L$(ROOT)/usr/lib32/internal
LSRCH_32_ABI =	-L$(ROOT)/usr/lib/abi
LSRCH_R32    =	-L$(ROOT)/libr32 -L$(ROOT)/usr/libr32
LSRCH_64_M3 =	-L$(ROOT)/usr/lib64/mips3 -L$(ROOT)/usr/lib64 -L$(ROOT)/usr/lib64/internal
LSRCH_64_M4 =	-L$(ROOT)/usr/lib64/mips4 -L$(ROOT)/usr/lib64 -L$(ROOT)/usr/lib64/internal
LSRCH_64_ABI =	-L$(ROOT)/usr/lib64/abi
endif

#
# each 'popular' combination of ABI and ISA gets its own set of
# GLDOPTS_*
# It is assumed that a command that needs to be built with more than
# one ABI uses cmdcommon* - thus the appropriate versiondefs file will
# contain any needed VERSION_LDOPTS.
#
# DSO's don't follow this rule - they typically create all versions at the
# top - thus, they need access to all possible LDOPTS_* values, and need
# a way to add additional options per object style. So, we add a set of LDOPTS_*
# this can also be used for makefiles that would rather not use cmdcommon*.
#
GLDOPTS_32_M2 = -mips2 -o32 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_32_M2)
GLDOPTS_32_ABI= -o32 -abi -nostdlib $(LSRCH_32_ABI)
GLDOPTS_N32_M3= -mips3 -n32 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_N32_M3)
GLDOPTS_N32_M4= -mips4 -n32 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_N32_M4)
GLDOPTS_R32   = -r32 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_R32)
GLDOPTS_64_M3 = -mips3 -64 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_64_M3)
GLDOPTS_64_M4 = -mips4 -64 $(LD_QUICKSTART_INFO) -nostdlib $(LSRCH_64_M4)
GLDOPTS_64_ABI= -mips3 -64 -abi -nostdlib $(LSRCH_64_ABI)
# until new ld
GLDOPTS_64_ABI= -mips3 -64 -nostdlib $(LSRCH_64_ABI)
GLDOPTS_IA32  =
#
# Most objects don't have absolute requirements for ISA - use these
# to get the default for each ABI as set by the release gods.
#
GLDOPTS_32    =$(DEF_GLDOPTS_32)
GLDOPTS_N32   =$(DEF_GLDOPTS_N32)
GLDOPTS_64    =$(DEF_GLDOPTS_64)

GLDLIBS= 

#
# LDFLAG layout
#
# Incompatibility from previous commondefs:
#	a) setting of LDOPTS in a makefile is probably wrong
#
LDFLAGS	= $(LDOPTS) $(LDLIBS) $(ENDIAN)
LDOPTS	= $(VLDOPTS) $(LLDOPTS) $(GLDOPTS)

LDLIBS	= $(VLDLIBS) $(LLDLIBS) $(GLDLIBS)

#
# Pick appropriate GLDOPTS - releasedefs defines the default
# Note that binaries that don't have absolute ISA requirements should use
# the generic OBJECT_STYLE={64, 32, N32}. This permits the default to be
# set by releasedefs
#
# set in releasedefs
# This is one that 'make' sees
GLDOPTS=$(DEF_GLDOPTS)

ifeq "$(OBJECT_STYLE)" "64"
GLDOPTS=$(GLDOPTS_64)
endif
ifeq "$(OBJECT_STYLE)" "64_M3"
GLDOPTS=$(GLDOPTS_64_M3)
endif
ifeq "$(OBJECT_STYLE)" "64_M4"
GLDOPTS=$(GLDOPTS_64_M4)
endif
ifeq "$(OBJECT_STYLE)" "64_ABI"
GLDOPTS=$(GLDOPTS_64_ABI)
endif
ifeq "$(OBJECT_STYLE)" "32_ABI"
GLDOPTS=$(GLDOPTS_32_ABI)
endif
ifeq "$(OBJECT_STYLE)" "N32"
GLDOPTS=$(GLDOPTS_N32)
endif
ifeq "$(OBJECT_STYLE)" "N32_M3"
GLDOPTS=$(GLDOPTS_N32_M3)
endif
ifeq "$(OBJECT_STYLE)" "N32_M4"
GLDOPTS=$(GLDOPTS_N32_M4)
endif
ifeq "$(OBJECT_STYLE)" "R32"
GLDOPTS=$(GLDOPTS_R32)
endif
ifeq "$(OBJECT_STYLE)" "32"
GLDOPTS=$(GLDOPTS_32)
endif
ifeq "$(OBJECT_STYLE)" "32_M2"
GLDOPTS=$(GLDOPTS_32_M2)
endif
ifeq "$(OBJECT_STYLE)" "IA32"
GLDOPTS=$(GLDOPTS_IA32)
endif
ifeq "$(OBJECT_STYLE)" "NONE"
GLDOPTS=
endif

LDOPTS_32    =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_32_M2) $(GLDOPTS_32_M2)
LDOPTS_32_M2 =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_32_M2) $(GLDOPTS_32_M2)
LDOPTS_32_ABI=$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_32_ABI) $(GLDOPTS_32_ABI)
LDOPTS_N32   =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_N32_M3) $(GLDOPTS_N32)
LDOPTS_N32_M3=$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_N32_M3) $(GLDOPTS_N32_M3)
LDOPTS_N32_M4=$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_N32_M4) $(GLDOPTS_N32_M4)
LDOPTS_R32   =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_R32) $(GLDOPTS_R32)
LDOPTS_64    =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_64_M3) $(GLDOPTS_64)
LDOPTS_64_M3 =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_64_M3) $(GLDOPTS_64_M3)
LDOPTS_64_M4 =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_64_M4) $(GLDOPTS_64_M4)
LDOPTS_64_ABI=$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_64_ABI) $(GLDOPTS_64_ABI)
LDOPTS_IA32  =$(VLDOPTS) $(LLDOPTS) $(LLDOPTS_IA32) $(GLDOPTS_IA32)

#
# Loader options for making shared objects. By default, shared objects
# are all registered in a global location file.
# Redefine $(DSOSTARTOPT) to not update the registry file
#
# 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.
#
# DSOs are typically all made in one top level makefile, in place, rather
#	than in subdirectories - therefore all the various flags must be
#	present with no conditionals
#
#
# To build a DSO that doesn't use lib*rules:
#
# $(LD) $(LDDSOOPTS) $(LDOPTS) $(OBJECTS) $(LDLIBS) -o $@
#
# Note that LDOPTS must be before the OBJECTS and LDLIBS must be after.
# For local .so's make it easy to not update any registry files
#
ifndef NO_STARTOPT
DSOREGFILE_32 = $(ROOT)/usr/lib/so_locations
DSOREGFILE = $(DSOREGFILE_32)
DSOREGFILE_R32 = $(ROOT)/usr/libr32/so_locations
DSOREGFILE_64 = $(ROOT)/usr/lib64/so_locations
DSOREGFILE_N32 = $(ROOT)/usr/lib32/so_locations

DSOSTARTOPT_32 = -update_registry $(DSOREGFILE_32)
DSOSTARTOPT = $(DSOSTARTOPT_32)
DSOSTARTOPT_R32 = -update_registry $(DSOREGFILE_R32)
DSOSTARTOPT_64 = -update_registry $(DSOREGFILE_64)
DSOSTARTOPT_N32 = -update_registry $(DSOREGFILE_N32)
endif

DSONAMEOPT  = -soname $@

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

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

#
# Export files - each build can have up to 2 exports file - a common
# one (DSOEXPORTS) and a per-ABI version (DSOEXPORTS_XXX)
# Note that _ABI (MIPS ABI) ONLY uses the DSOEXPORTS_XX_ABI) exports file
# This feature not available for make ...
# Note that these macros must be set BEFORE including commondefs/librootdefs
#
ifdef DSOEXPORTS
DSOEXPORTSOPT=-exports_file $(DSOEXPORTS)
else
# this is what make sees
DSOEXPORTSOPT=
endif

# Permit per ABI exports file
ifdef DSOEXPORTS_32
DSOEXPORTSOPT_32=-exports_file $(DSOEXPORTS_32)
else
# this is what make sees
DSOEXPORTSOPT_32=
endif
ifdef DSOEXPORTS_32_ABI
DSOEXPORTSOPT_32_ABI=-exports_file $(DSOEXPORTS_32_ABI)
else
# this is what make sees
DSOEXPORTSOPT_32_ABI=
endif
ifdef DSOEXPORTS_N32
DSOEXPORTSOPT_N32=-exports_file $(DSOEXPORTS_N32)
else
# this is what make sees
DSOEXPORTSOPT_N32=
endif
ifdef DSOEXPORTS_64
DSOEXPORTSOPT_64=-exports_file $(DSOEXPORTS_64)
else
# this is what make sees
DSOEXPORTSOPT_64=
endif
ifdef DSOEXPORTS_64_ABI
DSOEXPORTSOPT_64_ABI=-exports_file $(DSOEXPORTS_64_ABI)
else
# this is what make sees
DSOEXPORTSOPT_64_ABI=
endif

#
# Each ABI gets the generic *LDDSOOPTS as well as a set of ABI specific ones
#
LDDSOOPTS_32  = $(VLDDSOOPTS) $(VLDDSOOPTS_32) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_32) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_32)
LDDSOOPTS_32_ABI= $(VLDDSOOPTS) $(VLDDSOOPTS_32_ABI) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_32_ABI) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_32_ABI)
LDDSOOPTS_R32 = $(VLDDSOOPTS) $(VLDDSOOPTS_R32) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_R32) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_R32)
LDDSOOPTS_N32 = $(VLDDSOOPTS) $(VLDDSOOPTS_N32) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_N32) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_N32)
LDDSOOPTS_64  = $(VLDDSOOPTS) $(VLDDSOOPTS_64) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_64) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_64)
LDDSOOPTS_64_ABI= $(VLDDSOOPTS) $(VLDDSOOPTS_64_ABI) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_64_ABI) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_64_ABI)
LDDSOOPTS_IA32  = $(VLDDSOOPTS) $(VLDDSOOPTS_IA32) \
		$(LLDDSOOPTS) $(LLDDSOOPTS_IA32) \
		$(GLDDSOOPTS) $(GLDDSOOPTS_IA32)

# Totally generic - common options for all ABIs
ifeq ($(usingIrix), 1)
GLDDSOOPTS  = -elf -shared -all $(MKDEPOPT) $(DSONAMEOPT)
endif

GLDDSOOPTS_32  = $(LD_NO_UNRESOLVED) $(LD_QUICKSTART_INFO) \
			$(DSOEXPORTSOPT) $(DSOEXPORTSOPT_32) \
			$(DSOSTARTOPT_32) $(DSOVERSIONOPT)
GLDDSOOPTS_32_ABI  = $(DSOEXPORTSOPT_32_ABI)
GLDDSOOPTS_R32  = $(LD_NO_UNRESOLVED) $(LD_QUICKSTART_INFO) \
			$(DSOSTARTOPT_R32) $(DSOVERSIONOPT)
GLDDSOOPTS_N32  = $(LD_NO_UNRESOLVED) $(LD_QUICKSTART_INFO) \
			$(DSOEXPORTSOPT) $(DSOEXPORTSOPT_N32) \
			$(DSOSTARTOPT_N32) $(DSOVERSIONOPT)
GLDDSOOPTS_64   = $(LD_NO_UNRESOLVED) $(LD_QUICKSTART_INFO) \
			$(DSOEXPORTSOPT) $(DSOEXPORTSOPT_64) \
			$(DSOSTARTOPT_64) $(DSOVERSIONOPT)
GLDDSOOPTS_64_ABI   = $(DSOEXPORTSOPT_64_ABI)
GLDDSOOPTS_IA32 = $(DSOEXPORTSOPT) $(DSOEXPORTSOPT_IA32) \
			$(DSOSTARTOPT_IA32)

#
# set LDDSOOPTS based on OBJECT_STYLE - makes it easier to make .so's
# when one doesn't use lib*defs
#
# this is what 'make' sees
LDDSOOPTS=$(LDDSOOPTS_32)

ifeq "$(OBJECT_STYLE)" "32_ABI"
LDDSOOPTS=$(LDDSOOPTS_32_ABI)
endif
ifeq "$(OBJECT_STYLE)" "64_ABI"
LDDSOOPTS=$(LDDSOOPTS_64_ABI)
endif
ifneq (, $(findstring M64, $(OBJECTS_STYLE)))
LDDSOOPTS=$(LDDSOOPTS_64)
endif
ifneq (, $(findstring MN32, $(OBJECTS_STYLE)))
LDDSOOPTS=$(LDDSOOPTS_N32)
endif
ifneq (, $(findstring M32, $(OBJECTS_STYLE)))
LDDSOOPTS=$(LDDSOOPTS_32)
endif
ifneq (, $(findstring IA32, $(OBJECT_STYLE)))
LDDSOOPTS=$(LDDSOOPTS_IA32)
endif
ifeq "$(OBJECT_STYLE)" "NONE"
LDDSOOPTS=
endif

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


#
#  For people who want to run etags on other types of files
#
CTAGFILES = \( -name '*.[cfhlpy]' -o -name '*.c++' \)

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

#
# Name of the location of various libs $(ROOT)/usr/$(LIB_LOCATION)/libfoo.[a,so]
# This is set in the releasedefs file.
#
LIB_LOCATION_O32=lib
LIB_LOCATION_N32=lib32
LIB_LOCATION_IA32=lib

#
# 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.
#
# To allow the changing of the default object style ... we now have
# two different ROOTRLDNAME's which then can be mapped to ROOTRLDNAME.
# The variable ROOTRLDNAME is set in the releasedefs file.
#
ROOTRLDNAME_O32=/lib/libc.so.1,-rpath,/lib
ROOTRLDNAME_N32=/lib32/libc.so.1,-rpath,/lib32
ROOTRLDNAME_IA32=


#
# 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 suppress a warning that subdirectories 
# are not present. This is useful with mandefs/rules
#
SUBDIR_MAKERULE= \
	$(MAKE) -C$$d $${RULE:=$@} || exit 1

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

#
# One problem with the above rules is that if a make fails, and -k is
# set, the entire for loop might stop. This is because make still can
# (and XPG requires it) exit with an error status if the -k option is set.
# This is an alternate rule for SUBDIRS when it is desired that -k keep
# working on the next SUBDIR if the previous one failed. Its not quite
# as compact a rule as the previous ones.
# A standard usage would be:
#	default install $(COMMONTARGS): $(_FORCE)
#		$(MAKE) __DORULE=$@ $(SUBDIRS)
#	$(SUBDIRS): $(_FORCE)
#		@$(NSUBDIR_MAKERULE)

NSUBDIR_MAKERULE= \
	$(MAKE) -C$@ $(__DORULE)

#
# 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

#
# Permit dependencies for Null-suffix targets
#
.MAKEOPTS: -N


#
# 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.
#
SOURCES=$(HFILES) $(ASFILES) $(C++FILES) $(CXXFILES) $(CFILES) $(EFILES) \
	$(FFILES) $(LFILES) $(PFILES) $(RFILES) $(SHFILES) $(YFILES)

CXXO1=$(CXXFILES:.c++=.o) $(C++FILES:.c++=.o)
CXXO2=$(CXXO1:.cxx=.o)
CXXO3=$(CXXO2:.C=.o)
CXXOALL=$(CXXO3)
YO1=$(YFILES:.y=.o)
YO2=$(YO1:.yxx=.o)
YO3=$(YO2:.Y=.o)
YOALL=$(YO3)
LO1=$(LFILES:.l=.o)
LO2=$(LO1:.lxx=.o)
LO3=$(LO2:.L=.o)
LOALL=$(LO3)
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=*.[oue] 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)
