xref: /illumos-gate/usr/src/lib/Makefile.lib (revision b70bf3ee79d81df3ccc36e553e0ff11049a2b51a)
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 2016 RackTop Systems.
25# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
26# Copyright 2019, Joyent, Inc.
27#
28#
29# Definitions common to libraries.
30#
31# include global definitions; SRC should be defined in the shell.
32# SRC is needed until RFE 1026993 is implemented.
33
34include		$(SRC)/Makefile.master
35
36LORDER=		lorder
37TSORT=		tsort
38
39#
40# By default, we define the source directory for libraries to be
41# one level up from the ISA-specific directory, where the code is
42# actually built.  Many libraries define a 'common' directory to
43# contain the source.  These libraries must redefine SRCDIR as:
44#	SRCDIR = ../common
45# Other variations are possible (../port, ../src, etc).
46#
47SRCDIR =	..
48
49#
50# We define MAPFILES here for the benefit of most libraries, those that
51# follow the convention of having source files and other common files
52# in the $(SRCDIR) directory.  Libraries that do not follow this
53# convention must define MAPFILES, or MAPFILEDIR for themselves.
54# Libraries that do follow this convention but that need supplemental
55# ISA-specific mapfiles can augment MAPFILES like this:
56#	MAPFILES += mapfile-vers
57#
58MAPFILEDIR =	$(SRCDIR)
59MAPFILES =	$(MAPFILEDIR)/mapfile-vers
60
61#
62# If HDRDIR is left unset, then it's possible for the $(ROOTHDRDIR)/%
63# install rule in lib/Makefile.targ to generate false matches if there
64# are any common directory names between / and /usr/include (`xfn' is
65# one common example).  To prevent this, we set HDRDIR to a directory
66# name that will almost surely not exist on the build machine.
67#
68HDRDIR=		/__nonexistent_directory__
69
70#
71# We don't build archive (*.a) libraries by default anymore.
72# If a component of the build needs to build an archive library
73# for its own internal purposes, it can define LIBS for itself
74# after including Makefile.lib, like this:
75#	LIBS = $(LIBRARY)
76# or:
77#	LIBS = $(LIBRARYCCC)
78# Archive libraries must not be installed in the proto area.
79#
80LIBS=
81MACHLIBS=	$(LIBS:%=$(MACH)/%)
82MACHLIBS64=	$(LIBS:%=$(MACH64)/%)
83DYNLIB=		$(LIBRARY:.a=.so$(VERS))
84DYNLIBPSR=	$(LIBRARY:.a=_psr.so$(VERS))
85DYNLIBCCC=	$(LIBRARYCCC:.a=.so$(VERS))
86LIBLINKS=	$(LIBRARY:.a=.so)
87LIBLINKSCCC=	$(LIBRARYCCC:.a=.so)
88LIBNAME=	$(LIBRARY:lib%.a=%)
89LIBLINKPATH=
90LIBNULL=	null.a
91ROOTHDRDIR=	$(ROOT)/usr/include
92ROOTLIBDIR=	$(ROOT)/usr/lib
93ROOTLIBDIR64=	$(ROOT)/usr/lib/$(MACH64)
94ROOTFS_LIBDIR=	$(ROOT)/lib
95ROOTFS_LIBDIR64=	$(ROOT)/lib/$(MACH64)
96ROOTHDRS=	$(HDRS:%=$(ROOTHDRDIR)/%)
97HDRSRCS=	$(HDRS:%=$(HDRDIR)/%)
98CHECKHDRS=	$(HDRSRCS:%.h=%.check)
99ROOTLIBS=	$(LIBS:%=$(ROOTLIBDIR)/%)
100ROOTLIBS64=	$(LIBS:%=$(ROOTLIBDIR64)/%)
101# explicitly use usr/lib here instead of ROOTLIBDIR, so that pc files always
102# end up under /usr/lib, even if a library includes lib/Makefile.rootfs
103ROOTLIBPCDIR=	$(ROOT)/usr/lib/pkgconfig
104ROOTLIBPCDIR64=	$(ROOT)/usr/lib/$(MACH64)/pkgconfig
105ROOTLIBPC=	$(PCFILE:%=$(ROOTLIBPCDIR)/%)
106ROOTLIBPC64=	$(PCFILE:%=$(ROOTLIBPCDIR64)/%)
107PCLIBDIR = lib
108PCLIBDIR64 = lib/$(MACH64)
109ROOTFS_LIBS=	$(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
110ROOTFS_LIBS64=	$(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
111ROOTLINKS=	$(ROOTLIBDIR)/$(LIBLINKS)
112ROOTLINKS64=	$(ROOTLIBDIR64)/$(LIBLINKS)
113ROOTFS_LINKS=	$(ROOTFS_LIBDIR)/$(LIBLINKS)
114ROOTFS_LINKS64=	$(ROOTFS_LIBDIR64)/$(LIBLINKS)
115ROOTLINKSCCC=	$(ROOTLIBDIR)/$(LIBLINKSCCC)
116ROOTLINKSCCC64=	$(ROOTLIBDIR64)/$(LIBLINKSCCC)
117ROOTFS_LINKSCCC=	$(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
118ROOTFS_LINKSCCC64=	$(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
119
120# Demo rules
121DEMOFILES=
122DEMOFILESRCDIR=		common
123ROOTDEMODIRBASE=	__nonexistent_directory__
124ROOTDEMODIRS=
125ROOTDEMOFILES=	$(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
126$(ROOTDEMODIRS) :=	DIRMODE =	755
127
128ARFLAGS=	r
129SONAME=		$(DYNLIB)
130
131# For most libraries, we should be able to resolve all symbols at link time,
132# either within the library or as dependencies, all text should be pure, and
133# combining relocations into one relocation table reduces startup costs.
134# All options are tunable to allow overload/omission from lower makefiles.
135HSONAME=	-Wl,-h$(SONAME)
136DYNFLAGS=	$(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
137		$(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%) $(MAPFILE.NED:%=-Wl,-M%) \
138		$(LDCHECKS)
139
140LDLIBS=		$(LDLIBS.lib)
141
142OBJS=		$(OBJECTS:%=objs/%)
143PICS=		$(OBJECTS:%=pics/%)
144
145# Declare that all library .o's can all be made in parallel.
146# The DUMMY target is for those instances where OBJS and PICS
147# are empty (to avoid an unconditional .PARALLEL declaration).
148.PARALLEL:	$(OBJS) $(PICS) DUMMY
149
150# default value for "portable" source
151SRCS=		$(OBJECTS:%.o=$(SRCDIR)/%.c)
152
153# default build of an archive and a shared object,
154# overridden locally when extra processing is needed
155BUILD.AR=	$(AR) $(ARFLAGS) $@ $(AROBJS)
156BUILD.SO=	$(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
157		$(PICS) $(EXTPICS) $(LDLIBS)
158BUILD64.SO=	$(CC64) $(CFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
159		$(PICS) $(EXTPICS) $(LDLIBS)
160BUILDCCC.SO=	$(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
161		$(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED)
162BUILDCCC64.SO=	$(CCC64) $(CCFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
163		$(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED64)
164
165# default dynamic library symlink
166INS.liblink=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
167INS.liblinkccc=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
168
169# default 64-bit dynamic library symlink
170INS.liblink64=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
171INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
172
173#
174# Default to adding stack protection to all libraries.
175#
176CFLAGS +=	$(CCSTACKPROTECT)
177CFLAGS64 +=	$(CCSTACKPROTECT)
178LDLIBS +=	$(LDSTACKPROTECT)
179
180#
181# If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
182# processing.  We'd like to just conditionally append to POST_PROCESS_O and
183# POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
184# sometimes get appended more than once, which will cause ctfconvert to fail.
185# So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
186# appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
187# processing should be done.
188#
189CTFCONVERT_POST = :
190CTFMERGE_POST	= :
191POST_PROCESS_O += ; $(CTFCONVERT_POST)
192POST_PROCESS_SO += ; $(CTFMERGE_POST)
193
194CTFMERGE_LIB	= $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS)
195
196# conditional assignments
197
198$(PICS)  :=	sparc_CFLAGS += $(sparc_C_PICFLAGS)
199$(PICS)  :=	sparcv9_CFLAGS += $(sparcv9_C_PICFLAGS)
200$(PICS)  :=	i386_CFLAGS += $(i386_C_PICFLAGS)
201$(PICS)  :=	amd64_CFLAGS += $(amd64_C_PICFLAGS)
202$(PICS)  :=	CCFLAGS += $(CC_PICFLAGS)
203$(PICS)  :=	CPPFLAGS += -DPIC -D_REENTRANT
204$(PICS)  :=	sparcv9_CCFLAGS += $(sparcv9_CC_PICFLAGS)
205$(PICS)  :=	amd64_CCFLAGS += $(amd64_CC_PICFLAGS)
206$(PICS)  :=	CFLAGS += $(CTF_FLAGS)
207$(PICS)	 :=	CFLAGS64 += $(CTF_FLAGS)
208$(PICS)  :=	CTFCONVERT_POST = $(CTFCONVERT_O)
209$(DYNLIB) :=	CTFMERGE_POST = $(CTFMERGE_LIB)
210
211$(LIBRARY):=	AROBJS = $(OBJS)
212$(LIBRARY):=	DIR = objs
213$(DYNLIB):=	DIR = pics
214$(DYNLIBCCC):=	DIR = pics
215
216SONAMECCC=	$(DYNLIBCCC)
217HSONAMECCC=	-Wl,-h$(SONAMECCC)
218#
219# Keep in sync with the standard DYNFLAGS
220#
221$(DYNLIBCCC):=	DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
222		$(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%) $(MAPFILE.NED:%=-Wl,-M%) \
223		$(BDIRECT) $(NORUNPATH)
224
225
226# build rule for "portable" source
227objs/%.o pics/%.o: %.c
228	$(COMPILE.c) -o $@ $<
229	$(POST_PROCESS_O)
230
231objs/%.o pics/%.o: %.cc
232	$(COMPILE.cc) -o $@ $<
233	$(POST_PROCESS_CC_O)
234
235.PRECIOUS: $(LIBS)
236
237# Define the majority text domain in this directory.
238TEXT_DOMAIN= SUNW_OST_OSLIB
239
240#
241# Target Architecture
242#
243TARGETMACH=	$(MACH)
244
245#
246# Allow people to define their own clobber rules.  Normal makefiles
247# shouldn't override this - they should override $(CLOBBERFILES) instead.
248#
249CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES) $(PCFILE)
250
251#
252# Define the default ctfdiff invocation used to check a list of types
253# supplied by a user of a library. The goal is to validate that a given
254# series of types is the same in both a 32-bit and 64-bit artifact. This
255# is only defined if we have a 64-bit build to do.
256#
257TYPECHECK_LIB32 =		$(TYPECHECK_LIB:%=$(MACH)/%)
258TYPECHECK_LIB64 =		$(TYPECHECK_LIB:%=$(MACH64)/%)
259TYPECHECK_LIST=			$(TYPELIST:%=-T %)
260$(BUILD64)TYPECHECK.lib =	$(CTFDIFF) -t -I $(TYPECHECK_LIST) \
261	$(TYPECHECK_LIB32) $(TYPECHECK_LIB64)
262TYPECHECK =			$(TYPECHECK_LIB:%=%.typecheck)
263
264# Links we need to create for compatibility
265COMPATLINKS=
266COMPATLINKS64=
267ROOTCOMPATLINKS=	$(COMPATLINKS:%=$(ROOT)/%)
268ROOTCOMPATLINKS64=	$(COMPATLINKS64:%=$(ROOT)/%)
269
270# So if someone doesn't set the target-specific variable they get a clue what
271# went wrong.
272COMPATLINKTARGET=	/__you_didnt_use_COMPATLINKS_properly__
273