6172 ::printf should increment dot
[unleashed.git] / usr / src / cmd / mdb / Makefile.module
blobf741cd8278b915a206ec9329f2886364153fd83e
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
22 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23 # Use is subject to license terms.
25 # Copyright (c) 2013 by Delphix. All rights reserved.
26 # Copyright 2015, Joyent, Inc.
29 .KEEP_STATE:
30 .SUFFIXES:
32 include $(SRC)/cmd/mdb/Makefile.tools
34 $(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
35 $(KMOD_SOURCES_DIFFERENT)KMODASMSRCS = $(MODASMSRCS)
37 MODOBJS = $(MODSRCS:%.c=dmod/%.o) $(MODASMSRCS:%.s=dmod/%.o)
38 KMODOBJS = $(KMODSRCS:%.c=kmod/%.o) $(KMODASMSRCS:%.s=kmod/%.o)
40 MODNAME = $(MODULE:%.so=%)
41 KMODULE = $(MODNAME)
43 MODFILE = dmod/$(MODULE)
44 KMODFILE = kmod/$(KMODULE)
47 # The mess below is designed to pick the right set of objects to build and/or
48 # lint.  We have three flavors:
50 #  1. proc and raw modules.  Only $(MODOBJS) are built.
51 #  2. kvm modules for systems without kmdb.  Only $(MODOBJS) are built.
52 #  3. kvm modules for systems with kmdb.  $(MODOBJS) and $(KMODOBJS) are built.
54 # Complicating matters, we'd like to make the distinction between 2 and 3 before
55 # this Makefile is loaded.  By default, we'll assume that all kvm modules should
56 # be built for kmdb.  If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb',
57 # the kmdb variant of the module won't be built.
60 # Which flavors are to be built?
61 TARGETS_kvm_type_       = both  # Build both if $(MODULE_BUILD_TYPE) is unset
62 TARGETS_kvm_type_kmdb   = both
63 TARGETS_kvm_type_mdb    = mdb
64 TARGETS_kvm_type        = $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))
66 # What should we build?
67 TARGETS_kvm_kmdb        = $(KMODFILE)
68 TARGETS_kvm_mdb         = $(MODFILE)
69 TARGETS_kvm_both        = $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
70 TARGETS_kvm             = $(TARGETS_kvm_$(TARGETS_kvm_type))
71 TARGETS_proc            = $(MODFILE)
72 TARGETS_raw             = $(MODFILE)
73 TARGETS                 = $(TARGETS_$(MDBTGT))
75 # Where should we install that which we've built?
76 ROOTTGTS_kvm_type       = $(TARGETS_kvm_type)   # overridden by mdb_ks
77 ROOTTGTS_kvm_kmdb       = $(ROOTKMOD)/$(KMODULE)
78 ROOTTGTS_kvm_mdb        = $(ROOTMOD)/$(MODULE)
79 ROOTTGTS_kvm_both       = $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
80 ROOTTGTS_kvm            = $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
81 ROOTTGTS_proc           = $(ROOTMOD)/$(MODULE)
82 ROOTTGTS_raw            = $(ROOTMOD)/$(MODULE)
83 ROOTTGTS                = $(ROOTTGTS_$(MDBTGT))
85 # What should we lint?
86 KLINTOBJS               = $(KMODOBJS:%.o=%.ln)
87 LINTOBJS                = $(MODOBJS:%.o=%.ln)
89 LINTFILES_kvm_type      = $(TARGETS_kvm_type)
90 LINTFILES_kvm_both      = $(KLINTOBJS) $(LINTOBJS)
91 LINTFILES_kvm_mdb       = $(LINTOBJS)
92 LINTFILES_kvm           = $(LINTFILES_kvm_$(LINTFILES_kvm_type))
93 LINTFILES_proc          = $(LINTOBJS)
94 LINTFILES_raw           = $(LINTOBJS)
95 LINTFILES               = $(LINTFILES_$(MDBTGT))
97 kvm_TGTFLAGS            = -D_KERNEL
98 proc_TGTFLAGS           = -D_USER
100 C99MODE                 = $(C99_ENABLE)
102 CFLAGS                  += $(CCVERBOSE)
103 CFLAGS64                += $(CCVERBOSE)
104 CPPFLAGS                += $($(MDBTGT)_TGTFLAGS) -I../../../common
105 LDFLAGS                 += $(ZTEXT)
106 LDFLAGS64               += $(ZTEXT)
107 ASFLAGS                 += -P
108 AS_CPPFLAGS             += -D_ASM
110 # Module type-specific compiler flags
111 $(MODOBJS) :=                   CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
112 $(MODOBJS) :=                   CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
113 $(KMODOBJS) $(KLINTOBJS) :=     CPPFLAGS += -D_KMDB
114 $(KMODOBJS) :=                  V9CODESIZE = $(CCABS32)
115 $(KMODOBJS) :=                  DTS_ERRNO =
117 # Modules aren't allowed to export symbols
118 MAPFILE         = $(SRC)/cmd/mdb/common/modules/conf/mapfile
120 # Modules typically make external references.  To provide for -zdefs use
121 # and clean ldd(1) processing, explicitly define all external references.
122 MAPFILE-EXT     = $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
125 # kmdb is a kernel module, so we'll use the kernel's build flags.
126 $(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
127 $(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
130 # Override this to pull source files from another directory
132 MODSRCS_DIR = ../../../common/modules/genunix
134 all: $$(TARGETS)
136 install: all $$(ROOTTGTS)
138 dmods: install
140 clean.lint:
141         $(RM) $(LINTFILES) $(MODSRCS:.c=.ln)
143 clean:
144         $(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
146 clobber: clean clean.lint
147         $(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
149 lint: $$(LINTFILES)
151 .NO_PARALLEL:
152 .PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
153         $(TARGETS) $(LINTFILES)
155 $(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
156         $(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \
157             $(MODOBJS) -o $@ $(LDLIBS) -lc
158         $(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
159         $(POST_PROCESS_SO)
162 # kmdb dmods must *not* stray from the module API.  To ensure that they don't,
163 # we try to link them, at build time, against an object that exports the symbols
164 # that they can legally use.  The link test object is, however, only built when
165 # kmdb itself is built.  Requiring module developers to build kmdb first would
166 # be painful, so by default, module-level builds don't do the link test (the
167 # $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
168 # tree can, however, guarantee the construction of kmdb first, and as such can
169 # override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
170 # link test to be run.
172 # Developers wanting to force a link test for a single module can use the
173 # `linktest' target from within a module directory.
175 LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
177 KMDB_LINKTEST = \
178         $(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
179         $(STANDOBJS) $(LINKTESTOBJ) && \
180         $(RM) $@.linktest
182 KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
183 $(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
186 # Ensure that dmods don't use floating point
188 KMDB_FPTEST_CMD = $(KMDB_FPTEST)
190 $(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
191         $(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
192         $(STANDOBJS)
193         $(KMDB_LINKTEST_CMD)
194         $(KMDB_FPTEST_CMD)
195         $(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
196         $(POST_PROCESS)
197         $(SETDYNFLAG) -f DF_1_NOKSYMS $@
199 linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
200         $(KMDB_LINKTEST)
202 linktest_check:
203         @if [ "$(MDBTGT)" != "kvm" ] ; then \
204                 echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
205                     >&2 ; \
206                 exit 1 ; \
207         fi
210 # Dynamic rules for object construction
212 dmod/%.o kmod/%.o: %.c
213         $(COMPILE.c) -o $@ $<
214         $(CTFCONVERT_O)
216 dmod/%.o kmod%.o: %.s
217         $(COMPILE.s) -o $@ $<
218         $(CTFCONVERT_O)
220 dmod/%.o kmod/%.o: ../%.c
221         $(COMPILE.c) -o $@ $<
222         $(CTFCONVERT_O)
224 dmod/%.o kmod%.o: ../%.s
225         $(COMPILE.s) -o $@ $<
226         $(CTFCONVERT_O)
228 dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
229         $(COMPILE.c) -o $@ $<
230         $(CTFCONVERT_O)
232 dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
233         $(COMPILE.s) -o $@ $<
234         $(CTFCONVERT_O)
236 dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
237         $(COMPILE.c) -o $@ $<
238         $(CTFCONVERT_O)
240 dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
241         $(COMPILE.s) -o $@ $<
242         $(CTFCONVERT_O)
245 # Lint
247 dmod/%.ln kmod/%.ln: %.c
248         $(LINT.c) -dirout=$(@D) -c $<
250 dmod/%.ln kmod/%.ln: %.s
251         $(LINT.s) -dirout=$(@D) -c $<
253 dmod/%.ln kmod/%.ln: ../%.c
254         $(LINT.c) -dirout=$(@D) -c $<
256 dmod/%.ln kmod/%.ln: ../%.s
257         $(LINT.s) -dirout=$(@D) -c $<
259 dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
260         $(LINT.c) -dirout=$(@D) -c $<
262 dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.s
263         $(LINT.s) -dirout=$(@D) -c $<
265 dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
266         $(LINT.c) -dirout=$(@D) -c $<
268 dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.s
269         $(LINT.s) -dirout=$(@D) -c $<
272 # Installation targets
275 $(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
276         $(INS.dir)
278 $(ROOT)/usr/lib/mdb:
279         $(INS.dir)
281 $(ROOT)/kernel/kmdb:
282         $(INS.dir)
284 $(ROOTMOD)/$(MODULE): $(ROOTMOD)
286 $(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
288 kmod dmod:
289         -@mkdir -p $@