xref: /titanic_52/usr/src/lib/Makefile.lib (revision 941d8a6ea975201934fe21514a2bad8cbd907495)
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 2015 Gary Mills
22# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
23# Copyright 2016 RackTop Systems.
24# Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
25# Copyright (c) 2015, 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
33include		$(SRC)/Makefile.master
34
35LORDER=		lorder
36TSORT=		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#
46SRCDIR =	..
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#
57MAPFILEDIR =	$(SRCDIR)
58MAPFILES =	$(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#
67HDRDIR=		/__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#
79LIBS=
80MACHLIBS=	$(LIBS:%=$(MACH)/%)
81MACHLIBS64=	$(LIBS:%=$(MACH64)/%)
82DYNLIB=		$(LIBRARY:.a=.so$(VERS))
83DYNLIBPSR=	$(LIBRARY:.a=_psr.so$(VERS))
84DYNLIBCCC=	$(LIBRARYCCC:.a=.so$(VERS))
85LIBLINKS=	$(LIBRARY:.a=.so)
86LIBLINKSCCC=	$(LIBRARYCCC:.a=.so)
87LIBNAME=	$(LIBRARY:lib%.a=%)
88LIBLINKPATH=
89LIBNULL=	null.a
90ROOTHDRDIR=	$(ROOT)/usr/include
91ROOTLIBDIR=	$(ROOT)/usr/lib
92ROOTLIBDIR64=	$(ROOT)/usr/lib/$(MACH64)
93ROOTFS_LIBDIR=	$(ROOT)/lib
94ROOTFS_LIBDIR64=	$(ROOT)/lib/$(MACH64)
95ROOTLINTDIR=	$(ROOTLIBDIR)
96ROOTFS_LINTDIR=	$(ROOTFS_LIBDIR)
97ROOTFS_LINTDIR64=	$(ROOTFS_LIBDIR64)
98ROOTHDRS=	$(HDRS:%=$(ROOTHDRDIR)/%)
99HDRSRCS=	$(HDRS:%=$(HDRDIR)/%)
100CHECKHDRS=	$(HDRSRCS:%.h=%.check)
101ROOTLIBS=	$(LIBS:%=$(ROOTLIBDIR)/%)
102ROOTLIBS64=	$(LIBS:%=$(ROOTLIBDIR64)/%)
103ROOTFS_LIBS=	$(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
104ROOTFS_LIBS64=	$(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
105ROOTLINKS=	$(ROOTLIBDIR)/$(LIBLINKS)
106ROOTLINKS64=	$(ROOTLIBDIR64)/$(LIBLINKS)
107ROOTFS_LINKS=	$(ROOTFS_LIBDIR)/$(LIBLINKS)
108ROOTFS_LINKS64=	$(ROOTFS_LIBDIR64)/$(LIBLINKS)
109ROOTLINKSCCC=	$(ROOTLIBDIR)/$(LIBLINKSCCC)
110ROOTLINKSCCC64=	$(ROOTLIBDIR64)/$(LIBLINKSCCC)
111ROOTFS_LINKSCCC=	$(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
112ROOTFS_LINKSCCC64=	$(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
113ROOTLINT=	$(LINTSRC:%=$(ROOTLINTDIR)/%)
114ROOTFS_LINT=	$(LINTSRC:%=$(ROOTFS_LINTDIR)/%)
115ROOTFS_LINT64=	$(LINTSRC:%=$(ROOTFS_LINTDIR64)/%)
116ROOTMAN3=     $(ROOT)/usr/share/man/man3
117ROOTMAN3FILES=        $(MAN3FILES:%=$(ROOTMAN3)/%)
118$(ROOTMAN3FILES) := FILEMODE= 444
119
120# Demo rules
121DEMOFILES=
122DEMOFILESRCDIR=		common
123ROOTDEMODIRBASE=	__nonexistent_directory__
124ROOTDEMODIRS=
125ROOTDEMOFILES=	$(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
126$(ROOTDEMODIRS) :=	DIRMODE =	755
127
128LINTLIB=	llib-l$(LIBNAME).ln
129LINTFLAGS=	-uaxm
130LINTFLAGS64=	-uaxm -m64
131LINTSRC=	$(LINTLIB:%.ln=%)
132LINTOUT=	lint.out
133ARFLAGS=	r
134SONAME=		$(DYNLIB)
135# For most libraries, we should be able to resolve all symbols at link time,
136# either within the library or as dependencies, all text should be pure, and
137# combining relocations into one relocation table reduces startup costs.
138# All options are tunable to allow overload/omission from lower makefiles.
139
140
141HSONAME=	-h$(SONAME)
142DYNFLAGS=	$(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
143		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%)
144
145LDLIBS=		$(LDLIBS.lib)
146
147OBJS=		$(OBJECTS:%=objs/%)
148PICS=		$(OBJECTS:%=pics/%)
149
150# Declare that all library .o's can all be made in parallel.
151# The DUMMY target is for those instances where OBJS and PICS
152# are empty (to avoid an unconditional .PARALLEL declaration).
153.PARALLEL:	$(OBJS) $(PICS) DUMMY
154
155# default value for "portable" source
156SRCS=		$(OBJECTS:%.o=$(SRCDIR)/%.c)
157
158# default build of an archive and a shared object,
159# overridden locally when extra processing is needed
160BUILD.AR=	$(AR) $(ARFLAGS) $@ $(AROBJS)
161BUILD.SO=	$(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
162		$(PICS) $(EXTPICS) $(LDLIBS)
163BUILD64.SO=	$(CC64) $(CFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
164		$(PICS) $(EXTPICS) -L $(ROOTLIBDIR64) $(LDLIBS)
165BUILDCCC.SO=	$(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
166		$(PICS) $(EXTPICS) $(LDLIBS)
167BUILDCCC64.SO=	$(CCC64) $(CCFLAGS64) -o $@ $(GSHARED) $(DYNFLAGS) \
168		$(PICS) $(EXTPICS) $(LDLIBS) $(CCNEEDED64)
169
170# default dynamic library symlink
171INS.liblink=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
172INS.liblinkccc=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
173
174# default 64-bit dynamic library symlink
175INS.liblink64=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
176INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
177
178#
179# If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
180# processing.  We'd like to just conditionally append to POST_PROCESS_O and
181# POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
182# sometimes get appended more than once, which will cause ctfconvert to fail.
183# So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
184# appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
185# processing should be done.
186#
187CTFCONVERT_POST = :
188CTFMERGE_POST	= :
189POST_PROCESS_O += ; $(CTFCONVERT_POST)
190POST_PROCESS_SO += ; $(CTFMERGE_POST)
191
192CTFMERGE_LIB	= $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS)
193
194# conditional assignments
195
196$(OBJS)  :=	sparc_CFLAGS += -xregs=no%appl
197
198$(PICS)  :=	sparc_CFLAGS += -xregs=no%appl $(sparc_C_PICFLAGS)
199$(PICS)  :=	sparcv9_CFLAGS += -xregs=no%appl $(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 += -xregs=no%appl $(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$(LINTLIB):=	LOG = -DLOGGING
212$(LIBRARY):=	AROBJS = $(OBJS)
213$(LIBRARY):=	DIR = objs
214$(DYNLIB):=	DIR = pics
215$(DYNLIBCCC):=	DIR = pics
216
217SONAMECCC=	$(DYNLIBCCC)
218HSONAMECCC=	-h $(SONAMECCC)
219#
220# Keep in sync with the standard DYNFLAGS
221#
222$(DYNLIBCCC):=	DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
223		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%) \
224		$(BDIRECT) $(NORUNPATH)
225
226
227# build rule for "portable" source
228objs/%.o pics/%.o: %.c
229	$(COMPILE.c) -o $@ $<
230	$(POST_PROCESS_O)
231
232objs/%.o pics/%.o: %.cc
233	$(COMPILE.cc) -o $@ $<
234	$(POST_PROCESS_O)
235
236.PRECIOUS: $(LIBS)
237
238# Define the majority text domain in this directory.
239TEXT_DOMAIN= SUNW_OST_OSLIB
240
241$(ROOTMAN3)/%: %.sunman
242	$(INS.rename)
243
244#
245# For library source code, we expect that some symbols may not be used or
246# may *appear* to be able to rescoped to static; shut lint up.  Never add
247# a flag here unless you're *sure* that all libraries need to be linted
248# with it.
249#
250LINTCHECKFLAGS = -m -erroff=E_NAME_DEF_NOT_USED2
251LINTCHECKFLAGS += -erroff=E_NAME_DECL_NOT_USED_DEF2
252
253#
254# Target Architecture
255#
256TARGETMACH=	$(MACH)
257
258#
259# Allow people to define their own clobber rules.  Normal makefiles
260# shouldn't override this - they should override $(CLOBBERFILES) instead.
261#
262CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES)
263
264#
265# Define the default ctfdiff invocation used to check a list of types
266# supplied by a user of a library. The goal is to validate that a given
267# series of types is the same in both a 32-bit and 64-bit artifact. This
268# is only defined if we have a 64-bit build to do.
269#
270TYPECHECK_LIB32 =		$(TYPECHECK_LIB:%=$(MACH)/%)
271TYPECHECK_LIB64 =		$(TYPECHECK_LIB:%=$(MACH64)/%)
272TYPECHECK_LIST=			$(TYPELIST:%=-T %)
273$(BUILD64)TYPECHECK.lib =	$(CTFDIFF) -t -I $(TYPECHECK_LIST) $(TYPECHECK_LIB32) $(TYPECHECK_LIB64)
274TYPECHECK =			$(TYPECHECK_LIB:%=%.typecheck)
275