xref: /illumos-gate/usr/src/lib/Makefile.lib (revision a0ee54468d6e6b136d1ca470a03bb44165c66e6e)
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)/%)
101ROOTFS_LIBS=	$(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
102ROOTFS_LIBS64=	$(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
103ROOTLINKS=	$(ROOTLIBDIR)/$(LIBLINKS)
104ROOTLINKS64=	$(ROOTLIBDIR64)/$(LIBLINKS)
105ROOTFS_LINKS=	$(ROOTFS_LIBDIR)/$(LIBLINKS)
106ROOTFS_LINKS64=	$(ROOTFS_LIBDIR64)/$(LIBLINKS)
107ROOTLINKSCCC=	$(ROOTLIBDIR)/$(LIBLINKSCCC)
108ROOTLINKSCCC64=	$(ROOTLIBDIR64)/$(LIBLINKSCCC)
109ROOTFS_LINKSCCC=	$(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
110ROOTFS_LINKSCCC64=	$(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
111
112# Demo rules
113DEMOFILES=
114DEMOFILESRCDIR=		common
115ROOTDEMODIRBASE=	__nonexistent_directory__
116ROOTDEMODIRS=
117ROOTDEMOFILES=	$(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
118$(ROOTDEMODIRS) :=	DIRMODE =	755
119
120ARFLAGS=	r
121SONAME=		$(DYNLIB)
122# For most libraries, we should be able to resolve all symbols at link time,
123# either within the library or as dependencies, all text should be pure, and
124# combining relocations into one relocation table reduces startup costs.
125# All options are tunable to allow overload/omission from lower makefiles.
126
127
128HSONAME=	-h$(SONAME)
129DYNFLAGS=	$(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
130		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%)
131
132LDLIBS=		$(LDLIBS.lib)
133
134OBJS=		$(OBJECTS:%=objs/%)
135PICS=		$(OBJECTS:%=pics/%)
136
137# Declare that all library .o's can all be made in parallel.
138# The DUMMY target is for those instances where OBJS and PICS
139# are empty (to avoid an unconditional .PARALLEL declaration).
140.PARALLEL:	$(OBJS) $(PICS) DUMMY
141
142# default value for "portable" source
143SRCS=		$(OBJECTS:%.o=$(SRCDIR)/%.c)
144
145# default build of an archive and a shared object,
146# overridden locally when extra processing is needed
147BUILD.AR=	$(AR) $(ARFLAGS) $@ $(AROBJS)
148BUILD.SO=	$(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
149		$(PICS) $(EXTPICS) $(LDLIBS)
150BUILD64.SO=	$(CC64) $(CFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
151		$(PICS) $(EXTPICS) -L $(ROOTLIBDIR64) $(LDLIBS)
152BUILDCCC.SO=	$(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
153		$(PICS) $(EXTPICS) $(LDLIBS)
154BUILDCCC64.SO=	$(CCC64) $(CCFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
155		$(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED64)
156
157# default dynamic library symlink
158INS.liblink=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
159INS.liblinkccc=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
160
161# default 64-bit dynamic library symlink
162INS.liblink64=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
163INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
164
165#
166# If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
167# processing.  We'd like to just conditionally append to POST_PROCESS_O and
168# POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
169# sometimes get appended more than once, which will cause ctfconvert to fail.
170# So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
171# appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
172# processing should be done.
173#
174CTFCONVERT_POST = :
175CTFMERGE_POST	= :
176POST_PROCESS_O += ; $(CTFCONVERT_POST)
177POST_PROCESS_SO += ; $(CTFMERGE_POST)
178
179CTFMERGE_LIB	= $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS)
180
181# conditional assignments
182
183$(OBJS)  :=	sparc_CFLAGS += -xregs=no%appl
184
185$(PICS)  :=	sparc_CFLAGS += -xregs=no%appl $(sparc_C_PICFLAGS)
186$(PICS)  :=	sparcv9_CFLAGS += -xregs=no%appl $(sparcv9_C_PICFLAGS)
187$(PICS)  :=	i386_CFLAGS += $(i386_C_PICFLAGS)
188$(PICS)  :=	amd64_CFLAGS += $(amd64_C_PICFLAGS)
189$(PICS)  :=	CCFLAGS += $(CC_PICFLAGS)
190$(PICS)  :=	CPPFLAGS += -DPIC -D_REENTRANT
191$(PICS)  :=	sparcv9_CCFLAGS += -xregs=no%appl $(sparcv9_CC_PICFLAGS)
192$(PICS)  :=	amd64_CCFLAGS += $(amd64_CC_PICFLAGS)
193$(PICS)  :=	CFLAGS += $(CTF_FLAGS)
194$(PICS)	 :=	CFLAGS64 += $(CTF_FLAGS)
195$(PICS)  :=	CTFCONVERT_POST = $(CTFCONVERT_O)
196$(DYNLIB) :=	CTFMERGE_POST = $(CTFMERGE_LIB)
197
198$(LIBRARY):=	AROBJS = $(OBJS)
199$(LIBRARY):=	DIR = objs
200$(DYNLIB):=	DIR = pics
201$(DYNLIBCCC):=	DIR = pics
202
203SONAMECCC=	$(DYNLIBCCC)
204HSONAMECCC=	-h $(SONAMECCC)
205#
206# Keep in sync with the standard DYNFLAGS
207#
208$(DYNLIBCCC):=	DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
209		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%) \
210		$(BDIRECT) $(NORUNPATH)
211
212
213# build rule for "portable" source
214objs/%.o pics/%.o: %.c
215	$(COMPILE.c) -o $@ $<
216	$(POST_PROCESS_O)
217
218objs/%.o pics/%.o: %.cc
219	$(COMPILE.cc) -o $@ $<
220	$(POST_PROCESS_CC_O)
221
222.PRECIOUS: $(LIBS)
223
224# Define the majority text domain in this directory.
225TEXT_DOMAIN= SUNW_OST_OSLIB
226
227#
228# Target Architecture
229#
230TARGETMACH=	$(MACH)
231
232#
233# Allow people to define their own clobber rules.  Normal makefiles
234# shouldn't override this - they should override $(CLOBBERFILES) instead.
235#
236CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES)
237
238#
239# Define the default ctfdiff invocation used to check a list of types
240# supplied by a user of a library. The goal is to validate that a given
241# series of types is the same in both a 32-bit and 64-bit artifact. This
242# is only defined if we have a 64-bit build to do.
243#
244TYPECHECK_LIB32 =		$(TYPECHECK_LIB:%=$(MACH)/%)
245TYPECHECK_LIB64 =		$(TYPECHECK_LIB:%=$(MACH64)/%)
246TYPECHECK_LIST=			$(TYPELIST:%=-T %)
247$(BUILD64)TYPECHECK.lib =	$(CTFDIFF) -t -I $(TYPECHECK_LIST) $(TYPECHECK_LIB32) $(TYPECHECK_LIB64)
248TYPECHECK =			$(TYPECHECK_LIB:%=%.typecheck)
249