#ident "$Header: /d2/3.7/src/include/make/RCS/commondefs,v 1.1 89/03/27 16:12:32 root Exp $"
#
# 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.
#
COMMONRULES= $(ROOT)/usr/include/make/commonrules
COMMONTARGS= depend incdepend fluff tags clean clobber purge
PRODUCTDEFS= $(ROOT)/usr/include/make/$(PRODUCT)defs

#
# Fundamental product parameters, which determine the build environment.
# XXX this renders commondefs uncommon, and requires either (1) that the
# XXX developer always set PRODUCT, or (2) that there be a link named
# XXX 'defs' in /usr/include/make to the right productdefs file.
# XXX Alas, commondefs must include at least CC_CPUTYPE for cross-builds.
#
include $(PRODUCTDEFS)

#
# 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)/bin/ar
AS	= $(TOOLROOT)/bin/as
CC	= $(TOOLROOT)/bin/cc
ECHO	= $(TOOLROOT)/bin/echo
F77	= $(TOOLROOT)/bin/f77
LD	= $(TOOLROOT)/bin/ld
LEX	= $(TOOLROOT)/usr/bin/lex
PC	= $(TOOLROOT)/bin/pc
YACC	= $(TOOLROOT)/usr/bin/yacc
NM	= $(TOOLROOT)/bin/nm
SIZE	= $(TOOLROOT)/bin/size
STRIP	= $(TOOLROOT)/bin/strip
LORDER	= $(TOOLROOT)/usr/bin/lorder
M4	= $(TOOLROOT)/usr/bin/m4
SHELL	= $(TOOLROOT)/bin/sh
MAKESHELL= $(SHELL)
LINT	= $(TOOLROOT)/usr/bin/lint
RANLIB	= $(TOOLROOT)/bin/ranlib


#
# 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	= $(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.
#   - Until we find something in the IRIS that should not be optimized,
#     we put -O in GCOPTS.
#
VCFLAGS	= $(VCDEFS) $(VCINCS) $(VCOPTS)
LCFLAGS	= $(LCDEFS) $(LCINCS) $(LCOPTS)
GCFLAGS	= $(GCDEFS) $(GCINCS) $(GCOPTS)

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

#
# The -ZN 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.
#
# XXX The -Dident=undef is temporary until compilers understand #ident.
#
GCOPTS	= -Z$(CC_CPUTYPE) -O
GCDEFS	= -Dident=undef -D$(SYSTEM) -D$(CPUBOARD)
GCINCS	= -I$(INCLDIR) -ZN


#
# 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 any -ZR'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.
#
LDFLAGS	= $(LDOPTS) $(LDLIBS)

LDOPTS	= $(VLDOPTS) $(LLDOPTS) $(GLDOPTS)
LDLIBS	= $(VLDLIBS) $(LLDLIBS) $(GLDLIBS)

# XXX This assumes LDFLAGS is always given to CC, not LD.
GLDOPTS= -ZR "$(ROOT)"


#
# F77 flags are just like cc flags.
#
F77FLAGS= $(VF77FLAGS) $(LF77FLAGS) $(GF77FLAGS)

VF77FLAGS   = $(VF77DEFS) $(VF77INCS) $(VF77OPTS)
LF77FLAGS   = $(LF77DEFS) $(LF77INCS) $(LF77OPTS)
GF77FLAGS   = $(GF77DEFS) $(GF77INCS) $(GF77OPTS)

F77OPTS	= $(VF77OPTS) $(LF77OPTS) $(GF77OPTS)
F77DEFS	= $(VF77DEFS) $(LF77DEFS) $(GF77DEFS)
F77INCS	= $(VF77INCS) $(LF77INCS) $(GF77INCS)

GF77OPTS= $(GCOPTS)
GF77DEFS= $(GCDEFS)
GF77INCS= $(GCINCS)


#
# Pc flags are just like cc flags.
#
PCFLAGS = $(VPCFLAGS) $(LPCFLAGS) $(GPCFLAGS)

VPCFLAGS= $(VPCDEFS) $(VPCINCS) $(VPCOPTS)
LPCFLAGS= $(LPCDEFS) $(LPCINCS) $(LPCOPTS)
GPCFLAGS= $(GPCDEFS) $(GPCINCS) $(GPCOPTS)

PCOPTS	= $(VPCOPTS) $(LPCOPTS) $(GPCOPTS) $(GLDOPTS)
PCDEFS	= $(VPCDEFS) $(LPCDEFS) $(GPCDEFS)
PCINCS	= $(VPCINCS) $(LPCINCS) $(GPCINCS)

GPCOPTS= $(GCOPTS)
GPCDEFS= -Dsgi -D$(SYSTEM) -D$(CPUBOARD)
GPCINCS= $(GCINCS)


#
# C tags extractor, defined here so that commonrules users may redefine and
# still use the tags: rule from commonrules.
#
CTAGS	= $(TOOLROOT)/usr/bin/ctags

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

MKDEPEND= $(TOOLROOT)/usr/bin/mkdepend -c "$(CCF)" $(MKDEPFLAGS)
MKDEPFLAGS= $(VMKDEPFLAGS) $(LMKDEPFLAGS) $(GMKDEPFLAGS)
GMKDEPFLAGS= -e 's: $(INCLDIR)/: $$(INCLDIR)/:' -e 's: $(ROOT)/: $$(ROOT)/:'

#
# MKDEPFILE is the name of the dependency database.  Currently, its
# default value is $(MAKEFILE), which make sets to the make script's name.
# Users may redefine it before including commonrules in order to put
# dependencies in an include file (we plan to do this globally soon).
#
MKDEPFILE= $(MAKEFILE)

#
# Various directory shorthands defined, mainly for make depend.
#
INCLDIR	= $(ROOT)/usr/include


#
# Convenient command macros that include the flags macros.
#
# You should always invoke make in makefiles via $(MAKEF), so that the
# variable commonflags get passed to sub-makes.  Note that MAKEF does
# *not* include $(MAKEFLAGS), since make magically passes its flags
# through the environment.
#
# Never use just #{CCF}, etc. in rules that link executables; LDFLAGS
# needs to be there as well.
#
MAKEF	= $(MAKE) VCFLAGS="$(VCFLAGS)" VFFLAGS="$(VFFLAGS)" \
	    VPFLAGS="$(VPFLAGS)" VMKDEPFLAGS="$(VMKDEPFLAGS)"
ASF	= $(AS) $(ASFLAGS)
CCF	= $(CC) $(CFLAGS)
F77F	= $(F77) $(FFLAGS)
LDF	= $(LD) $(LDFLAGS)
LEXF	= $(LEX) $(LFLAGS)
PCF	= $(PC) $(PFLAGS)
YACCF	= $(YACC) $(YFLAGS)
