1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 # Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
  22 # Copyright 2015 Gary Mills
  23 # Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
  24 # Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
  25 # Copyright 2019, Joyent, Inc.
  26 #
  27 #
  28 # Definitions common to libraries.
  29 #
  30 # include global definitions; SRC should be defined in the shell.
  31 # SRC is needed until RFE 1026993 is implemented.
  32 
  33 include         $(SRC)/Makefile.master
  34 
  35 LORDER=         lorder
  36 TSORT=          tsort
  37 
  38 #
  39 # By default, we define the source directory for libraries to be
  40 # one level up from the ISA-specific directory, where the code is
  41 # actually built.  Many libraries define a 'common' directory to
  42 # contain the source.  These libraries must redefine SRCDIR as:
  43 #       SRCDIR = ../common
  44 # Other variations are possible (../port, ../src, etc).
  45 #
  46 SRCDIR =        ..
  47 
  48 #
  49 # We define MAPFILES here for the benefit of most libraries, those that
  50 # follow the convention of having source files and other common files
  51 # in the $(SRCDIR) directory.  Libraries that do not follow this
  52 # convention must define MAPFILES, or MAPFILEDIR for themselves.
  53 # Libraries that do follow this convention but that need supplemental
  54 # ISA-specific mapfiles can augment MAPFILES like this:
  55 #       MAPFILES += mapfile-vers
  56 #
  57 MAPFILEDIR =    $(SRCDIR)
  58 MAPFILES =      $(MAPFILEDIR)/mapfile-vers
  59 
  60 #
  61 # If HDRDIR is left unset, then it's possible for the $(ROOTHDRDIR)/%
  62 # install rule in lib/Makefile.targ to generate false matches if there
  63 # are any common directory names between / and /usr/include (`xfn' is
  64 # one common example).  To prevent this, we set HDRDIR to a directory
  65 # name that will almost surely not exist on the build machine.
  66 #
  67 HDRDIR=         /__nonexistent_directory__
  68 
  69 #
  70 # We don't build archive (*.a) libraries by default anymore.
  71 # If a component of the build needs to build an archive library
  72 # for its own internal purposes, it can define LIBS for itself
  73 # after including Makefile.lib, like this:
  74 #       LIBS = $(LIBRARY)
  75 # or:
  76 #       LIBS = $(LIBRARYCCC)
  77 # Archive libraries must not be installed in the proto area.
  78 #
  79 LIBS=
  80 MACHLIBS=       $(LIBS:%=$(MACH)/%)
  81 MACHLIBS64=     $(LIBS:%=$(MACH64)/%)
  82 DYNLIB=         $(LIBRARY:.a=.so$(VERS))
  83 DYNLIBPSR=      $(LIBRARY:.a=_psr.so$(VERS))
  84 DYNLIBCCC=      $(LIBRARYCCC:.a=.so$(VERS))
  85 LIBLINKS=       $(LIBRARY:.a=.so)
  86 LIBLINKSCCC=    $(LIBRARYCCC:.a=.so)
  87 LIBNAME=        $(LIBRARY:lib%.a=%)
  88 LIBLINKPATH=
  89 LIBNULL=        null.a
  90 ROOTHDRDIR=     $(ROOT)/usr/include
  91 ROOTLIBDIR=     $(ROOT)/usr/lib
  92 ROOTLIBDIR64=   $(ROOT)/usr/lib/$(MACH64)
  93 ROOTFS_LIBDIR=  $(ROOT)/lib
  94 ROOTFS_LIBDIR64=        $(ROOT)/lib/$(MACH64)
  95 ROOTHDRS=       $(HDRS:%=$(ROOTHDRDIR)/%)
  96 HDRSRCS=        $(HDRS:%=$(HDRDIR)/%)
  97 CHECKHDRS=      $(HDRSRCS:%.h=%.check)
  98 ROOTLIBS=       $(LIBS:%=$(ROOTLIBDIR)/%)
  99 ROOTLIBS64=     $(LIBS:%=$(ROOTLIBDIR64)/%)
 100 ROOTFS_LIBS=    $(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
 101 ROOTFS_LIBS64=  $(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
 102 ROOTLINKS=      $(ROOTLIBDIR)/$(LIBLINKS)
 103 ROOTLINKS64=    $(ROOTLIBDIR64)/$(LIBLINKS)
 104 ROOTFS_LINKS=   $(ROOTFS_LIBDIR)/$(LIBLINKS)
 105 ROOTFS_LINKS64= $(ROOTFS_LIBDIR64)/$(LIBLINKS)
 106 ROOTLINKSCCC=   $(ROOTLIBDIR)/$(LIBLINKSCCC)
 107 ROOTLINKSCCC64= $(ROOTLIBDIR64)/$(LIBLINKSCCC)
 108 ROOTFS_LINKSCCC=        $(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
 109 ROOTFS_LINKSCCC64=      $(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
 110 
 111 # Demo rules
 112 DEMOFILES=
 113 DEMOFILESRCDIR=         common
 114 ROOTDEMODIRBASE=        __nonexistent_directory__
 115 ROOTDEMODIRS=
 116 ROOTDEMOFILES=  $(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
 117 $(ROOTDEMODIRS) :=      DIRMODE =       755
 118 
 119 ARFLAGS=        r
 120 SONAME=         $(DYNLIB)
 121 # For most libraries, we should be able to resolve all symbols at link time,
 122 # either within the library or as dependencies, all text should be pure, and
 123 # combining relocations into one relocation table reduces startup costs.
 124 # All options are tunable to allow overload/omission from lower makefiles.
 125 
 126 
 127 HSONAME=        -h$(SONAME)
 128 DYNFLAGS=       $(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
 129                 $(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%)
 130 
 131 LDLIBS=         $(LDLIBS.lib)
 132 
 133 OBJS=           $(OBJECTS:%=objs/%)
 134 PICS=           $(OBJECTS:%=pics/%)
 135 
 136 # Declare that all library .o's can all be made in parallel.
 137 # The DUMMY target is for those instances where OBJS and PICS
 138 # are empty (to avoid an unconditional .PARALLEL declaration).
 139 .PARALLEL:      $(OBJS) $(PICS) DUMMY
 140 
 141 # default value for "portable" source
 142 SRCS=           $(OBJECTS:%.o=$(SRCDIR)/%.c)
 143 
 144 # default build of an archive and a shared object,
 145 # overridden locally when extra processing is needed
 146 BUILD.AR=       $(AR) $(ARFLAGS) $@ $(AROBJS)
 147 BUILD.SO=       $(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
 148                 $(PICS) $(EXTPICS) $(LDLIBS)
 149 BUILDCCC.SO=    $(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
 150                 $(PICS) $(EXTPICS) $(LDLIBS)
 151 
 152 # default dynamic library symlink
 153 INS.liblink=    -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
 154 INS.liblinkccc= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
 155 
 156 # default 64-bit dynamic library symlink
 157 INS.liblink64=  -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
 158 INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
 159 
 160 #
 161 # If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
 162 # processing.  We'd like to just conditionally append to POST_PROCESS_O and
 163 # POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
 164 # sometimes get appended more than once, which will cause ctfconvert to fail.
 165 # So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
 166 # appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
 167 # processing should be done.
 168 #
 169 CTFCONVERT_POST = :
 170 CTFMERGE_POST   = :
 171 POST_PROCESS_O += ; $(CTFCONVERT_POST)
 172 POST_PROCESS_SO += ; $(CTFMERGE_POST)
 173 
 174 CTFMERGE_LIB    = $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS)
 175 
 176 # conditional assignments
 177 
 178 $(OBJS)  :=     sparc_CFLAGS += -xregs=no%appl
 179 
 180 $(PICS)  :=     sparc_CFLAGS += -xregs=no%appl $(sparc_C_PICFLAGS)
 181 $(PICS)  :=     sparcv9_CFLAGS += -xregs=no%appl $(sparcv9_C_PICFLAGS)
 182 $(PICS)  :=     i386_CFLAGS += $(i386_C_PICFLAGS)
 183 $(PICS)  :=     amd64_CFLAGS += $(amd64_C_PICFLAGS)
 184 $(PICS)  :=     CCFLAGS += $(CC_PICFLAGS)
 185 $(PICS)  :=     CPPFLAGS += -DPIC -D_REENTRANT
 186 $(PICS)  :=     sparcv9_CCFLAGS += -xregs=no%appl $(sparcv9_CC_PICFLAGS)
 187 $(PICS)  :=     amd64_CCFLAGS += $(amd64_CC_PICFLAGS)
 188 $(PICS)  :=     CFLAGS += $(CTF_FLAGS)
 189 $(PICS)  :=     CFLAGS64 += $(CTF_FLAGS)
 190 $(PICS)  :=     CTFCONVERT_POST = $(CTFCONVERT_O)
 191 $(DYNLIB) :=    CTFMERGE_POST = $(CTFMERGE_LIB)
 192 
 193 $(LIBRARY):=    AROBJS = $(OBJS)
 194 $(LIBRARY):=    DIR = objs
 195 $(DYNLIB):=     DIR = pics
 196 $(DYNLIBCCC):=  DIR = pics
 197 
 198 SONAMECCC=      $(DYNLIBCCC)
 199 HSONAMECCC=     -h $(SONAMECCC)
 200 #
 201 # Keep in sync with the standard DYNFLAGS
 202 #
 203 $(DYNLIBCCC):=  DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
 204                 $(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%) \
 205                 $(BDIRECT) $(NORUNPATH)
 206 
 207 
 208 # build rule for "portable" source
 209 objs/%.o pics/%.o: %.c
 210         $(COMPILE.c) -o $@ $<
 211         $(POST_PROCESS_O)
 212 
 213 objs/%.o pics/%.o: %.cc
 214         $(COMPILE.cc) -o $@ $<
 215         $(POST_PROCESS_CC_O)
 216 
 217 .PRECIOUS: $(LIBS)
 218 
 219 # Define the majority text domain in this directory.
 220 TEXT_DOMAIN= SUNW_OST_OSLIB
 221 
 222 #
 223 # Target Architecture
 224 #
 225 TARGETMACH=     $(MACH)
 226 
 227 #
 228 # Allow people to define their own clobber rules.  Normal makefiles
 229 # shouldn't override this - they should override $(CLOBBERFILES) instead.
 230 #
 231 CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES)
 232 
 233 #
 234 # Define the default ctfdiff invocation used to check a list of types
 235 # supplied by a user of a library. The goal is to validate that a given
 236 # series of types is the same in both a 32-bit and 64-bit artifact. This
 237 # is only defined if we have a 64-bit build to do.
 238 #
 239 TYPECHECK_LIB32 =               $(TYPECHECK_LIB:%=$(MACH)/%)
 240 TYPECHECK_LIB64 =               $(TYPECHECK_LIB:%=$(MACH64)/%)
 241 TYPECHECK_LIST=                 $(TYPELIST:%=-T %)
 242 $(BUILD64)TYPECHECK.lib =       $(CTFDIFF) -t -I $(TYPECHECK_LIST) $(TYPECHECK_LIB32) $(TYPECHECK_LIB64)
 243 TYPECHECK =                     $(TYPECHECK_LIB:%=%.typecheck)