xref: /illumos-gate/usr/src/lib/Makefile.lib (revision 67e3a03e)
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#
22# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25# ident	"%Z%%M%	%I%	%E% SMI"
26#
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
38AWK=		awk
39
40#
41# By default, we define the source directory for libraries to be
42# one level up from the ISA-specific directory, where the code is
43# actually built.  Many libraries define a 'common' directory to
44# contain the source.  These libraries must redefine SRCDIR as:
45#	SRCDIR = ../common
46# Other variations are possible (../port, ../src, etc).
47#
48SRCDIR =	..
49
50#
51# We define MAPFILES here for the benefit of most libraries,
52# those that follow the convention of having source files and other
53# common files in the $(SRCDIR) directory.  Libraries that do not
54# follow this convention must define MAPFILES for themselves.
55# Libraries that do follow this convention but that need supplemental
56# ISA-specific mapfiles can augment MAPFILES like this:
57#	MAPFILES += mapfile-vers
58#
59MAPFILES =	$(SRCDIR)/mapfile-vers
60
61C_SYNONYMS_H=	$(SRC)/lib/common/inc/c_synonyms.h
62
63#
64# If HDRDIR is left unset, then it's possible for the $(ROOTHDRDIR)/%
65# install rule in lib/Makefile.targ to generate false matches if there
66# are any common directory names between / and /usr/include (`xfn' is
67# one common example).  To prevent this, we set HDRDIR to a directory
68# name that will almost surely not exist on the build machine.
69#
70HDRDIR=		/__nonexistent_directory__
71
72#
73# We don't build archive (*.a) libraries by default anymore.
74# If a component of the build needs to build an archive library
75# for its own internal purposes, it can define LIBS for itself
76# after including Makefile.lib, like this:
77# 	LIBS = $(LIBRARY)
78# or:
79# 	LIBS = $(LIBRARYCCC)
80# Archive libraries must not be installed in the proto area.
81#
82LIBS=
83MACHLIBS=	$(LIBS:%=$(MACH)/%)
84MACHLIBS64=	$(LIBS:%=$(MACH64)/%)
85DYNLIB=		$(LIBRARY:.a=.so$(VERS))
86DYNLIBPSR=	$(LIBRARY:.a=_psr.so$(VERS))
87DYNLIBCCC=	$(LIBRARYCCC:.a=.so$(VERS))
88LIBLINKS=	$(LIBRARY:.a=.so)
89LIBLINKSCCC=	$(LIBRARYCCC:.a=.so)
90LIBNAME=	$(LIBRARY:lib%.a=%)
91LIBLINKPATH=
92LIBNULL=	null.a
93ROOTHDRDIR=	$(ROOT)/usr/include
94ROOTLIBDIR=	$(ROOT)/usr/lib
95ROOTLIBDIR64=	$(ROOT)/usr/lib/$(MACH64)
96ROOTFS_LIBDIR=	$(ROOT)/lib
97ROOTFS_LIBDIR64=	$(ROOT)/lib/$(MACH64)
98ROOTLINTDIR=	$(ROOTLIBDIR)
99ROOTFS_LINTDIR=	$(ROOTFS_LIBDIR)
100ROOTFS_LINTDIR64=	$(ROOTFS_LIBDIR64)
101ROOTHDRS=	$(HDRS:%=$(ROOTHDRDIR)/%)
102HDRSRCS=	$(HDRS:%=$(HDRDIR)/%)
103CHECKHDRS=	$(HDRSRCS:%.h=%.check)
104ROOTLIBS=	$(LIBS:%=$(ROOTLIBDIR)/%)
105ROOTLIBS64=	$(LIBS:%=$(ROOTLIBDIR64)/%)
106ROOTFS_LIBS=	$(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
107ROOTFS_LIBS64=	$(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
108ROOTLINKS=	$(ROOTLIBDIR)/$(LIBLINKS)
109ROOTLINKS64=	$(ROOTLIBDIR64)/$(LIBLINKS)
110ROOTFS_LINKS=	$(ROOTFS_LIBDIR)/$(LIBLINKS)
111ROOTFS_LINKS64=	$(ROOTFS_LIBDIR64)/$(LIBLINKS)
112ROOTLINKSCCC=	$(ROOTLIBDIR)/$(LIBLINKSCCC)
113ROOTLINKSCCC64=	$(ROOTLIBDIR64)/$(LIBLINKSCCC)
114ROOTFS_LINKSCCC=	$(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
115ROOTFS_LINKSCCC64=	$(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
116ROOTLINT=	$(LINTSRC:%=$(ROOTLINTDIR)/%)
117ROOTFS_LINT=	$(LINTSRC:%=$(ROOTFS_LINTDIR)/%)
118ROOTFS_LINT64=	$(LINTSRC:%=$(ROOTFS_LINTDIR64)/%)
119ROOTMAN3=     $(ROOT)/usr/share/man/man3
120ROOTMAN3FILES=        $(MAN3FILES:%=$(ROOTMAN3)/%)
121$(ROOTMAN3FILES) := FILEMODE= 444
122$(ROOTMAN3FILES) := OWNER= root
123$(ROOTMAN3FILES) := GROUP= bin
124
125# Demo rules
126DEMOFILES=
127DEMOFILESRCDIR=		common
128ROOTDEMODIRBASE=	__nonexistent_directory__
129ROOTDEMODIRS=
130ROOTDEMOFILES=	$(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
131$(ROOTDEMODIRS) :=	OWNER =		root
132$(ROOTDEMODIRS) :=	GROUP =		bin
133$(ROOTDEMODIRS) :=	DIRMODE =	755
134
135#
136# Begin /usr/sfw freeware rules for freeware that has "External"
137# taxonomy stability level.
138#
139ROOTSFW=	$(ROOT)/usr/sfw
140ROOTSFWBIN=	$(ROOT)/usr/sfw/bin
141ROOTSFWETC=	$(ROOT)/etc/sfw
142ROOTSFWVAR=	$(ROOT)/var/sfw
143ROOTSFWSHARE=	$(ROOT)/usr/sfw/share
144ROOTSFWSHSRC=	$(ROOT)/usr/sfw/share/src
145ROOTSFWINCLUDE=	$(ROOT)/usr/sfw/include
146ROOTSFWLIB=	$(ROOT)/usr/sfw/lib
147ROOTSFWLIB64=	$(ROOT)/usr/sfw/lib/$(MACH64)
148ROOTSFWMAN=	$(ROOT)/usr/sfw/share/man
149ROOTSFWMANN=	$(ROOT)/usr/sfw/share/mann
150ROOTSFWMAN1=	$(ROOT)/usr/sfw/share/man/man1
151ROOTSFWMAN1M=	$(ROOT)/usr/sfw/share/man/man1m
152ROOTSFWMAN3=	$(ROOT)/usr/sfw/share/man/man3
153ROOTSFWMAN5=	$(ROOT)/usr/sfw/share/man/man5
154ROOTSFWMAN7=	$(ROOT)/usr/sfw/share/man/man7
155#
156# End /usr/sfw freeware rules
157#
158
159LINTLIB=	llib-l$(LIBNAME).ln
160LINTFLAGS=	-uaxm
161LINTFLAGS64=	-uaxm -Xarch=$(MACH64:sparcv9=v9)
162LINTSRC=	$(LINTLIB:%.ln=%)
163LINTOUT=	lint.out
164ARFLAGS=	r
165SONAME=		$(DYNLIB)
166# For most libraries, we should be able to resolve all symbols at link time,
167# either within the library or as dependencies, all text should be pure, and
168# combining relocations into one relocation table reduces startup costs.
169# All options are tunable to allow overload/omission from lower makefiles.
170
171
172HSONAME=	-h$(SONAME)
173DYNFLAGS=	$(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
174		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%)
175
176LDLIBS=		$(LDLIBS.lib)
177
178OBJS=		$(OBJECTS:%=objs/%)
179PICS=		$(OBJECTS:%=pics/%)
180
181# Declare that all library .o's can all be made in parallel.
182# The DUMMY target is for those instances where OBJS and PICS
183# are empty (to avoid an unconditional .PARALLEL declaration).
184.PARALLEL:	$(OBJS) $(PICS) DUMMY
185
186# default value for "portable" source
187SRCS=		$(OBJECTS:%.o=$(SRCDIR)/%.c)
188
189# default build of an archive and a shared object,
190# overridden locally when extra processing is needed
191BUILD.AR=	$(AR) $(ARFLAGS) $@ $(AROBJS)
192BUILD.SO=	$(CC) -o $@ $(GSHARED) $(DYNFLAGS) $(PICS) $(LDLIBS)
193BUILDCCC.SO=	$(CCC) -o $@ $(GSHARED) $(DYNFLAGS) $(PICS) $(LDLIBS)
194
195# default dynamic library symlink
196INS.liblink=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
197INS.liblinkccc=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
198
199# default 64-bit dynamic library symlink
200INS.liblink64=	-$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
201INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
202
203#
204# If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
205# processing.  We'd like to just conditionally append to POST_PROCESS_O and
206# POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
207# sometimes get appended more than once, which will cause ctfconvert to fail.
208# So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
209# appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
210# processing should be done.
211#
212CTFCONVERT_POST = :
213CTFMERGE_POST	= :
214POST_PROCESS_O += ; $(CTFCONVERT_POST)
215POST_PROCESS_SO += ; $(CTFMERGE_POST)
216
217CTFMERGE_LIB	= $(CTFMERGE) -t -f -L VERSION -o $@ $(PICS)
218
219# conditional assignments
220
221$(OBJS)  :=	sparc_CFLAGS += -xregs=no%appl
222
223$(PICS)  :=	sparc_CFLAGS += -xregs=no%appl $(sparc_C_PICFLAGS)
224$(PICS)  :=	sparcv9_CFLAGS += -xregs=no%appl $(sparcv9_C_PICFLAGS)
225$(PICS)  :=	i386_CFLAGS += $(i386_C_PICFLAGS)
226$(PICS)  :=	amd64_CFLAGS += $(amd64_C_PICFLAGS)
227$(PICS)  :=	CCFLAGS += $(CC_PICFLAGS)
228$(PICS)  :=	CPPFLAGS += -DPIC -D_REENTRANT
229$(PICS)  :=	sparcv9_CCFLAGS += -xregs=no%appl $(sparcv9_CC_PICFLAGS)
230$(PICS)  :=	amd64_CCFLAGS += $(amd64_CC_PICFLAGS)
231$(PICS)  :=	CFLAGS += $(CTF_FLAGS)
232$(PICS)	 :=	CFLAGS64 += $(CTF_FLAGS)
233$(PICS)  :=	CTFCONVERT_POST = $(CTFCONVERT_O)
234$(DYNLIB) :=	CTFMERGE_POST = $(CTFMERGE_LIB)
235
236$(LINTLIB):=	LOG = -DLOGGING
237$(LIBRARY):=	AROBJS = $(OBJS)
238$(LIBRARY):=	DIR = objs
239$(DYNLIB):=	DIR = pics
240$(DYNLIBCCC):=	DIR = pics
241
242SONAMECCC=	$(DYNLIBCCC)
243HSONAMECCC=	-h $(SONAMECCC)
244#
245# Keep in sync with the standard DYNFLAGS
246#
247$(DYNLIBCCC):=	DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
248		$(MAPFILES:%=-M%) $(MAPFILE.PGA:%=-M%) $(MAPFILE.NED:%=-M%) \
249		$(BDIRECT) $(NORUNPATH)
250
251
252# build rule for "portable" source
253objs/%.o pics/%.o: %.c
254	$(COMPILE.c) -o $@ $<
255	$(POST_PROCESS_O)
256
257objs/%.o pics/%.o: %.cc
258	$(COMPILE.cc) -o $@ $<
259	$(POST_PROCESS_O)
260
261.PRECIOUS: $(LIBS)
262
263# Define the majority text domain in this directory.
264TEXT_DOMAIN= SUNW_OST_OSLIB
265
266$(ROOTMAN3)/%: %.sunman
267	$(INS.rename)
268
269#
270# For library source code, we expect that some symbols may not be used or
271# may *appear* to be able to rescoped to static; shut lint up.  Never add
272# a flag here unless you're *sure* that all libraries need to be linted
273# with it.
274#
275LINTCHECKFLAGS = -m -erroff=E_NAME_DEF_NOT_USED2
276LINTCHECKFLAGS += -erroff=E_NAME_DECL_NOT_USED_DEF2
277
278#
279# Target Architecture
280#
281TARGETMACH=	$(MACH)
282
283#
284# Allow people to define their own clobber rules.  Normal makefiles
285# shouldn't override this - they should override $(CLOBBERFILES) instead.
286#
287CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES)
288