10Sstevel@tonic-gate# 20Sstevel@tonic-gate# CDDL HEADER START 30Sstevel@tonic-gate# 40Sstevel@tonic-gate# The contents of this file are subject to the terms of the 5*2522Sraf# Common Development and Distribution License (the "License"). 6*2522Sraf# You may not use this file except in compliance with the License. 70Sstevel@tonic-gate# 80Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate# See the License for the specific language governing permissions 110Sstevel@tonic-gate# and limitations under the License. 120Sstevel@tonic-gate# 130Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate# 190Sstevel@tonic-gate# CDDL HEADER END 200Sstevel@tonic-gate# 21*2522Sraf# 22*2522Sraf# Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*2522Sraf# Use is subject to license terms. 24*2522Sraf# 25*2522Sraf# ident "%Z%%M% %I% %E% SMI" 26*2522Sraf# 27*2522Sraf 280Sstevel@tonic-gateWriting Library Makefiles in ON 290Sstevel@tonic-gate=============================== 300Sstevel@tonic-gate 310Sstevel@tonic-gateIntroduction 320Sstevel@tonic-gate------------ 330Sstevel@tonic-gate 340Sstevel@tonic-gateThis document guides you through the gnarly process of writing library 350Sstevel@tonic-gateMakefiles for the ON consolidation. It assumes that you're comfortable with 360Sstevel@tonic-gatemake(1) and are somewhat familiar with the ON Makefile standards outlined in 370Sstevel@tonic-gate/shared/ON/general_docs/make_std.txt. 380Sstevel@tonic-gate 390Sstevel@tonic-gateMakefile Overview 400Sstevel@tonic-gate----------------- 410Sstevel@tonic-gate 420Sstevel@tonic-gateYour library should consist of a hierarchical collection of Makefiles: 430Sstevel@tonic-gate 440Sstevel@tonic-gate lib/<library>/Makefile: 450Sstevel@tonic-gate 460Sstevel@tonic-gate This is your library's top-level Makefile. It should contain rules 470Sstevel@tonic-gate for building any ISA-independent targets, such as installing header 480Sstevel@tonic-gate files and building message catalogs, but should defer all other 490Sstevel@tonic-gate targets to ISA-specific Makefiles. 500Sstevel@tonic-gate 510Sstevel@tonic-gate lib/<library>/Makefile.com 520Sstevel@tonic-gate 530Sstevel@tonic-gate This is your library's common Makefile. It should contain rules 540Sstevel@tonic-gate and macros which are common to all ISAs. This Makefile should never 550Sstevel@tonic-gate be built explicitly, but instead should be included (using the make 560Sstevel@tonic-gate include mechanism) by all of your ISA-specific Makefiles. 570Sstevel@tonic-gate 580Sstevel@tonic-gate lib/<library>/<isa>/Makefile 590Sstevel@tonic-gate 600Sstevel@tonic-gate These are your library's ISA-specific Makefiles, one per ISA 61*2522Sraf (usually sparc and i386, and often sparcv9 and amd64). These 620Sstevel@tonic-gate Makefiles should include your common Makefile and then provide any 630Sstevel@tonic-gate needed ISA-specific rules and definitions, perhaps overriding those 640Sstevel@tonic-gate provided in your common Makefile. 650Sstevel@tonic-gate 660Sstevel@tonic-gateTo simplify their maintenance and construction, $(SRC)/lib has a handful of 670Sstevel@tonic-gateprovided Makefiles that yours must include; the examples provided throughout 680Sstevel@tonic-gatethe document will show how to use them. Please be sure to consult these 690Sstevel@tonic-gateMakefiles before introducing your own custom build macros or rules. 700Sstevel@tonic-gate 710Sstevel@tonic-gate lib/Makefile.lib: 720Sstevel@tonic-gate 730Sstevel@tonic-gate This contains the bulk of the macros for building shared objects. 740Sstevel@tonic-gate 750Sstevel@tonic-gate lib/Makefile.lib.64 760Sstevel@tonic-gate 770Sstevel@tonic-gate This contains macros for building 64-bit objects, and should be 78*2522Sraf included in Makefiles for 64-bit native ISAs. 790Sstevel@tonic-gate 800Sstevel@tonic-gate lib/Makefile.rootfs 810Sstevel@tonic-gate 820Sstevel@tonic-gate This contains macro overrides for libraries that install into /lib 830Sstevel@tonic-gate (rather than /usr/lib). 840Sstevel@tonic-gate 850Sstevel@tonic-gate lib/Makefile.targ 860Sstevel@tonic-gate 870Sstevel@tonic-gate This contains rules for building shared objects. 880Sstevel@tonic-gate 890Sstevel@tonic-gateThe remainder of this document discusses how to write each of your Makefiles 900Sstevel@tonic-gatein detail, and provides examples from the libinetutil library. 910Sstevel@tonic-gate 920Sstevel@tonic-gateThe Library Top-level Makefile 930Sstevel@tonic-gate------------------------------ 940Sstevel@tonic-gate 950Sstevel@tonic-gateAs described above, your top-level library Makefile should contain 960Sstevel@tonic-gaterules for building ISA-independent targets, but should defer the 970Sstevel@tonic-gatebuilding of all other targets to ISA-specific Makefiles. The 980Sstevel@tonic-gateISA-independent targets usually consist of: 990Sstevel@tonic-gate 1000Sstevel@tonic-gate install_h 1010Sstevel@tonic-gate 102*2522Sraf Install all library header files into the proto area. 103*2522Sraf Can be omitted if your library has no header files. 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate check 1060Sstevel@tonic-gate 107*2522Sraf Check all library header files for hdrchk compliance. 108*2522Sraf Can be omitted if your library has no header files. 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate _msg 1110Sstevel@tonic-gate 112*2522Sraf Build and install a message catalog. 113*2522Sraf Can be omitted if your library has no message catalog. 1140Sstevel@tonic-gate 115*2522SrafOf course, other targets (such as `cstyle') are fine as well, as long as 1160Sstevel@tonic-gatethey are ISA-independent. 1170Sstevel@tonic-gate 1180Sstevel@tonic-gateThe ROOTHDRS and CHECKHDRS targets are provided in lib/Makefile.lib to make 1190Sstevel@tonic-gateit easy for you to install and check your library's header files. To use 1200Sstevel@tonic-gatethese targets, your Makefile must set the HDRS to the list of your library's 1210Sstevel@tonic-gateheader files to install and HDRDIR to the their location in the source tree. 1220Sstevel@tonic-gateIn addition, if your header files need to be installed in a location other 1230Sstevel@tonic-gatethan $(ROOT)/usr/include, your Makefile must also set ROOTHDRDIR to the 1240Sstevel@tonic-gateappropriate location in the proto area. Once HDRS, HDRDIR and (optionally) 1250Sstevel@tonic-gateROOTHDRDIR have been set, your Makefile need only contain 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate install_h: $(ROOTHDRS) 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate check: $(CHECKHDRS) 1300Sstevel@tonic-gate 1310Sstevel@tonic-gateto bind the provided targets to the standard `install_h' and `check' rules. 1320Sstevel@tonic-gate 1330Sstevel@tonic-gateSimilar rules are provided (in $(SRC)/Makefile.msg.targ) to make it easy for 1340Sstevel@tonic-gateyou to build and install message catalogs from your library's source files. 1350Sstevel@tonic-gate 1360Sstevel@tonic-gateTo install a catalog into the catalog directory in the proto area, define the 1370Sstevel@tonic-gatePOFILE macro to be the name of your catalog, and specify that the _msg target 1380Sstevel@tonic-gatedepends on $(MSGDOMAINPOFILE). The examples below should clarify this. 1390Sstevel@tonic-gate 1400Sstevel@tonic-gateTo build a message catalog from arbitrarily many message source files, use 1410Sstevel@tonic-gatethe BUILDPO.msgfiles macro. 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate include ../Makefile.lib 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate POFILE = libfoo.po 1460Sstevel@tonic-gate MSGFILES = $(OBJECTS:%.o=%.i) 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate # ... 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate $(POFILE): $(MSGFILES) 1510Sstevel@tonic-gate $(BUILDPO.msgfiles) 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate _msg: $(MSGDOMAINPOFILE) 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate include $(SRC)/Makefile.msg.targ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gateNote that this example doesn't use grep to find message files, since that can 1580Sstevel@tonic-gatemask unreferenced files, and potentially lead to the inclusion of unwanted 1590Sstevel@tonic-gatemessages or omission of intended messages in the catalogs. As such, MSGFILES 1600Sstevel@tonic-gateshould be derived from a known list of objects or sources. 1610Sstevel@tonic-gate 1620Sstevel@tonic-gateIt is usually preferable to run the source through the C preprocessor prior 1630Sstevel@tonic-gateto extracting messages. To do this, use the ".i" suffix, as shown in the 1640Sstevel@tonic-gateabove example. If you need to skip the C preprocessor, just use the native 1650Sstevel@tonic-gate(.[ch]) suffix. 1660Sstevel@tonic-gate 1670Sstevel@tonic-gateThe only time you shouldn't use BUILDPO.msgfiles as the preferred means of 168*2522Srafextracting messages is when you're extracting them from shell scripts; in 1690Sstevel@tonic-gatethat case, you can use the BUILDPO.pofiles macro as explained below. 1700Sstevel@tonic-gate 1710Sstevel@tonic-gateTo build a message catalog from other message catalogs, or from source files 1720Sstevel@tonic-gatethat include shell scripts, use the BUILDPO.pofiles macro: 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate include ../Makefile.lib 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate SUBDIRS = $(MACH) 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate POFILE = libfoo.po 1790Sstevel@tonic-gate POFILES = $(SUBDIRS:%=%/_%.po) 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate _msg := TARGET = _msg 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate # ... 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate $(POFILE): $(POFILES) 1860Sstevel@tonic-gate $(BUILDPO.pofiles) 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate _msg: $(MSGDOMAINPOFILE) 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate include $(SRC)/Makefile.msg.targ 1910Sstevel@tonic-gate 1920Sstevel@tonic-gateThe Makefile above would work in conjunction with the following in its 1930Sstevel@tonic-gatesubdirectories' Makefiles: 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate POFILE = _thissubdir.po 1960Sstevel@tonic-gate MSGFILES = $(OBJECTS:%.o=%.i) 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate $(POFILE): $(MSGFILES) 1990Sstevel@tonic-gate $(BUILDPO.msgfiles) 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate _msg: $(POFILE) 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate include $(SRC)/Makefile.msg.targ 2040Sstevel@tonic-gate 2050Sstevel@tonic-gateSince this POFILE will be combined with those in other subdirectories by the 2060Sstevel@tonic-gateparent Makefile and that merged file will be installed into the proto area 2070Sstevel@tonic-gatevia MSGDOMAINPOFILE, there is no need to use MSGDOMAINPOFILE in this Makefile 2080Sstevel@tonic-gate(in fact, using it would lead to duplicate messages in the catalog). 2090Sstevel@tonic-gate 2100Sstevel@tonic-gateWhen using any of these targets, keep in mind that other macros, like 2110Sstevel@tonic-gateXGETFLAGS and TEXT_DOMAIN may also be set in your Makefile to override or 2120Sstevel@tonic-gateaugment the defaults provided in higher-level Makefiles. 2130Sstevel@tonic-gate 2140Sstevel@tonic-gateAs previously mentioned, you should defer all ISA-specific targets to your 2150Sstevel@tonic-gateISA-specific Makefiles. You can do this by: 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate 1. Setting SUBDIRS to the list of directories to descend into: 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate SUBDIRS = $(MACH) 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate Note that if your library is also built 64-bit, then you should 2220Sstevel@tonic-gate also specify 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate $(BUILD64)SUBDIRS += $(MACH64) 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate so that SUBDIRS contains $(MACH64) if and only if you're compiling 2270Sstevel@tonic-gate on a 64-bit ISA. 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate 2. Providing a common "descend into SUBDIRS" rule: 2300Sstevel@tonic-gate 231*2522Sraf $(SUBDIRS): FRC 2320Sstevel@tonic-gate @cd $@; pwd; $(MAKE) $(TARGET) 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate FRC: 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate 3. Providing a collection of conditional assignments that set TARGET 2370Sstevel@tonic-gate appropriately: 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate all := TARGET= all 2400Sstevel@tonic-gate clean := TARGET= clean 2410Sstevel@tonic-gate clobber := TARGET= clobber 2420Sstevel@tonic-gate install := TARGET= install 2430Sstevel@tonic-gate lint := TARGET= lint 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate The order doesn't matter, but alphabetical is preferable. 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate 4. Having the aforementioned targets depend on SUBDIRS: 2480Sstevel@tonic-gate 249*2522Sraf all clean clobber install lint: $(SUBDIRS) 2500Sstevel@tonic-gate 251*2522Sraf The `all' target must be listed first so that make uses it as the 252*2522Sraf default target; the others might as well be listed alphabetically. 2530Sstevel@tonic-gate 2540Sstevel@tonic-gateAs an example of how all of this goes together, here's libinetutil's 255*2522Sraftop-level library Makefile (license notice and copyright omitted): 2560Sstevel@tonic-gate 257*2522Sraf include ../Makefile.lib 2580Sstevel@tonic-gate 259*2522Sraf HDRS = libinetutil.h 260*2522Sraf HDRDIR = common 261*2522Sraf SUBDIRS = $(MACH) 262*2522Sraf $(BUILD64)SUBDIRS += $(MACH64) 2630Sstevel@tonic-gate 264*2522Sraf all := TARGET = all 265*2522Sraf clean := TARGET = clean 266*2522Sraf clobber := TARGET = clobber 267*2522Sraf install := TARGET = install 268*2522Sraf lint := TARGET = lint 2690Sstevel@tonic-gate 270*2522Sraf .KEEP_STATE: 2710Sstevel@tonic-gate 272*2522Sraf all clean clobber install lint: $(SUBDIRS) 2730Sstevel@tonic-gate 274*2522Sraf install_h: $(ROOTHDRS) 2750Sstevel@tonic-gate 276*2522Sraf check: $(CHECKHDRS) 2770Sstevel@tonic-gate 278*2522Sraf $(SUBDIRS): FRC 279*2522Sraf @cd $@; pwd; $(MAKE) $(TARGET) 2800Sstevel@tonic-gate 281*2522Sraf FRC: 2820Sstevel@tonic-gate 283*2522Sraf include ../Makefile.targ 2840Sstevel@tonic-gate 2850Sstevel@tonic-gateThe Common Makefile 2860Sstevel@tonic-gate------------------- 2870Sstevel@tonic-gate 2880Sstevel@tonic-gateIn concept, your common Makefile should contain all of the rules and 2890Sstevel@tonic-gatedefinitions that are the same on all ISAs. However, for reasons of 2900Sstevel@tonic-gatemaintainability and cleanliness, you're encouraged to place even 2910Sstevel@tonic-gateISA-dependent rules and definitions, as long you express them in an 292*2522SrafISA-independent way (e.g., by using $(MACH), $(TARGETMACH), and their kin). 293*2522Sraf(TARGETMACH is the same as MACH for 32-bit targets, and the same as MACH64 294*2522Sraffor 64-bit targets). 2950Sstevel@tonic-gate 2960Sstevel@tonic-gateThe common Makefile can be conceptually split up into four sections: 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate 1. A copyright and comments section. Please see the prototype 2990Sstevel@tonic-gate files in usr/src/prototypes for examples of how to format the 3000Sstevel@tonic-gate copyright message properly. For brevity and clarity, this 3010Sstevel@tonic-gate section has been omitted from the examples shown here. 3020Sstevel@tonic-gate 3030Sstevel@tonic-gate 2. A list of macros that must be defined prior to the inclusion of 3040Sstevel@tonic-gate Makefile.lib. This section is conceptually terminated by the 3050Sstevel@tonic-gate inclusion of Makefile.lib, followed, if necessary, by the 3060Sstevel@tonic-gate inclusion of Makefile.rootfs (only if the library is to be 3070Sstevel@tonic-gate installed in /lib rather than the default /usr/lib). 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate 3. A list of macros that need not be defined prior to the inclusion 3100Sstevel@tonic-gate of Makefile.lib (or which must be defined following the inclusion 3110Sstevel@tonic-gate of Makefile.lib, to override or augment its definitions). This 3120Sstevel@tonic-gate section is conceptually terminated by the .KEEP_STATE directive. 3130Sstevel@tonic-gate 3140Sstevel@tonic-gate 4. A list of targets. 3150Sstevel@tonic-gate 3160Sstevel@tonic-gateThe first section is self-explanatory. The second typically consists of the 3170Sstevel@tonic-gatefollowing macros: 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate LIBRARY 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate Set to the name of the static version of your library, such 3220Sstevel@tonic-gate as `libinetutil.a'. You should always specify the `.a' suffix, 3230Sstevel@tonic-gate since pattern-matching rules in higher-level Makefiles rely on it, 3240Sstevel@tonic-gate even though static libraries are not normally built in ON, and 3250Sstevel@tonic-gate are never installed in the proto area. Note that the LIBS macro 3260Sstevel@tonic-gate (described below) controls the types of libraries that are built 3270Sstevel@tonic-gate when building your library. 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate If you are building a loadable module (i.e., a shared object that 3300Sstevel@tonic-gate is only linked at runtime with dlopen(3dl)), specify the name of 3310Sstevel@tonic-gate the loadable module with a `.a' suffix, such as `devfsadm_mod.a'. 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate VERS 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate Set to the version of your shared library, such as `.1'. You 3360Sstevel@tonic-gate actually do not need to set this prior to the inclusion of 3370Sstevel@tonic-gate Makefile.lib, but it is good practice to do so since VERS and 3380Sstevel@tonic-gate LIBRARY are so closely related. 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate OBJECTS 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate Set to the list of object files contained in your library, such as 3430Sstevel@tonic-gate `a.o b.o'. Usually, this will be the same as your library's source 3440Sstevel@tonic-gate files (except with .o extensions), but if your library compiles 3450Sstevel@tonic-gate source files outside of the library directory itself, it will 3460Sstevel@tonic-gate differ. We'll see an example of this with libinetutil. 3470Sstevel@tonic-gate 3480Sstevel@tonic-gateThe third section typically consists of the following macros: 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate LIBS 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate Set to the list of the types of libraries to build when building 3530Sstevel@tonic-gate your library. For dynamic libraries, you should set this to 3540Sstevel@tonic-gate `$(DYNLIB) $(LINTLIB)' so that a dynamic library and lint library 3550Sstevel@tonic-gate are built. For loadable modules, you should just list DYNLIB, 3560Sstevel@tonic-gate since there's no point in building a lint library for libraries 3570Sstevel@tonic-gate that are never linked at compile-time. 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate If your library needs to be built as a static library (typically 3600Sstevel@tonic-gate to be used in other parts of the build), you should set LIBS to 3610Sstevel@tonic-gate `$(LIBRARY)'. However, you should do this only when absolutely 3620Sstevel@tonic-gate necessary, and you must *never* ship static libraries to customers. 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate ROOTLIBDIR (if your library installs to a nonstandard directory) 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate Set to the directory your 32-bit shared objects will install into 3670Sstevel@tonic-gate with the standard $(ROOTxxx) macros. Since this defaults to 3680Sstevel@tonic-gate $(ROOT)/usr/lib ($(ROOT)/lib if you included Makefile.rootfs), 3690Sstevel@tonic-gate you usually do not need to set this. 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate ROOTLIBDIR64 (if your library installs to a nonstandard directory) 3720Sstevel@tonic-gate 3730Sstevel@tonic-gate Set to the directory your 64-bit shared objects will install into 3740Sstevel@tonic-gate with the standard $(ROOTxxx64) macros. Since this defaults to 3750Sstevel@tonic-gate $(ROOT)/usr/lib/$(MACH64) ($(ROOT)/lib/$(MACH64) if you included 3760Sstevel@tonic-gate Makefile.rootfs), you usually do not need to set this. 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate SRCDIR 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate Set to the directory containing your library's source files, such 3810Sstevel@tonic-gate as `../common'. Because this Makefile is actually included from 3820Sstevel@tonic-gate your ISA-specific Makefiles, make sure you specify the directory 3830Sstevel@tonic-gate relative to your library's <isa> directory. 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate SRCS (if necessary) 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate Set to the list of source files required to build your library. 3880Sstevel@tonic-gate This defaults to $(OBJECTS:%.o=$(SRCDIR)/%.c) in Makefile.lib, so 3890Sstevel@tonic-gate you only need to set this when source files from directories other 3900Sstevel@tonic-gate than SRCDIR are needed. Keep in mind that SRCS should be set to a 3910Sstevel@tonic-gate list of source file *pathnames*, not just a list of filenames. 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate LINTLIB-specific SRCS (required if building a lint library) 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate Set to a special "lint stubs" file to use when constructing your 3960Sstevel@tonic-gate library's lint library. The lint stubs file must be used to 3970Sstevel@tonic-gate guarantee that programs that link against your library will be able 3980Sstevel@tonic-gate to lint clean. To do this, you must conditionally set SRCS to use 3990Sstevel@tonic-gate your stubs file by specifying `LINTLIB := SRCS= $(SRCDIR)/$(LINTSRC)' 4000Sstevel@tonic-gate in your Makefile. Of course, you do not need to set this if your 4010Sstevel@tonic-gate library does not build a lint library. 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate LDLIBS 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate Appended with the list of libraries and library directories needed 4060Sstevel@tonic-gate to build your library; minimally "-lc". Note that this should 4070Sstevel@tonic-gate *never* be set, since that will inadvertently clear the library 4080Sstevel@tonic-gate search path, causing the linker to look in the wrong place for 4090Sstevel@tonic-gate the libraries. 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate Since lint targets also make use of LDLIBS, LDLIBS *must* only 4120Sstevel@tonic-gate contain -l and -L directives; all other link-related directives 4130Sstevel@tonic-gate should be put in DYNFLAGS (if they apply only to shared object 4140Sstevel@tonic-gate construction) or LDFLAGS (if they apply in general). 4150Sstevel@tonic-gate 416*2522Sraf MAPFILES (if necessary) 4170Sstevel@tonic-gate 418*2522Sraf Set to the list of mapfiles used to link each ISA-specific version 419*2522Sraf of your library. This defaults to `$(SRCDIR)/mapfile-vers' in 420*2522Sraf Makefile.lib, so you only need to change this if you have additional 421*2522Sraf mapfiles or your mapfile doesn't follow the standard naming 422*2522Sraf convention. If you have supplemental ISA-dependent mapfiles that 423*2522Sraf reside in the respective <isa> directories, you can augment 424*2522Sraf MAPFILES like this: 4250Sstevel@tonic-gate 426*2522Sraf MAPFILES += mapfile-vers 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate CPPFLAGS (if necessary) 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate Appended with any flags that need to be passed to the C 4310Sstevel@tonic-gate preprocessor (typically -D and -I flags). Since lint macros use 4320Sstevel@tonic-gate CPPFLAGS, CPPFLAGS *must* only contain directives known to the C 4330Sstevel@tonic-gate preprocessor. When compiling MT-safe code, CPPFLAGS *must* 4340Sstevel@tonic-gate include -D_REENTRANT. When compiling large file aware code, 4350Sstevel@tonic-gate CPPFLAGS *must* include -D_FILE_OFFSET_BITS=64. 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate CFLAGS 4380Sstevel@tonic-gate 4390Sstevel@tonic-gate Appended with any flags that need to be passed to the C compiler. 4400Sstevel@tonic-gate Minimally, append `$(CCVERBOSE)'. Keep in mind that you should 4410Sstevel@tonic-gate add any C preprocessor flags to CPPFLAGS, not CFLAGS. 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate CFLAGS64 (if necessary) 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate Appended with any flags that need to be passed to the C compiler 4460Sstevel@tonic-gate when compiling 64-bit code. Since all 64-bit code is compiled 4470Sstevel@tonic-gate $(CCVERBOSE), you usually do not need to modify CFLAGS64. 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate COPTFLAG (if necessary) 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate Set to control the optimization level used by the C compiler when 4520Sstevel@tonic-gate compiling 32-bit code. You should only set this if absolutely 4530Sstevel@tonic-gate necessary, and it should only contain optimization-related 4540Sstevel@tonic-gate settings (or -g). 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate COPTFLAG64 (if necessary) 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate Set to control the optimization level used by the C compiler when 4590Sstevel@tonic-gate compiling 64-bit code. You should only set this if absolutely 4600Sstevel@tonic-gate necessary, and it should only contain optimization-related 4610Sstevel@tonic-gate settings (or -g). 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate LINTFLAGS (if necessary) 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate Appended with any flags that need to be passed to lint when 4660Sstevel@tonic-gate linting 32-bit code. You should only modify LINTFLAGS in 4670Sstevel@tonic-gate rare instances where your code cannot (or should not) be fixed. 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate LINTFLAGS64 (if necessary) 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate Appended with any flags that need to be passed to lint when 4720Sstevel@tonic-gate linting 64-bit code. You should only modify LINTFLAGS64 in 4730Sstevel@tonic-gate rare instances where your code cannot (or should not) be fixed. 4740Sstevel@tonic-gate 4750Sstevel@tonic-gateOf course, you may use other macros as necessary. 4760Sstevel@tonic-gate 4770Sstevel@tonic-gateThe fourth section typically consists of the following targets: 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate all 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate Build all of the types of the libraries named by LIBS. Must always 4820Sstevel@tonic-gate be the first real target in common Makefile. Since the 4830Sstevel@tonic-gate higher-level Makefiles already contain rules to build all of the 4840Sstevel@tonic-gate different types of libraries, you can usually just specify 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate all: $(LIBS) 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate though it should be listed as an empty target if LIBS is set by your 4890Sstevel@tonic-gate ISA-specific Makefiles (see above). 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate lint 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate Use the `lintcheck' rule provided by lib/Makefile.targ to lint the 4940Sstevel@tonic-gate actual library sources. Historically, this target has also been 4950Sstevel@tonic-gate used to build the lint library (using LINTLIB), but that usage is 4960Sstevel@tonic-gate now discouraged. Thus, this rule should be specified as 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate lint: lintcheck 4990Sstevel@tonic-gate 5000Sstevel@tonic-gateConspicuously absent from this section are the `clean' and `clobber' targets. 5010Sstevel@tonic-gateThese targets are already provided by lib/Makefile.targ and thus should not 5020Sstevel@tonic-gatebe provided by your common Makefile. Instead, your common Makefile should 5030Sstevel@tonic-gatelist any additional files to remove during a `clean' and `clobber' by 5040Sstevel@tonic-gateappending to the CLEANFILES and CLOBBERFILES macros. 5050Sstevel@tonic-gate 5060Sstevel@tonic-gateOnce again, here's libinetutil's common Makefile, which shows how many of 5070Sstevel@tonic-gatethese directives go together. Note that Makefile.rootfs is included to 5080Sstevel@tonic-gatecause libinetutil.so.1 to be installed in /lib rather than /usr/lib: 5090Sstevel@tonic-gate 510*2522Sraf LIBRARY = libinetutil.a 511*2522Sraf VERS = .1 512*2522Sraf OBJECTS = octet.o inetutil4.o ifspec.o ifaddrlist.o eh.o tq.o 513*2522Sraf 514*2522Sraf include ../../Makefile.lib 515*2522Sraf include ../../Makefile.rootfs 516*2522Sraf 517*2522Sraf LIBS = $(DYNLIB) $(LINTLIB) 5180Sstevel@tonic-gate 519*2522Sraf SRCDIR = ../common 520*2522Sraf COMDIR = $(SRC)/common/net/dhcp 521*2522Sraf SRCS = $(COMDIR)/octet.c $(SRCDIR)/inetutil4.c \ 522*2522Sraf $(SRCDIR)/ifspec.c $(SRCDIR)/eh.c $(SRCDIR)/tq.c \ 523*2522Sraf $(SRCDIR)/ifaddrlist.c 5240Sstevel@tonic-gate 525*2522Sraf $(LINTLIB):= SRCS = $(SRCDIR)/$(LINTSRC) 526*2522Sraf LDLIBS += -lsocket -lc 5270Sstevel@tonic-gate 528*2522Sraf CFLAGS += $(CCVERBOSE) 529*2522Sraf CPPFLAGS += -I$(SRCDIR) 5300Sstevel@tonic-gate 531*2522Sraf .KEEP_STATE: 5320Sstevel@tonic-gate 533*2522Sraf all: $(LIBS) 534*2522Sraf 535*2522Sraf lint: lintcheck 5360Sstevel@tonic-gate 537*2522Sraf pics/%.o: $(COMDIR)/%.c 538*2522Sraf $(COMPILE.c) -o $@ $< 539*2522Sraf $(POST_PROCESS_O) 5400Sstevel@tonic-gate 541*2522Sraf include ../../Makefile.targ 5420Sstevel@tonic-gate 543*2522SrafThe mapfile for libinetutil is named `mapfile-vers' and resides in $(SRCDIR), 544*2522Srafso the MAPFILES definition is omitted, defaulting to $(SRCDIR)/mapfile-vers. 5450Sstevel@tonic-gate 5460Sstevel@tonic-gateNote that for libinetutil, not all of the object files come from SRCDIR. To 5470Sstevel@tonic-gatesupport this, an alternate source file directory named COMDIR is defined, and 5480Sstevel@tonic-gatethe source files listed in SRCS are specified using both COMDIR and SRCDIR. 5490Sstevel@tonic-gateAdditionally, a special build rule is provided to build object files from the 5500Sstevel@tonic-gatesources in COMDIR; the rule uses COMPILE.c and POST_PROCESS_O so that any 5510Sstevel@tonic-gatechanges to the compilation and object-post-processing phases will be 5520Sstevel@tonic-gateautomatically picked up. 5530Sstevel@tonic-gate 5540Sstevel@tonic-gateThe ISA-Specific Makefiles 5550Sstevel@tonic-gate-------------------------- 5560Sstevel@tonic-gate 5570Sstevel@tonic-gateAs the name implies, your ISA-specific Makefiles should contain macros and 5580Sstevel@tonic-gaterules that cannot be expressed in an ISA-independent way. Usually, the only 5590Sstevel@tonic-gaterule you will need to put here is `install', which has different dependencies 5600Sstevel@tonic-gatefor 32-bit and 64-bit libraries. For instance, here are the ISA-specific 5610Sstevel@tonic-gateMakefiles for libinetutil: 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate sparc/Makefile: 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate include ../Makefile.com 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate sparcv9/Makefile: 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate include ../Makefile.com 5720Sstevel@tonic-gate include ../../Makefile.lib.64 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate install: all $(ROOTLIBS64) $(ROOTLINKS64) 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate i386/Makefile: 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate include ../Makefile.com 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT) 5810Sstevel@tonic-gate 582*2522Sraf amd64/Makefile: 583*2522Sraf 584*2522Sraf include ../Makefile.com 585*2522Sraf include ../../Makefile.lib.64 586*2522Sraf 587*2522Sraf install: all $(ROOTLIBS64) $(ROOTLINKS64) 588*2522Sraf 5890Sstevel@tonic-gateObserve that there is no .KEEP_STATE directive in these Makefiles, since all 5900Sstevel@tonic-gateof these Makefiles include libinetutil/Makefile.com, and it already has a 591*2522Sraf.KEEP_STATE directive. Also, note that the 64-bit Makefiles also include 5920Sstevel@tonic-gateMakefile.lib.64, which overrides some of the definitions contained in the 5930Sstevel@tonic-gatehigher level Makefiles included by the common Makefile so that 64-bit 5940Sstevel@tonic-gatecompiles work correctly. 5950Sstevel@tonic-gate 5960Sstevel@tonic-gateCTF Data in Libraries 5970Sstevel@tonic-gate--------------------- 5980Sstevel@tonic-gate 599*2522SrafBy default, all position-independent objects are built with CTF data using 6000Sstevel@tonic-gatectfconvert, which is then merged together using ctfmerge when the shared 6010Sstevel@tonic-gateobject is built. All C-source objects processed via ctfmerge need to be 6020Sstevel@tonic-gateprocessed via ctfconvert or the build will fail. Objects built from non-C 6030Sstevel@tonic-gatesources (such as assembly or C++) are silently ignored for CTF processing. 6040Sstevel@tonic-gate 6050Sstevel@tonic-gateFilter libraries that have no source files will need to explicitly disable 6060Sstevel@tonic-gateCTF by setting CTFMERGE_LIB to ":"; see libw/Makefile.com for an example. 6070Sstevel@tonic-gate 6080Sstevel@tonic-gateMore Information 6090Sstevel@tonic-gate---------------- 6100Sstevel@tonic-gate 6110Sstevel@tonic-gateOther issues and questions will undoubtedly arise while you work on your 6120Sstevel@tonic-gatelibrary's Makefiles. To help in this regard, a number of libraries of 6130Sstevel@tonic-gatevarying complexity have been updated to follow the guidelines and practices 6140Sstevel@tonic-gateoutlined in this document: 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate lib/libdhcputil 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate Example of a simple 32-bit only library. 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate lib/libdhcpagent 6210Sstevel@tonic-gate 6220Sstevel@tonic-gate Example of a simple 32-bit only library that obtains its sources 6230Sstevel@tonic-gate from multiple directories. 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate lib/ncad_addr 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate Example of a simple loadable module. 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate lib/libipmp 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate Example of a simple library that builds a message catalog. 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate lib/libdhcpsvc 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate Example of a Makefile hierarchy for a library and a collection 6360Sstevel@tonic-gate of related pluggable modules. 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate lib/lvm 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate Example of a Makefile hierarchy for a collection of related 6410Sstevel@tonic-gate libraries and pluggable modules. 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate Also an example of a Makefile hierarchy that supports the 6440Sstevel@tonic-gate _dc target for domain and category specific messages. 6450Sstevel@tonic-gate 6460Sstevel@tonic-gateOf course, if you still have questions, please do not hesitate to send email 6470Sstevel@tonic-gateto the ON gatekeepers. 648