Makefile.lib: use tsort -q
[unleashed.git] / usr / src / lib / Makefile.lib
blobc0216dd3b2c6e7db83c9d14bf325c98596eb39f6
2 # CDDL HEADER START
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.
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.
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]
19 # CDDL HEADER END
21 # Copyright 2015 Gary Mills
22 # Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
23 # Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Copyright (c) 2015, Joyent, Inc.
27 # Definitions common to libraries.
29 # include global definitions; SRC should be defined in the shell.
30 # SRC is needed until RFE 1026993 is implemented.
32 include         $(SRC)/Makefile.master
34 LORDER=         lorder
35 TSORT=          tsort -q
38 # By default, we define the source directory for libraries to be
39 # one level up from the ISA-specific directory, where the code is
40 # actually built.  Many libraries define a 'common' directory to
41 # contain the source.  These libraries must redefine SRCDIR as:
42 #       SRCDIR = ../common
43 # Other variations are possible (../port, ../src, etc).
45 SRCDIR =        ..
48 # We define MAPFILES here for the benefit of most libraries, those that
49 # follow the convention of having source files and other common files
50 # in the $(SRCDIR) directory.  Libraries that do not follow this
51 # convention must define MAPFILES, or MAPFILEDIR for themselves.
52 # Libraries that do follow this convention but that need supplemental
53 # ISA-specific mapfiles can augment MAPFILES like this:
54 #       MAPFILES += mapfile-vers
56 MAPFILEDIR =    $(SRCDIR)
57 MAPFILES =      $(MAPFILEDIR)/mapfile-vers
60 # If HDRDIR is left unset, then it's possible for the $(ROOTHDRDIR)/%
61 # install rule in lib/Makefile.targ to generate false matches if there
62 # are any common directory names between / and /usr/include (`xfn' is
63 # one common example).  To prevent this, we set HDRDIR to a directory
64 # name that will almost surely not exist on the build machine.
66 HDRDIR=         /__nonexistent_directory__
69 # We don't build archive (*.a) libraries by default anymore.
70 # If a component of the build needs to build an archive library
71 # for its own internal purposes, it can define LIBS for itself
72 # after including Makefile.lib, like this:
73 #       LIBS = $(LIBRARY)
74 # or:
75 #       LIBS = $(LIBRARYCCC)
76 # Archive libraries must not be installed in the proto area.
78 LIBS=
79 MACHLIBS=       $(LIBS:%=$(MACH)/%)
80 MACHLIBS64=     $(LIBS:%=$(MACH64)/%)
81 DYNLIB=         $(LIBRARY:.a=.so$(VERS))
82 DYNLIBPSR=      $(LIBRARY:.a=_psr.so$(VERS))
83 DYNLIBCCC=      $(LIBRARYCCC:.a=.so$(VERS))
84 LIBLINKS=       $(LIBRARY:.a=.so)
85 LIBLINKSCCC=    $(LIBRARYCCC:.a=.so)
86 LIBNAME=        $(LIBRARY:lib%.a=%)
87 LIBLINKPATH=
88 LIBNULL=        null.a
89 ROOTHDRDIR=     $(ROOT)/usr/include
90 ROOTLIBDIR=     $(ROOT)/usr/lib
91 ROOTLIBDIR64=   $(ROOT)/usr/lib/$(MACH64)
92 ROOTFS_LIBDIR=  $(ROOT)/lib
93 ROOTFS_LIBDIR64=        $(ROOT)/lib/$(MACH64)
94 ROOTHDRS=       $(HDRS:%=$(ROOTHDRDIR)/%)
95 HDRSRCS=        $(HDRS:%=$(HDRDIR)/%)
96 CHECKHDRS=      $(HDRSRCS:%.h=%.check)
97 ROOTLIBS=       $(LIBS:%=$(ROOTLIBDIR)/%)
98 ROOTLIBS64=     $(LIBS:%=$(ROOTLIBDIR64)/%)
99 ROOTFS_LIBS=    $(DYNLIB:%=$(ROOTFS_LIBDIR)/%)
100 ROOTFS_LIBS64=  $(DYNLIB:%=$(ROOTFS_LIBDIR64)/%)
101 ROOTLINKS=      $(ROOTLIBDIR)/$(LIBLINKS)
102 ROOTLINKS64=    $(ROOTLIBDIR64)/$(LIBLINKS)
103 ROOTFS_LINKS=   $(ROOTFS_LIBDIR)/$(LIBLINKS)
104 ROOTFS_LINKS64= $(ROOTFS_LIBDIR64)/$(LIBLINKS)
105 ROOTLINKSCCC=   $(ROOTLIBDIR)/$(LIBLINKSCCC)
106 ROOTLINKSCCC64= $(ROOTLIBDIR64)/$(LIBLINKSCCC)
107 ROOTFS_LINKSCCC=        $(ROOTFS_LIBDIR)/$(LIBLINKSCCC)
108 ROOTFS_LINKSCCC64=      $(ROOTFS_LIBDIR64)/$(LIBLINKSCCC)
109 ROOTMAN3=     $(ROOT)/usr/share/man/man3
110 ROOTMAN3FILES=        $(MAN3FILES:%=$(ROOTMAN3)/%)
111 $(ROOTMAN3FILES) := FILEMODE= 444
113 # Demo rules
114 DEMOFILES=
115 DEMOFILESRCDIR=         common
116 ROOTDEMODIRBASE=        __nonexistent_directory__
117 ROOTDEMODIRS=
118 ROOTDEMOFILES=  $(DEMOFILES:%=$(ROOTDEMODIRBASE)/%)
119 $(ROOTDEMODIRS) :=      DIRMODE =       755
121 SONAME=         $(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.
128 HSONAME=        -h$(SONAME)
129 DYNFLAGS=       $(HSONAME) $(ZTEXT) $(ZDEFS) $(BDIRECT) \
130                 $(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%)
132 LDLIBS=         $(LDLIBS.lib)
134 OBJS=           $(OBJECTS:%=objs/%)
135 PICS=           $(OBJECTS:%=pics/%)
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
142 # default value for "portable" source
143 SRCS=           $(OBJECTS:%.o=$(SRCDIR)/%.c)
145 # default build of an archive and a shared object,
146 # overridden locally when extra processing is needed
147 BUILD.AR=       $(AR) $(ARFLAGS) $@ $(AROBJS)
148 BUILD.SO=       $(CC) $(CFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
149                 $(PICS) $(EXTPICS) $(LDLIBS)
150 BUILDCCC.SO=    $(CCC) $(CCFLAGS) -o $@ $(GSHARED) $(DYNFLAGS) \
151                 $(PICS) $(EXTPICS) $(LDLIBS)
153 # default dynamic library symlink
154 INS.liblink=    -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
155 INS.liblinkccc= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
157 # default 64-bit dynamic library symlink
158 INS.liblink64=  -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKS)$(VERS) $@
159 INS.liblinkccc64= -$(RM) $@; $(SYMLINK) $(LIBLINKPATH)$(LIBLINKSCCC)$(VERS) $@
162 # If appropriate, augment POST_PROCESS_O and POST_PROCESS_SO to do CTF
163 # processing.  We'd like to just conditionally append to POST_PROCESS_O and
164 # POST_PROCESS_SO, but ParallelMake has a bug which causes the same value to
165 # sometimes get appended more than once, which will cause ctfconvert to fail.
166 # So, instead we introduce CTFCONVERT_POST and CTFMERGE_POST, which are always
167 # appended to POST_PROCESS_O and POST_PROCESS_SO but are no-ops unless CTF
168 # processing should be done.
170 CTFCONVERT_POST = :
171 CTFMERGE_POST   = :
172 POST_PROCESS_O += ; $(CTFCONVERT_POST)
173 POST_PROCESS_SO += ; $(CTFMERGE_POST)
175 CTFMERGE_LIB    = $(CTFMERGE) $(CTFMRGFLAGS) -t -f -L VERSION -o $@ $(PICS)
177 # conditional assignments
179 $(OBJS)  :=     sparc_CFLAGS += -mno-app-regs
181 $(PICS)  :=     sparc_CFLAGS += -mno-app-regs $(sparc_C_PICFLAGS)
182 $(PICS)  :=     sparcv9_CFLAGS += -mno-app-regs $(sparcv9_C_PICFLAGS)
183 $(PICS)  :=     i386_CFLAGS += $(i386_C_PICFLAGS)
184 $(PICS)  :=     amd64_CFLAGS += $(amd64_C_PICFLAGS)
185 $(PICS)  :=     CCFLAGS += $(CC_PICFLAGS)
186 $(PICS)  :=     CPPFLAGS += -DPIC
187 $(PICS)  :=     sparcv9_CCFLAGS += -mno-app-regs $(sparcv9_CC_PICFLAGS)
188 $(PICS)  :=     amd64_CCFLAGS += $(amd64_CC_PICFLAGS)
189 $(PICS)  :=     CFLAGS += $(CTF_FLAGS)
190 $(PICS)  :=     CFLAGS64 += $(CTF_FLAGS)
191 $(PICS)  :=     CTFCONVERT_POST = $(CTFCONVERT_O)
192 $(DYNLIB) :=    CTFMERGE_POST = $(CTFMERGE_LIB)
194 $(LIBRARY):=    AROBJS = $(OBJS)
195 $(LIBRARY):=    DIR = objs
196 $(DYNLIB):=     DIR = pics
197 $(DYNLIBCCC):=  DIR = pics
199 SONAMECCC=      $(DYNLIBCCC)
200 HSONAMECCC=     -h $(SONAMECCC)
202 # Keep in sync with the standard DYNFLAGS
204 $(DYNLIBCCC):=  DYNFLAGS = $(HSONAMECCC) $(ZTEXT) $(ZDEFS) \
205                 $(MAPFILES:%=-Wl,-M%) $(MAPFILE.PGA:%=-Wl,-M%) $(BDIRECT)
208 # build rule for "portable" source 
209 objs/%.o pics/%.o: %.c
210         $(COMPILE.c) -o $@ $<
211         $(POST_PROCESS_O)
213 objs/%.o pics/%.o: %.cc
214         $(COMPILE.cc) -o $@ $<
215         $(POST_PROCESS_O)
217 .PRECIOUS: $(LIBS)
219 # Define the majority text domain in this directory.
220 TEXT_DOMAIN= SUNW_OST_OSLIB
222 $(ROOTMAN3)/%: %.sunman
223         $(INS.rename)
226 # Target Architecture
228 TARGETMACH=     $(MACH)
231 # Allow people to define their own clobber rules.  Normal makefiles
232 # shouldn't override this - they should override $(CLOBBERFILES) instead.
234 CLOBBERTARGFILES= $(LIBS) $(DYNLIB) $(CLOBBERFILES)
237 # Define the default ctfdiff invocation used to check a list of types
238 # supplied by a user of a library. The goal is to validate that a given
239 # series of types is the same in both a 32-bit and 64-bit artifact. This
240 # is only defined if we have a 64-bit build to do.
242 TYPECHECK_LIB32 =               $(TYPECHECK_LIB:%=$(MACH)/%)
243 TYPECHECK_LIB64 =               $(TYPECHECK_LIB:%=$(MACH64)/%)
244 TYPECHECK_LIST=                 $(TYPELIST:%=-T %)
245 $(BUILD64)TYPECHECK.lib =       $(CTFDIFF) -t -I $(TYPECHECK_LIST) $(TYPECHECK_LIB32) $(TYPECHECK_LIB64)
246 TYPECHECK =                     $(TYPECHECK_LIB:%=%.typecheck)