17c478bd9Sstevel@tonic-gate# 27c478bd9Sstevel@tonic-gate# CDDL HEADER START 37c478bd9Sstevel@tonic-gate# 47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 5f808c858Sraf# Common Development and Distribution License (the "License"). 6f808c858Sraf# You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate# 87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate# and limitations under the License. 127c478bd9Sstevel@tonic-gate# 137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate# 197c478bd9Sstevel@tonic-gate# CDDL HEADER END 207c478bd9Sstevel@tonic-gate# 21856f710cSAndy Fiddaman# Copyright 2019 OmniOS Community Edition (OmniOSce) Association. 22ee637354SGary Mills# Copyright 2015 Gary Mills 237b07063dSIgor Kozhukhov# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com> 240ae9a84fSAndrew Stormont# Copyright 2016 RackTop Systems. 25b83ec4edSjmcp# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 263eca6103SJohn Levon# Copyright 2019, Joyent, Inc. 277c478bd9Sstevel@tonic-gate# 287c478bd9Sstevel@tonic-gate# 297c478bd9Sstevel@tonic-gate# Definitions common to libraries. 307c478bd9Sstevel@tonic-gate# 317c478bd9Sstevel@tonic-gate# include global definitions; SRC should be defined in the shell. 327c478bd9Sstevel@tonic-gate# SRC is needed until RFE 1026993 is implemented. 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gateinclude $(SRC)/Makefile.master 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gateLORDER= lorder 377c478bd9Sstevel@tonic-gateTSORT= tsort 387c478bd9Sstevel@tonic-gate 39f808c858Sraf# 40f808c858Sraf# By default, we define the source directory for libraries to be 41f808c858Sraf# one level up from the ISA-specific directory, where the code is 42f808c858Sraf# actually built. Many libraries define a 'common' directory to 43f808c858Sraf# contain the source. These libraries must redefine SRCDIR as: 44f808c858Sraf# SRCDIR = ../common 45f808c858Sraf# Other variations are possible (../port, ../src, etc). 46f808c858Sraf# 47f808c858SrafSRCDIR = .. 48f808c858Sraf 49f808c858Sraf# 502a8d6ebaSRod Evans# We define MAPFILES here for the benefit of most libraries, those that 512a8d6ebaSRod Evans# follow the convention of having source files and other common files 522a8d6ebaSRod Evans# in the $(SRCDIR) directory. Libraries that do not follow this 532a8d6ebaSRod Evans# convention must define MAPFILES, or MAPFILEDIR for themselves. 54f808c858Sraf# Libraries that do follow this convention but that need supplemental 55f808c858Sraf# ISA-specific mapfiles can augment MAPFILES like this: 56f808c858Sraf# MAPFILES += mapfile-vers 57f808c858Sraf# 582a8d6ebaSRod EvansMAPFILEDIR = $(SRCDIR) 592a8d6ebaSRod EvansMAPFILES = $(MAPFILEDIR)/mapfile-vers 60f808c858Sraf 617c478bd9Sstevel@tonic-gate# 627c478bd9Sstevel@tonic-gate# If HDRDIR is left unset, then it's possible for the $(ROOTHDRDIR)/% 637c478bd9Sstevel@tonic-gate# install rule in lib/Makefile.targ to generate false matches if there 647c478bd9Sstevel@tonic-gate# are any common directory names between / and /usr/include (`xfn' is 657c478bd9Sstevel@tonic-gate# one common example). To prevent this, we set HDRDIR to a directory 667c478bd9Sstevel@tonic-gate# name that will almost surely not exist on the build machine. 677c478bd9Sstevel@tonic-gate# 687c478bd9Sstevel@tonic-gateHDRDIR= /__nonexistent_directory__ 69f808c858Sraf 707c478bd9Sstevel@tonic-gate# 717c478bd9Sstevel@tonic-gate# We don't build archive (*.a) libraries by default anymore. 727c478bd9Sstevel@tonic-gate# If a component of the build needs to build an archive library 737c478bd9Sstevel@tonic-gate# for its own internal purposes, it can define LIBS for itself 747c478bd9Sstevel@tonic-gate# after including Makefile.lib, like this: 75856f710cSAndy Fiddaman# LIBS = $(LIBRARY) 767c478bd9Sstevel@tonic-gate# or: 77856f710cSAndy Fiddaman# LIBS = $(LIBRARYCCC) 787c478bd9Sstevel@tonic-gate# Archive libraries must not be installed in the proto area. 797c478bd9Sstevel@tonic-gate# 807c478bd9Sstevel@tonic-gateLIBS= 817c478bd9Sstevel@tonic-gateMACHLIBS= $(LIBS:%=$(MACH)/%) 827c478bd9Sstevel@tonic-gateMACHLIBS64= $(LIBS:%=$(MACH64)/%) 837c478bd9Sstevel@tonic-gateDYNLIB= $(LIBRARY:.a=.so$(VERS)) 847c478bd9Sstevel@tonic-gateDYNLIBPSR= $(LIBRARY:.a=_psr.so$(VERS)) 857c478bd9Sstevel@tonic-gateDYNLIBCCC= $(LIBRARYCCC:.a=.so$(VERS)) 867c478bd9Sstevel@tonic-gateLIBLINKS= $(LIBRARY:.a=.so) 877c478bd9Sstevel@tonic-gateLIBLINKSCCC= $(LIBRARYCCC:.a=.so) 887c478bd9Sstevel@tonic-gateLIBNAME= $(LIBRARY:lib%.a=%) 897c478bd9Sstevel@tonic-gateLIBLINKPATH= 907c478bd9Sstevel@tonic-gateLIBNULL= null.a 917c478bd9Sstevel@tonic-gateROOTHDRDIR= $(ROOT)/usr/include 927c478bd9Sstevel@tonic-gateROOTLIBDIR= $(ROOT)/usr/lib 937c478bd9Sstevel@tonic-gateROOTLIBDIR64= $(ROOT)/usr/lib/$(MACH64) 947c478bd9Sstevel@tonic-gateROOTFS_LIBDIR= $(ROOT)/lib 957c478bd9Sstevel@tonic-gateROOTFS_LIBDIR64= $(ROOT)/lib/$(MACH64) 967c478bd9Sstevel@tonic-gateROOTHDRS= $(HDRS:%=$(ROOTHDRDIR)/%) 977c478bd9Sstevel@tonic-gateHDRSRCS= $(HDRS:%=$(HDRDIR)/%) 987c478bd9Sstevel@tonic-gateCHECKHDRS= $(HDRSRCS:%.h=%.check) 997c478bd9Sstevel@tonic-gateROOTLIBS= $(LIBS:%=$(ROOTLIBDIR)/%) 1007c478bd9Sstevel@tonic-gateROOTLIBS64= $(LIBS:%=$(ROOTLIBDIR64)/%) 101ddb365bfSKlaus Ziegler# explicitly use usr/lib here instead of ROOTLIBDIR, so that pc files always 102ddb365bfSKlaus Ziegler# end up under /usr/lib, even if a library includes lib/Makefile.rootfs 103ddb365bfSKlaus ZieglerROOTLIBPCDIR= $(ROOT)/usr/lib/pkgconfig 104ddb365bfSKlaus ZieglerROOTLIBPCDIR64= $(ROOT)/usr/lib/$(MACH64)/pkgconfig 105ddb365bfSKlaus ZieglerROOTLIBPC= $(PCFILE:%=$(ROOTLIBPCDIR)/%) 106ddb365bfSKlaus ZieglerROOTLIBPC64= $(PCFILE:%=$(ROOTLIBPCDIR64)/%) 107ddb365bfSKlaus ZieglerPCLIBDIR = lib 108ddb365bfSKlaus ZieglerPCLIBDIR64 = lib/$(MACH64) 1097c478bd9Sstevel@tonic-gateROOTFS_LIBS= $(DYNLIB:%=$(ROOTFS_LIBDIR)/%) 1107c478bd9Sstevel@tonic-gateROOTFS_LIBS64= $(DYNLIB:%=$(ROOTFS_LIBDIR64)/%) 1117c478bd9Sstevel@tonic-gateROOTLINKS= $(ROOTLIBDIR)/$(LIBLINKS) 1127c478bd9Sstevel@tonic-gateROOTLINKS64= $(ROOTLIBDIR64)/$(LIBLINKS) 1137c478bd9Sstevel@tonic-gateROOTFS_LINKS= $(ROOTFS_LIBDIR)/$(LIBLINKS) 1147c478bd9Sstevel@tonic-gateROOTFS_LINKS64= $(ROOTFS_LIBDIR64)/$(LIBLINKS) 1157c478bd9Sstevel@tonic-gateROOTLINKSCCC= $(ROOTLIBDIR)/$(LIBLINKSCCC) 1167c478bd9Sstevel@tonic-gateROOTLINKSCCC64= $(ROOTLIBDIR64)/$(LIBLINKSCCC) 1177c478bd9Sstevel@tonic-gateROOTFS_LINKSCCC= $(ROOTFS_LIBDIR)/$(LIBLINKSCCC) 1187c478bd9Sstevel@tonic-gateROOTFS_LINKSCCC64= $(ROOTFS_LIBDIR64)/$(LIBLINKSCCC) 1197c478bd9Sstevel@tonic-gate 120da2e3ebdSchin# Demo rules 121da2e3ebdSchinDEMOFILES= 122da2e3ebdSchinDEMOFILESRCDIR= common 123da2e3ebdSchinROOTDEMODIRBASE= __nonexistent_directory__ 124da2e3ebdSchinROOTDEMODIRS= 125da2e3ebdSchinROOTDEMOFILES= $(DEMOFILES:%=$(ROOTDEMODIRBASE)/%) 126da2e3ebdSchin$(ROOTDEMODIRS) := DIRMODE = 755 127da2e3ebdSchin 1287c478bd9Sstevel@tonic-gateARFLAGS= r 1297c478bd9Sstevel@tonic-gateSONAME= $(DYNLIB) 130cd61ae21SRichard Lowe 1317c478bd9Sstevel@tonic-gate# For most libraries, we should be able to resolve all symbols at link time, 1327c478bd9Sstevel@tonic-gate# either within the library or as dependencies, all text should be pure, and 1337c478bd9Sstevel@tonic-gate# combining relocations into one relocation table reduces startup costs. 1347c478bd9Sstevel@tonic-gate# All options are tunable to allow overload/omission from lower makefiles. 13573a801acSToomas SoomeHSONAME= -Wl,-h$(SONAME) 13667e3a03eSrieDYNFLAGS= $(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \ 13785f4cb87SRichard Lowe $(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%) $(MAPFILE.NED:%=-Wl,-M%) \ 1385801b0f0SToomas Soome $(LDCHECKS) 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gateLDLIBS= $(LDLIBS.lib) 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gateOBJS= $(OBJECTS:%=objs/%) 1437c478bd9Sstevel@tonic-gatePICS= $(OBJECTS:%=pics/%) 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate# Declare that all library .o's can all be made in parallel. 1467c478bd9Sstevel@tonic-gate# The DUMMY target is for those instances where OBJS and PICS 1477c478bd9Sstevel@tonic-gate# are empty (to avoid an unconditional .PARALLEL declaration). 1487c478bd9Sstevel@tonic-gate.PARALLEL: $(OBJS) $(PICS) DUMMY 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate# default value for "portable" source 1517c478bd9Sstevel@tonic-gateSRCS= $(OBJECTS:%.o=$(SRCDIR)/%.c) 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate# default build of an archive and a shared object, 1547c478bd9Sstevel@tonic-gate# overridden locally when extra processing is needed 1557c478bd9Sstevel@tonic-gateBUILD.AR= $(AR) $(ARFLAGS) $@ $(AROBJS) 156ee637354SGary MillsBUILD.SO= $(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \ 157ee637354SGary Mills $(PICS) $(EXTPICS) $(LDLIBS) 1580ae9a84fSAndrew StormontBUILD64.SO= $(CC64) $(CFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \ 159ee637354SGary Mills $(PICS) $(EXTPICS) $(LDLIBS) 160a5619348SRichard LoweBUILDCCC.SO= $(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \ 161a5619348SRichard Lowe $(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED) 1620ae9a84fSAndrew StormontBUILDCCC64.SO= $(CCC64) $(CCFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \ 1630ae9a84fSAndrew Stormont $(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED64) 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate# default dynamic library symlink 1667c478bd9Sstevel@tonic-gateINS.liblink= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@ 1677c478bd9Sstevel@tonic-gateINS.liblinkccc= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@ 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate# default 64-bit dynamic library symlink 1707c478bd9Sstevel@tonic-gateINS.liblink64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@ 1717c478bd9Sstevel@tonic-gateINS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@ 1727c478bd9Sstevel@tonic-gate 1735a0af816SRobert Mustacchi# 1745a0af816SRobert Mustacchi# Default to adding stack protection to all libraries. 1755a0af816SRobert Mustacchi# 1765a0af816SRobert MustacchiCFLAGS += $(CCSTACKPROTECT) 1775a0af816SRobert MustacchiCFLAGS64 += $(CCSTACKPROTECT) 1785a0af816SRobert MustacchiLDLIBS += $(LDSTACKPROTECT) 1795a0af816SRobert Mustacchi 1807c478bd9Sstevel@tonic-gate# 1817c478bd9Sstevel@tonic-gate# If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF 1827c478bd9Sstevel@tonic-gate# processing. We'd like to just conditionally append to POST_PROCESS_O and 1837c478bd9Sstevel@tonic-gate# POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to 1847c478bd9Sstevel@tonic-gate# sometimes get appended more than once, which will cause ctfconvert to fail. 1857c478bd9Sstevel@tonic-gate# So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always 1867c478bd9Sstevel@tonic-gate# appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF 1877c478bd9Sstevel@tonic-gate# processing should be done. 1887c478bd9Sstevel@tonic-gate# 1897c478bd9Sstevel@tonic-gateCTFCONVERT_POST = : 1907c478bd9Sstevel@tonic-gateCTFMERGE_POST = : 1917c478bd9Sstevel@tonic-gatePOST_PROCESS_O += ; $(CTFCONVERT_POST) 1927c478bd9Sstevel@tonic-gatePOST_PROCESS_SO += ; $(CTFMERGE_POST) 1937c478bd9Sstevel@tonic-gate 194d69cdb36SRichard LoweCTFMERGE_LIB = $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS) 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate# conditional assignments 1977c478bd9Sstevel@tonic-gate 198*d17be682SRichard Lowe$(PICS) := sparc_CFLAGS += $(sparc_C_PICFLAGS) 199*d17be682SRichard Lowe$(PICS) := sparcv9_CFLAGS += $(sparcv9_C_PICFLAGS) 2007c478bd9Sstevel@tonic-gate$(PICS) := i386_CFLAGS += $(i386_C_PICFLAGS) 2017c478bd9Sstevel@tonic-gate$(PICS) := amd64_CFLAGS += $(amd64_C_PICFLAGS) 2027c478bd9Sstevel@tonic-gate$(PICS) := CCFLAGS += $(CC_PICFLAGS) 2037c478bd9Sstevel@tonic-gate$(PICS) := CPPFLAGS += -DPIC -D_REENTRANT 204*d17be682SRichard Lowe$(PICS) := sparcv9_CCFLAGS += $(sparcv9_CC_PICFLAGS) 2057c478bd9Sstevel@tonic-gate$(PICS) := amd64_CCFLAGS += $(amd64_CC_PICFLAGS) 2067c478bd9Sstevel@tonic-gate$(PICS) := CFLAGS += $(CTF_FLAGS) 2077c478bd9Sstevel@tonic-gate$(PICS) := CFLAGS64 += $(CTF_FLAGS) 2087c478bd9Sstevel@tonic-gate$(PICS) := CTFCONVERT_POST = $(CTFCONVERT_O) 2097c478bd9Sstevel@tonic-gate$(DYNLIB) := CTFMERGE_POST = $(CTFMERGE_LIB) 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate$(LIBRARY):= AROBJS = $(OBJS) 2127c478bd9Sstevel@tonic-gate$(LIBRARY):= DIR = objs 2137c478bd9Sstevel@tonic-gate$(DYNLIB):= DIR = pics 2147c478bd9Sstevel@tonic-gate$(DYNLIBCCC):= DIR = pics 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gateSONAMECCC= $(DYNLIBCCC) 21773a801acSToomas SoomeHSONAMECCC= -Wl,-h$(SONAMECCC) 2187c478bd9Sstevel@tonic-gate# 2197c478bd9Sstevel@tonic-gate# Keep in sync with the standard DYNFLAGS 2207c478bd9Sstevel@tonic-gate# 22167e3a03eSrie$(DYNLIBCCC):= DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \ 22285f4cb87SRichard Lowe $(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%) $(MAPFILE.NED:%=-Wl,-M%) \ 223f6acbf7cSrie $(BDIRECT) $(NORUNPATH) 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate 226856f710cSAndy Fiddaman# build rule for "portable" source 2277c478bd9Sstevel@tonic-gateobjs/%.o pics/%.o: %.c 2287c478bd9Sstevel@tonic-gate $(COMPILE.c) -o $@ $< 2297c478bd9Sstevel@tonic-gate $(POST_PROCESS_O) 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gateobjs/%.o pics/%.o: %.cc 2327c478bd9Sstevel@tonic-gate $(COMPILE.cc) -o $@ $< 2333eca6103SJohn Levon $(POST_PROCESS_CC_O) 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate.PRECIOUS: $(LIBS) 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate# Define the majority text domain in this directory. 2387c478bd9Sstevel@tonic-gateTEXT_DOMAIN= SUNW_OST_OSLIB 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate# 241f808c858Sraf# Target Architecture 2427c478bd9Sstevel@tonic-gate# 243f808c858SrafTARGETMACH= $(MACH) 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate# 2467c478bd9Sstevel@tonic-gate# Allow people to define their own clobber rules. Normal makefiles 2477c478bd9Sstevel@tonic-gate# shouldn't override this - they should override $(CLOBBERFILES) instead. 2487c478bd9Sstevel@tonic-gate# 249ddb365bfSKlaus ZieglerCLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES) $(PCFILE) 250bc1f688bSRobert Mustacchi 251bc1f688bSRobert Mustacchi# 252bc1f688bSRobert Mustacchi# Define the default ctfdiff invocation used to check a list of types 253bc1f688bSRobert Mustacchi# supplied by a user of a library. The goal is to validate that a given 254bc1f688bSRobert Mustacchi# series of types is the same in both a 32-bit and 64-bit artifact. This 255bc1f688bSRobert Mustacchi# is only defined if we have a 64-bit build to do. 256bc1f688bSRobert Mustacchi# 257bc1f688bSRobert MustacchiTYPECHECK_LIB32 = $(TYPECHECK_LIB:%=$(MACH)/%) 258bc1f688bSRobert MustacchiTYPECHECK_LIB64 = $(TYPECHECK_LIB:%=$(MACH64)/%) 259bc1f688bSRobert MustacchiTYPECHECK_LIST= $(TYPELIST:%=-T %) 260cd61ae21SRichard Lowe$(BUILD64)TYPECHECK.lib = $(CTFDIFF) -t -I $(TYPECHECK_LIST) \ 261cd61ae21SRichard Lowe $(TYPECHECK_LIB32) $(TYPECHECK_LIB64) 262bc1f688bSRobert MustacchiTYPECHECK = $(TYPECHECK_LIB:%=%.typecheck) 263cd61ae21SRichard Lowe 264cd61ae21SRichard Lowe# Links we need to create for compatibility 265cd61ae21SRichard LoweCOMPATLINKS= 266cd61ae21SRichard LoweCOMPATLINKS64= 267cd61ae21SRichard LoweROOTCOMPATLINKS= $(COMPATLINKS:%=$(ROOT)/%) 268cd61ae21SRichard LoweROOTCOMPATLINKS64= $(COMPATLINKS64:%=$(ROOT)/%) 269cd61ae21SRichard Lowe 270cd61ae21SRichard Lowe# So if someone doesn't set the target-specific variable they get a clue what 271cd61ae21SRichard Lowe# went wrong. 272cd61ae21SRichard LoweCOMPATLINKTARGET= /__you_didnt_use_COMPATLINKS_properly__ 273