README.Makefiles
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 2006 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
24 #
25 # ident "%Z%%M% %I% %E% SMI"
26 #
27
28 Writing Library Makefiles in ON
29 ===============================
30
31 Introduction
32 ------------
33
34 This document guides you through the gnarly process of writing library
35 Makefiles for the ON consolidation. It assumes that you're comfortable with
36 make(1) and are somewhat familiar with the ON Makefile standards outlined in
37 /shared/ON/general_docs/make_std.txt.
38
39 Makefile Overview
40 -----------------
41
42 Your library should consist of a hierarchical collection of Makefiles:
43
44 lib/<library>/Makefile:
45
46 This is your library's top-level Makefile. It should contain rules
47 for building any ISA-independent targets, such as installing header
48 files and building message catalogs, but should defer all other
49 targets to ISA-specific Makefiles.
50
51 lib/<library>/Makefile.com
52
53 This is your library's common Makefile. It should contain rules
54 and macros which are common to all ISAs. This Makefile should never
55 be built explicitly, but instead should be included (using the make
56 include mechanism) by all of your ISA-specific Makefiles.
57
58 lib/<library>/<isa>/Makefile
59
60 These are your library's ISA-specific Makefiles, one per ISA
61 (usually sparc and i386, and often sparcv9 and amd64). These
62 Makefiles should include your common Makefile and then provide any
63 needed ISA-specific rules and definitions, perhaps overriding those
64 provided in your common Makefile.
65
66 To simplify their maintenance and construction, $(SRC)/lib has a handful of
67 provided Makefiles that yours must include; the examples provided throughout
68 the document will show how to use them. Please be sure to consult these
69 Makefiles before introducing your own custom build macros or rules.
70
71 lib/Makefile.lib:
72
73 This contains the bulk of the macros for building shared objects.
74
75 lib/Makefile.lib.64
76
77 This contains macros for building 64-bit objects, and should be
78 included in Makefiles for 64-bit native ISAs.
79
80 lib/Makefile.rootfs
81
82 This contains macro overrides for libraries that install into /lib
83 (rather than /usr/lib).
84
85 lib/Makefile.targ
86
87 This contains rules for building shared objects.
88
89 The remainder of this document discusses how to write each of your Makefiles
90 in detail, and provides examples from the libinetutil library.
91
92 The Library Top-level Makefile
93 ------------------------------
94
95 As described above, your top-level library Makefile should contain
96 rules for building ISA-independent targets, but should defer the
97 building of all other targets to ISA-specific Makefiles. The
98 ISA-independent targets usually consist of:
99
100 install_h
101
102 Install all library header files into the proto area.
103 Can be omitted if your library has no header files.
104
105 check
106
107 Check all library header files for hdrchk compliance.
108 Can be omitted if your library has no header files.
109
110 _msg
111
112 Build and install a message catalog.
113 Can be omitted if your library has no message catalog.
114
115 Of course, other targets (such as `cstyle') are fine as well, as long as
116 they are ISA-independent.
117
118 The ROOTHDRS and CHECKHDRS targets are provided in lib/Makefile.lib to make
119 it easy for you to install and check your library's header files. To use
120 these targets, your Makefile must set the HDRS to the list of your library's
121 header files to install and HDRDIR to the their location in the source tree.
122 In addition, if your header files need to be installed in a location other
123 than $(ROOT)/usr/include, your Makefile must also set ROOTHDRDIR to the
124 appropriate location in the proto area. Once HDRS, HDRDIR and (optionally)
125 ROOTHDRDIR have been set, your Makefile need only contain
126
127 install_h: $(ROOTHDRS)
128
129 check: $(CHECKHDRS)
130
131 to bind the provided targets to the standard `install_h' and `check' rules.
132
133 Similar rules are provided (in $(SRC)/Makefile.msg.targ) to make it easy for
134 you to build and install message catalogs from your library's source files.
135
136 To install a catalog into the catalog directory in the proto area, define the
137 POFILE macro to be the name of your catalog, and specify that the _msg target
138 depends on $(MSGDOMAINPOFILE). The examples below should clarify this.
139
140 To build a message catalog from arbitrarily many message source files, use
141 the BUILDPO.msgfiles macro.
142
143 include ../Makefile.lib
144
145 POFILE = libfoo.po
146 MSGFILES = $(OBJECTS:%.o=%.i)
147
148 # ...
149
150 $(POFILE): $(MSGFILES)
151 $(BUILDPO.msgfiles)
152
153 _msg: $(MSGDOMAINPOFILE)
154
155 include $(SRC)/Makefile.msg.targ
156
157 Note that this example doesn't use grep to find message files, since that can
158 mask unreferenced files, and potentially lead to the inclusion of unwanted
159 messages or omission of intended messages in the catalogs. As such, MSGFILES
160 should be derived from a known list of objects or sources.
161
162 It is usually preferable to run the source through the C preprocessor prior
163 to extracting messages. To do this, use the ".i" suffix, as shown in the
164 above example. If you need to skip the C preprocessor, just use the native
165 (.[ch]) suffix.
166
167 The only time you shouldn't use BUILDPO.msgfiles as the preferred means of
168 extracting messages is when you're extracting them from shell scripts; in
169 that case, you can use the BUILDPO.pofiles macro as explained below.
170
171 To build a message catalog from other message catalogs, or from source files
172 that include shell scripts, use the BUILDPO.pofiles macro:
173
174 include ../Makefile.lib
175
176 SUBDIRS = $(MACH)
177
178 POFILE = libfoo.po
179 POFILES = $(SUBDIRS:%=%/_%.po)
180
181 _msg := TARGET = _msg
182
183 # ...
184
185 $(POFILE): $(POFILES)
186 $(BUILDPO.pofiles)
187
188 _msg: $(MSGDOMAINPOFILE)
189
190 include $(SRC)/Makefile.msg.targ
191
192 The Makefile above would work in conjunction with the following in its
193 subdirectories' Makefiles:
194
195 POFILE = _thissubdir.po
196 MSGFILES = $(OBJECTS:%.o=%.i)
197
198 $(POFILE): $(MSGFILES)
199 $(BUILDPO.msgfiles)
200
201 _msg: $(POFILE)
202
203 include $(SRC)/Makefile.msg.targ
204
205 Since this POFILE will be combined with those in other subdirectories by the
206 parent Makefile and that merged file will be installed into the proto area
207 via MSGDOMAINPOFILE, there is no need to use MSGDOMAINPOFILE in this Makefile
208 (in fact, using it would lead to duplicate messages in the catalog).
209
210 When using any of these targets, keep in mind that other macros, like
211 XGETFLAGS and TEXT_DOMAIN may also be set in your Makefile to override or
212 augment the defaults provided in higher-level Makefiles.
213
214 As previously mentioned, you should defer all ISA-specific targets to your
215 ISA-specific Makefiles. You can do this by:
216
217 1. Setting SUBDIRS to the list of directories to descend into:
218
219 SUBDIRS = $(MACH)
220
221 Note that if your library is also built 64-bit, then you should
222 also specify
223
224 $(BUILD64)SUBDIRS += $(MACH64)
225
226 so that SUBDIRS contains $(MACH64) if and only if you're compiling
227 on a 64-bit ISA.
228
229 2. Providing a common "descend into SUBDIRS" rule:
230
231 $(SUBDIRS): FRC
232 @cd $@; pwd; $(MAKE) $(TARGET)
233
234 FRC:
235
236 3. Providing a collection of conditional assignments that set TARGET
237 appropriately:
238
239 all := TARGET= all
240 clean := TARGET= clean
241 clobber := TARGET= clobber
242 install := TARGET= install
243 lint := TARGET= lint
244
245 The order doesn't matter, but alphabetical is preferable.
246
247 4. Having the aforementioned targets depend on SUBDIRS:
248
249 all clean clobber install lint: $(SUBDIRS)
250
251 The `all' target must be listed first so that make uses it as the
252 default target; the others might as well be listed alphabetically.
253
254 As an example of how all of this goes together, here's libinetutil's
255 top-level library Makefile (license notice and copyright omitted):
256
257 include ../Makefile.lib
258
259 HDRS = libinetutil.h
260 HDRDIR = common
261 SUBDIRS = $(MACH)
262 $(BUILD64)SUBDIRS += $(MACH64)
263
264 all := TARGET = all
265 clean := TARGET = clean
266 clobber := TARGET = clobber
267 install := TARGET = install
268 lint := TARGET = lint
269
270 .KEEP_STATE:
271
272 all clean clobber install lint: $(SUBDIRS)
273
274 install_h: $(ROOTHDRS)
275
276 check: $(CHECKHDRS)
277
278 $(SUBDIRS): FRC
279 @cd $@; pwd; $(MAKE) $(TARGET)
280
281 FRC:
282
283 include ../Makefile.targ
284
285 The Common Makefile
286 -------------------
287
288 In concept, your common Makefile should contain all of the rules and
289 definitions that are the same on all ISAs. However, for reasons of
290 maintainability and cleanliness, you're encouraged to place even
291 ISA-dependent rules and definitions, as long you express them in an
292 ISA-independent way (e.g., by using $(MACH), $(TARGETMACH), and their kin).
293 (TARGETMACH is the same as MACH for 32-bit targets, and the same as MACH64
294 for 64-bit targets).
295
296 The common Makefile can be conceptually split up into four sections:
297
298 1. A copyright and comments section. Please see the prototype
299 files in usr/src/prototypes for examples of how to format the
300 copyright message properly. For brevity and clarity, this
301 section has been omitted from the examples shown here.
302
303 2. A list of macros that must be defined prior to the inclusion of
304 Makefile.lib. This section is conceptually terminated by the
305 inclusion of Makefile.lib, followed, if necessary, by the
306 inclusion of Makefile.rootfs (only if the library is to be
307 installed in /lib rather than the default /usr/lib).
308
309 3. A list of macros that need not be defined prior to the inclusion
310 of Makefile.lib (or which must be defined following the inclusion
311 of Makefile.lib, to override or augment its definitions). This
312 section is conceptually terminated by the .KEEP_STATE directive.
313
314 4. A list of targets.
315
316 The first section is self-explanatory. The second typically consists of the
317 following macros:
318
319 LIBRARY
320
321 Set to the name of the static version of your library, such
322 as `libinetutil.a'. You should always specify the `.a' suffix,
323 since pattern-matching rules in higher-level Makefiles rely on it,
324 even though static libraries are not normally built in ON, and
325 are never installed in the proto area. Note that the LIBS macro
326 (described below) controls the types of libraries that are built
327 when building your library.
328
329 If you are building a loadable module (i.e., a shared object that
330 is only linked at runtime with dlopen(3dl)), specify the name of
331 the loadable module with a `.a' suffix, such as `devfsadm_mod.a'.
332
333 VERS
334
335 Set to the version of your shared library, such as `.1'. You
336 actually do not need to set this prior to the inclusion of
337 Makefile.lib, but it is good practice to do so since VERS and
338 LIBRARY are so closely related.
339
340 OBJECTS
341
342 Set to the list of object files contained in your library, such as
343 `a.o b.o'. Usually, this will be the same as your library's source
344 files (except with .o extensions), but if your library compiles
345 source files outside of the library directory itself, it will
346 differ. We'll see an example of this with libinetutil.
347
348 The third section typically consists of the following macros:
349
350 LIBS
351
352 Set to the list of the types of libraries to build when building
353 your library. For dynamic libraries, you should set this to
354 `$(DYNLIB) $(LINTLIB)' so that a dynamic library and lint library
355 are built. For loadable modules, you should just list DYNLIB,
356 since there's no point in building a lint library for libraries
357 that are never linked at compile-time.
358
359 If your library needs to be built as a static library (typically
360 to be used in other parts of the build), you should set LIBS to
361 `$(LIBRARY)'. However, you should do this only when absolutely
362 necessary, and you must *never* ship static libraries to customers.
363
364 ROOTLIBDIR (if your library installs to a nonstandard directory)
365
366 Set to the directory your 32-bit shared objects will install into
367 with the standard $(ROOTxxx) macros. Since this defaults to
368 $(ROOT)/usr/lib ($(ROOT)/lib if you included Makefile.rootfs),
369 you usually do not need to set this.
370
371 ROOTLIBDIR64 (if your library installs to a nonstandard directory)
372
373 Set to the directory your 64-bit shared objects will install into
374 with the standard $(ROOTxxx64) macros. Since this defaults to
375 $(ROOT)/usr/lib/$(MACH64) ($(ROOT)/lib/$(MACH64) if you included
376 Makefile.rootfs), you usually do not need to set this.
377
378 SRCDIR
379
380 Set to the directory containing your library's source files, such
381 as `../common'. Because this Makefile is actually included from
382 your ISA-specific Makefiles, make sure you specify the directory
383 relative to your library's <isa> directory.
384
385 SRCS (if necessary)
386
387 Set to the list of source files required to build your library.
388 This defaults to $(OBJECTS:%.o=$(SRCDIR)/%.c) in Makefile.lib, so
389 you only need to set this when source files from directories other
390 than SRCDIR are needed. Keep in mind that SRCS should be set to a
391 list of source file *pathnames*, not just a list of filenames.
392
393 LINTLIB-specific SRCS (required if building a lint library)
394
395 Set to a special "lint stubs" file to use when constructing your
396 library's lint library. The lint stubs file must be used to
397 guarantee that programs that link against your library will be able
398 to lint clean. To do this, you must conditionally set SRCS to use
399 your stubs file by specifying `LINTLIB := SRCS= $(SRCDIR)/$(LINTSRC)'
400 in your Makefile. Of course, you do not need to set this if your
401 library does not build a lint library.
402
403 LDLIBS
404
405 Appended with the list of libraries and library directories needed
406 to build your library; minimally "-lc". Note that this should
407 *never* be set, since that will inadvertently clear the library
408 search path, causing the linker to look in the wrong place for
409 the libraries.
410
411 Since lint targets also make use of LDLIBS, LDLIBS *must* only
412 contain -l and -L directives; all other link-related directives
413 should be put in DYNFLAGS (if they apply only to shared object
414 construction) or LDFLAGS (if they apply in general).
415
416 MAPFILES (if necessary)
417
418 Set to the list of mapfiles used to link each ISA-specific version
419 of your library. This defaults to `$(SRCDIR)/mapfile-vers' in
420 Makefile.lib, so you only need to change this if you have additional
421 mapfiles or your mapfile doesn't follow the standard naming
422 convention. If you have supplemental ISA-dependent mapfiles that
423 reside in the respective <isa> directories, you can augment
424 MAPFILES like this:
425
426 MAPFILES += mapfile-vers
427
428 CPPFLAGS (if necessary)
429
430 Appended with any flags that need to be passed to the C
431 preprocessor (typically -D and -I flags). Since lint macros use
432 CPPFLAGS, CPPFLAGS *must* only contain directives known to the C
433 preprocessor. When compiling MT-safe code, CPPFLAGS *must*
434 include -D_REENTRANT. When compiling large file aware code,
435 CPPFLAGS *must* include -D_FILE_OFFSET_BITS=64.
436
437 CFLAGS
438
439 Appended with any flags that need to be passed to the C compiler.
440 Minimally, append `$(CCVERBOSE)'. Keep in mind that you should
441 add any C preprocessor flags to CPPFLAGS, not CFLAGS.
442
443 CFLAGS64 (if necessary)
444
445 Appended with any flags that need to be passed to the C compiler
446 when compiling 64-bit code. Since all 64-bit code is compiled
447 $(CCVERBOSE), you usually do not need to modify CFLAGS64.
448
449 COPTFLAG (if necessary)
450
451 Set to control the optimization level used by the C compiler when
452 compiling 32-bit code. You should only set this if absolutely
453 necessary, and it should only contain optimization-related
454 settings (or -g).
455
456 COPTFLAG64 (if necessary)
457
458 Set to control the optimization level used by the C compiler when
459 compiling 64-bit code. You should only set this if absolutely
460 necessary, and it should only contain optimization-related
461 settings (or -g).
462
463 LINTFLAGS (if necessary)
464
465 Appended with any flags that need to be passed to lint when
466 linting 32-bit code. You should only modify LINTFLAGS in
467 rare instances where your code cannot (or should not) be fixed.
468
469 LINTFLAGS64 (if necessary)
470
471 Appended with any flags that need to be passed to lint when
472 linting 64-bit code. You should only modify LINTFLAGS64 in
473 rare instances where your code cannot (or should not) be fixed.
474
475 Of course, you may use other macros as necessary.
476
477 The fourth section typically consists of the following targets:
478
479 all
480
481 Build all of the types of the libraries named by LIBS. Must always
482 be the first real target in common Makefile. Since the
483 higher-level Makefiles already contain rules to build all of the
484 different types of libraries, you can usually just specify
485
486 all: $(LIBS)
487
488 though it should be listed as an empty target if LIBS is set by your
489 ISA-specific Makefiles (see above).
490
491 lint
492
493 Use the `lintcheck' rule provided by lib/Makefile.targ to lint the
494 actual library sources. Historically, this target has also been
495 used to build the lint library (using LINTLIB), but that usage is
496 now discouraged. Thus, this rule should be specified as
497
498 lint: lintcheck
499
500 Conspicuously absent from this section are the `clean' and `clobber' targets.
501 These targets are already provided by lib/Makefile.targ and thus should not
502 be provided by your common Makefile. Instead, your common Makefile should
503 list any additional files to remove during a `clean' and `clobber' by
504 appending to the CLEANFILES and CLOBBERFILES macros.
505
506 Once again, here's libinetutil's common Makefile, which shows how many of
507 these directives go together. Note that Makefile.rootfs is included to
508 cause libinetutil.so.1 to be installed in /lib rather than /usr/lib:
509
510 LIBRARY = libinetutil.a
511 VERS = .1
512 OBJECTS = octet.o inetutil4.o ifspec.o ifaddrlist.o eh.o tq.o
513
514 include ../../Makefile.lib
515 include ../../Makefile.rootfs
516
517 LIBS = $(DYNLIB) $(LINTLIB)
518
519 SRCDIR = ../common
520 COMDIR = $(SRC)/common/net/dhcp
521 SRCS = $(COMDIR)/octet.c $(SRCDIR)/inetutil4.c \
522 $(SRCDIR)/ifspec.c $(SRCDIR)/eh.c $(SRCDIR)/tq.c \
523 $(SRCDIR)/ifaddrlist.c
524
525 $(LINTLIB):= SRCS = $(SRCDIR)/$(LINTSRC)
526 LDLIBS += -lsocket -lc
527
528 CFLAGS += $(CCVERBOSE)
529 CPPFLAGS += -I$(SRCDIR)
530
531 .KEEP_STATE:
532
533 all: $(LIBS)
534
535 lint: lintcheck
536
537 pics/%.o: $(COMDIR)/%.c
538 $(COMPILE.c) -o $@ $<
539 $(POST_PROCESS_O)
540
541 include ../../Makefile.targ
542
543 The mapfile for libinetutil is named `mapfile-vers' and resides in $(SRCDIR),
544 so the MAPFILES definition is omitted, defaulting to $(SRCDIR)/mapfile-vers.
545
546 Note that for libinetutil, not all of the object files come from SRCDIR. To
547 support this, an alternate source file directory named COMDIR is defined, and
548 the source files listed in SRCS are specified using both COMDIR and SRCDIR.
549 Additionally, a special build rule is provided to build object files from the
550 sources in COMDIR; the rule uses COMPILE.c and POST_PROCESS_O so that any
551 changes to the compilation and object-post-processing phases will be
552 automatically picked up.
553
554 The ISA-Specific Makefiles
555 --------------------------
556
557 As the name implies, your ISA-specific Makefiles should contain macros and
558 rules that cannot be expressed in an ISA-independent way. Usually, the only
559 rule you will need to put here is `install', which has different dependencies
560 for 32-bit and 64-bit libraries. For instance, here are the ISA-specific
561 Makefiles for libinetutil:
562
563 sparc/Makefile:
564
565 include ../Makefile.com
566
567 install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
568
569 sparcv9/Makefile:
570
571 include ../Makefile.com
572 include ../../Makefile.lib.64
573
574 install: all $(ROOTLIBS64) $(ROOTLINKS64)
575
576 i386/Makefile:
577
578 include ../Makefile.com
579
580 install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
581
582 amd64/Makefile:
583
584 include ../Makefile.com
585 include ../../Makefile.lib.64
586
587 install: all $(ROOTLIBS64) $(ROOTLINKS64)
588
589 Observe that there is no .KEEP_STATE directive in these Makefiles, since all
590 of these Makefiles include libinetutil/Makefile.com, and it already has a
591 .KEEP_STATE directive. Also, note that the 64-bit Makefiles also include
592 Makefile.lib.64, which overrides some of the definitions contained in the
593 higher level Makefiles included by the common Makefile so that 64-bit
594 compiles work correctly.
595
596 CTF Data in Libraries
597 ---------------------
598
599 By default, all position-independent objects are built with CTF data using
600 ctfconvert, which is then merged together using ctfmerge when the shared
601 object is built. All C-source objects processed via ctfmerge need to be
602 processed via ctfconvert or the build will fail. Objects built from non-C
603 sources (such as assembly or C++) are silently ignored for CTF processing.
604
605 Filter libraries that have no source files will need to explicitly disable
606 CTF by setting CTFMERGE_LIB to ":"; see libw/Makefile.com for an example.
607
608 More Information
609 ----------------
610
611 Other issues and questions will undoubtedly arise while you work on your
612 library's Makefiles. To help in this regard, a number of libraries of
613 varying complexity have been updated to follow the guidelines and practices
614 outlined in this document:
615
616 lib/libdhcputil
617
618 Example of a simple 32-bit only library.
619
620 lib/libdhcpagent
621
622 Example of a simple 32-bit only library that obtains its sources
623 from multiple directories.
624
625 lib/ncad_addr
626
627 Example of a simple loadable module.
628
629 lib/libipmp
630
631 Example of a simple library that builds a message catalog.
632
633 lib/libdhcpsvc
634
635 Example of a Makefile hierarchy for a library and a collection
636 of related pluggable modules.
637
638 lib/lvm
639
640 Example of a Makefile hierarchy for a collection of related
641 libraries and pluggable modules.
642
643 Also an example of a Makefile hierarchy that supports the
644 _dc target for domain and category specific messages.
645
646 Of course, if you still have questions, please do not hesitate to send email
647 to the ON gatekeepers.
648 README.mapfiles
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 2006 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
24 #
25 # ident "%Z%%M% %I% %E% SMI"
26 #
27
28 Mapfiles and versioning in ON
29 =============================
30
31 1.0 Objective of this README
32
33 This README describes the engineering practices of creating and updating
34 visible library interfaces. It describes various kinds of actions that
35 typically occur as libraries are evolved, and shows how interface
36 specifications are affected or updated in accordance. It tells you what
37 you must do as a shared library developer if you:
38
39 1. Make interface additions to an existing library
40 - add a Public interface
41 - add a Private interface
42 2. Update an interface in an existing library
43 - remove an existing interface
44 - promote a Private interface to Public
45 - scope a Private interface to local
46 - move an interface from one library to another
47 - copy interfaces which are part of the standard to a new or
48 existing library
49 3. Introduce a new library
50 - source directory hierarchy
51 - creation of the "mapfile-vers" file
52 - Makefiles
53 4. Make an entire library obsolete before end-of-life
54 - introduce SUNWobsolete to the "mapfile-vers" file
55
56 -------------------------------------------------------------------------------
57
58 2.0 What's a mapfile?
59
60 Mapfiles are used to tell the link editor ("ld") all sorts of things about
61 how to generate an executable file or a shared object from a collection of
62 relocatable objects, such as generated by a compiler. For all the gory
63 details, see the Solaris Linker and Libraries Guide, which can be found
64 under http://docs.sun.com.
65
66 Here, we are only concerned with specifying externally-visible interfaces
67 for shared libraries (shared objects) and with specifying their versions
68 for ABI (Application Binary Interface) purposes. For these purposes, we
69 only need to deal with a subset of the mapfile interfaces.
70
71 There should be a "mapfile-vers" file associated with every shared library
72 and it should reside in the common source directory for that library, most
73 often in a "common" directory. This is the usual layout of a library's
74 top-level directory (usr/src/lib/libwombat):
75 Makefile amd64/ i386/ sparcv9/
76 Makefile.com common/ sparc/
77
78 The "common" directory contains the source files and other common files
79 for the library:
80 bat.c libwombat_impl.h mapfile-vers wom.c
81 libwombat.h llib-lwombat util.c wombat.c
82
83 The mapfile's name is, by convention, "mapfile-vers" because it is used
84 for only two purposes: to specify externally-visible interface names while
85 suppressing visibility of all other names, and to specify their respective
86 unique version names.
87
88 -------------------------------------------------------------------------------
89
90 3.0 Contents of mapfile-vers
91
92 The structure of mapfile-vers is best explained by an example
93 (the license notification and copyright notice is omitted here
94 for brevity):
95
96 SUNW_1.2 { # update to libwombat, Solaris 10
97 global:
98 wb_readv;
99 wb_stat;
100 wb_writev;
101 } SUNW_1.1;
102
103 SUNW_1.1 { # first release of libwombat, Solaris 9
104 global:
105 wb_read;
106 wb_write;
107 };
108
109 SUNWprivate { # private libwombat symbols
110 global:
111 wb_add;
112 wb_delete;
113 wb_search;
114 local:
115 *;
116 };
117
118 The SUNW_1.* names are the Public version names for the library.
119 There should be at most one version name for each release of Solaris,
120 with the minor number incremented by one over the previous version.
121
122 If no update to the Public-visible names in the library is made
123 in a given Solaris release, no new version name should be generated
124 for that release. If multiple updates are made to the library at
125 different points in the development of a given release of Solaris,
126 only one version should be used for the entire release.
127
128 So, for example, if an update to libwombat is made in Solaris 11,
129 you would add "SUNW_1.3" at the start of the mapfile:
130
131 SUNW_1.3 { # update to libwombat, Solaris 11
132 global:
133 wb_lseek;
134 } SUNW_1.2;
135
136 Each version must inherit all symbols from its preceding version,
137 specified at the ending "}" for each version. SUNW_1.1 does not
138 inherit any symbols. SUNWprivate, if present, stands alone.
139
140 The two lines in SUNWprivate:
141 local:
142 *;
143 ensure that no symbols other than those listed in the mapfile are
144 visible to clients of the library. If there is no SUNWprivate,
145 these two lines should appear in SUNW_1.1.
146
147 For maintainability, the list of names in each version block should
148 be sorted in dictionary order (sort -d). Please comply.
149
150 In addition to the common mapfile:
151 common/mapfile-vers
152 some libraries require ISA-specific supplemental mapfiles, one in each
153 of the ISA directories:
154 amd64/mapfile-vers
155 i386/mapfile-vers
156 sparc/mapfile-vers
157 sparcv9/mapfile-vers
158 This is necessary only if there are ISA-specific library interfaces not
159 common to all instances of the library. For example, see libproc, or,
160 if you are masochistic, libc or libnsl.
161
162 The ISA-specific mapfiles look like the common mapfile, except that only
163 the ISA-specific names appear. The version names are the same as those
164 in the common mapfile, but only non-empty version instances are present
165 and no inheritance specification is present.
166
167 -------------------------------------------------------------------------------
168
169 4.0 Making interface additions to an existing library
170
171 4.1 Adding a Public interface
172
173 The first engineer to update the existing mapfile-vers file in a release needs
174 to identify the current highest version name and properly increment the minor
175 version number by 1 to be the new version name. If this is the first Public
176 interface in the shared object, a new SUNW_1.1 version name must be introduced.
177
178 The major revision number is incremented whenever an incompatible change is
179 made to an interface. This could be the case if an API changes so dramatically
180 as to invalidate dependencies. This rarely occurs in practice. It also
181 requires changing the suffix of the shared object from, say, .so.1 to .so.2
182 and introducing code to continue to ship the .so.1 version of the library.
183
184 The minor revision number is incremented whenever one or more new interfaces
185 is added to a library. Note that the minor number is not incremented on every
186 putback that makes an interface addition to the library. Rather, it is
187 incremented at most once per (external to Sun) release of the library.
188
189 4.2 Adding a Private interface
190
191 Private interfaces are the non-ABI interfaces of the library. Unlike
192 introducing a Public interface, a new entry is simply added to the
193 SUNWprivate version. No minor number increment is necessary.
194
195 If this interface happens to be the first Private interface introduced
196 into the library, the SUNWprivate version must be created (no major.minor
197 version numbers). It inherits nothing and nothing inherits from it.
198
199 If the library already has Private interfaces, they may have numbered version
200 names like SUNWprivate_m.n (due to errors of the past). If so, just use the
201 highest numbered private version name to version the new interface. There
202 is no need to introduce a new private version name. Be careful not to use
203 a lower numbered private version name; doing so can cause runtime errors
204 (as opposed to load time errors) when running an application with older
205 versions of the library.
206
207 4.3 Adding new public interfaces in an update release
208
209 Adding new public interfaces in an update release requires careful
210 coordination with the next marketing release currently under development.
211 Multiple updates ship during the period before the next marketing release
212 ships, and since it is generally impossible to know the full set of new
213 interfaces in the next marketing release until late in its development
214 (after multiple updates have shipped) it must be assumed that not all
215 interfaces added to the next marketing release will be added to an update.
216
217 Consequently, the new version number for an update cannot be a minor
218 increment, but must be a micro increment. For example, if Release N
219 has version number SUNW_1.3 and Release N+1 will have SUNW_1.4, then
220 interfaces added to an update of Release N must have micro numbers such
221 as SUNW_1.3.1, SUNW_1.3.2, etc. (note that the micro number is not
222 directly tied to the update number: SUNW_1.3.1 may appear in Update 2).
223 The micro versions form an inheritance chain that is inserted between
224 two successive minor versions. For example, the mapfile-vers file for
225 minor release "N+1" to reflect its inclusion of micro releases will
226 look like the following:
227
228 SUNW_1.4 { # release N+1
229 global:
230 ...
231 } SUNW_1.3.2;
232
233 SUNW_1.3.2 { # micro release 2 (e.g., release NU3)
234 global:
235 ...
236 } SUNW_1.3.1;
237
238 SUNW_1.3.1 { # micro release 1 (e.g., release NU2)
239 global:
240 ...
241 } SUNW_1.3;
242
243 SUNW_1.3 { # release N
244 global:
245 ...
246 } SUNW_1.2;
247
248 SUNW_1.2 { # release N-1
249 global:
250 ...
251 } SUNW_1.1;
252
253 SUNW_1.1 { # first release
254 global:
255 ...
256 };
257
258 SUNW_private { # same in all releases
259 global:
260 ...
261 local:
262 *;
263 };
264
265 The corresponding update/patch mapfile-vers file will be identical
266 except for the exclusion of SUNW_1.4.
267
268 Those interfaces which are only present in Release N+1 are always put
269 into the next minor version set, SUNW_1.4.
270
271 Thus when adding a new public interface to an update, both the mapfiles
272 of the update release and next marketing release must be modified to be
273 consistent. The update versions should not be added to the marketing
274 release until the putback to the update release has occurred, to avoid
275 timing problems with the update releases (it's all too easy for projects
276 to slip out of updates, or to change ordering).
277
278 -------------------------------------------------------------------------------
279
280 5.0 How to update an interface in an existing library
281
282 5.1 Removing an existing interface
283
284 5.1.1 Moving a Public interface
285
286 No Public interfaces should ever be removed from any mapfile.
287
288 To move an interface from one library to (say) libc, the code has to be
289 deleted from the library and added to libc, then the mapfile for the
290 library has to have the interface's entry changed from:
291 getfoobar;
292 to:
293 getfoobar = FUNCTION FILTER libc.so.1;
294 See, for example, libnsl's common/mapfile-vers file.
295
296 Follow the rules for adding a new interface for the necessary changes
297 to libc's mapfile to accommodate the moved interface. In particular,
298 the new interface must be added to the current highest libc version.
299
300 To move an entire library into libc, look at what has already been done
301 for libthread, libaio, and librt.
302
303 5.1.2 Removing a Private interface
304
305 Deletion of Private interfaces is allowed, but caution should be taken;
306 it should first be established that the interface is not being used.
307 To remove a Private interface, simply delete the corresponding entry
308 for that symbol from the mapfile's SUNWprivate section.
309
310 Do not forget to delete these Public or Private interfaces from the library's
311 header files as well as from the code that implements the interfaces.
312
313 5.2 Promoting a Private interface to Public
314
315 This is similar to what's done when adding a Public interface. Promoting an
316 existing Private interface to a Public one only requires a change to the
317 existing interface definition. Private interfaces have the symbol version name
318 "SUNWprivate" associated with them. To make the interface a Public one, the
319 interface must be put into a set associated with the current Public release
320 level of the library.
321
322 As an example, if we were modifying libwombat.so.1 and its version in the
323 last release of Solaris was SUNW_1.23, any new ABI introduced in the next
324 release would be put into a version called SUNW_1.24. Therefore, whether
325 you wish to promote an existing Private interface to Public, or to introduce
326 a new Public interface, this (next successive minor numbered version level)
327 would be the version that it would be associated with.
328
329 5.3 Scoping a Private interface local
330
331 Any interfaces not present in the mapfile-vers file will automatically be
332 scoped local (i.e., they will not be visible outside the library). Simply
333 remove the Private interface from the mapfile-vers file and the header file
334 to prevent it from being exported. This may require moving the Private
335 interface into a library-private header file. Scope reduction of Public
336 interfaces is not allowed.
337
338 For the interface to be used in more than one file within the library, it
339 should be in a header file that can be included by each file in the library
340 that uses the interface. For example:
341
342 #include "libprivate.h"
343
344 5.4 How to copy interfaces which are part of a standard to a new or existing
345 library
346
347 SYSVABI and SISCD are reserved version names for interfaces listed in the
348 System V Interface Definition and the Sparc Compliance Definition. Avoid using
349 these version names when copying the implementation of standard interfaces to
350 another library. Instead, use SUNW_1.1 for a new library, and SUNW_m.n for
351 an existing library (where m.n is the next release version; i.e., if the
352 last version was SUNW_1.18, then you should version the interfaces with
353 SUNW_1.19).
354
355 -------------------------------------------------------------------------------
356
357 6.0 Introducing a new library
358
359 6.1 Directories
360
361 The normal discipline for introducing a new library in OS/Net is to create a
362 new subdirectory of /usr/src/lib. The interface definition discipline is to
363 create a common/mapfile-vers file for the new library. If we were introducing
364 a new foo library, libfoo, we'd create /usr/src/lib/libfoo containing:
365 Makefile amd64/ i386/ sparcv9/
366 Makefile.com common/ sparc/
367 The common subdirectory would contain the normal source files plus the
368 mapfile-vers file. See usr/src/lib/README.Makefiles for directions on
369 how to organize the Makefiles.
370
371 6.2 The mapfile
372
373 The new common/mapfile-vers file would contain:
374
375 SUNW_1.1 { # first release of libfoo
376 global:
377 ...
378 };
379
380 SUNWprivate {
381 global:
382 ...
383 local:
384 *;
385 };
386
387 If there are no Public interfaces, the SUNW_1.1 section would be omitted.
388 If there are no Private interfaces, the SUNWprivate section would be
389 omitted and the two lines:
390 local:
391 *;
392 would be moved into SUNW_1.1
393
394 To decide which interfaces are Public (part of the ABI) and which are Private
395 (unstable interfaces not intended to be used by third party applications or
396 unbundled products), the heuristic which works to a first approximation is
397 that if it has a man page then it's Public. Also, it is really the ARC case
398 for the new interfaces that prescribes which interfaces are Public and
399 which are not (hence, which interfaces have man pages and which do not).
400
401 For maintainability, the list of names in each version block should
402 be sorted in dictionary order (sort -d). Please comply.
403
404 -------------------------------------------------------------------------------
405
406 7.0 Make an entire library obsolete
407
408 7.1 Introduce SUNWobsolete version
409
410 Use this version name not for specific interfaces but for marking an entire
411 library as obsolete. The existing public/private version names are left
412 unchanged, but a new SUNWobsolete version is created with no symbols in it.
413 This becomes a tag by which the obsolescence of the library can be recognized.
414 There is no numbering of this version name.
415
416 SUNWobsolete {
417 global:
418 SUNWobsolete; # This is the only way to do it.
419 } SUNW_1.2;
420
421 SUNW_1.2 {
422 ...
423
424 -------------------------------------------------------------------------------
425
426 8.0 Documentation
427
428 For further information, please refer to the following documents:
429
430 "Solaris Linker and Libraries Guide", http://docs.sun.com
431 /shared/ON/general_docs/scoping-rules.fm.ps
432
433 For information on the now-obsolete spec files, used in Solaris releases
434 7 through 10, see:
435 /shared/ON/general_docs/README.spec
436 /shared/ON/general_docs/libspec-rules.ps
437 /shared/ON/general_docs/spectrans/*
438