xref: /titanic_51/usr/src/cmd/mdb/Makefile.module (revision 77dabb95057c6ac2d639808648bf928ca53585f4)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24#
25# Copyright (c) 2013 by Delphix. All rights reserved.
26# Copyright 2015, Joyent, Inc.
27#
28
29.KEEP_STATE:
30.SUFFIXES:
31
32include $(SRC)/cmd/mdb/Makefile.tools
33
34$(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
35$(KMOD_SOURCES_DIFFERENT)KMODASMSRCS = $(MODASMSRCS)
36
37MODOBJS = $(MODSRCS:%.c=dmod/%.o) $(MODASMSRCS:%.s=dmod/%.o)
38KMODOBJS = $(KMODSRCS:%.c=kmod/%.o) $(KMODASMSRCS:%.s=kmod/%.o)
39
40MODNAME = $(MODULE:%.so=%)
41KMODULE = $(MODNAME)
42
43MODFILE = dmod/$(MODULE)
44KMODFILE = kmod/$(KMODULE)
45
46#
47# The mess below is designed to pick the right set of objects to build and/or
48# lint.  We have three flavors:
49#
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.
53#
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.
58#
59
60# Which flavors are to be built?
61TARGETS_kvm_type_	= both	# Build both if $(MODULE_BUILD_TYPE) is unset
62TARGETS_kvm_type_kmdb	= both
63TARGETS_kvm_type_mdb	= mdb
64TARGETS_kvm_type	= $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))
65
66# What should we build?
67TARGETS_kvm_kmdb	= $(KMODFILE)
68TARGETS_kvm_mdb		= $(MODFILE)
69TARGETS_kvm_both	= $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
70TARGETS_kvm		= $(TARGETS_kvm_$(TARGETS_kvm_type))
71TARGETS_proc		= $(MODFILE)
72TARGETS_raw		= $(MODFILE)
73TARGETS			= $(TARGETS_$(MDBTGT))
74
75# Where should we install that which we've built?
76ROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
77ROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
78ROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
79ROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
80ROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
81ROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
82ROOTTGTS_raw		= $(ROOTMOD)/$(MODULE)
83ROOTTGTS		= $(ROOTTGTS_$(MDBTGT))
84
85# What should we lint?
86KLINTOBJS		= $(KMODOBJS:%.o=%.ln)
87LINTOBJS		= $(MODOBJS:%.o=%.ln)
88
89LINTFILES_kvm_type	= $(TARGETS_kvm_type)
90LINTFILES_kvm_both	= $(KLINTOBJS) $(LINTOBJS)
91LINTFILES_kvm_mdb	= $(LINTOBJS)
92LINTFILES_kvm		= $(LINTFILES_kvm_$(LINTFILES_kvm_type))
93LINTFILES_proc		= $(LINTOBJS)
94LINTFILES_raw		= $(LINTOBJS)
95LINTFILES		= $(LINTFILES_$(MDBTGT))
96
97kvm_TGTFLAGS		= -D_KERNEL
98proc_TGTFLAGS		= -D_USER
99
100C99MODE			= $(C99_ENABLE)
101
102CFLAGS			+= $(CCVERBOSE)
103CFLAGS64		+= $(CCVERBOSE)
104CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
105LDFLAGS			+= $(ZTEXT)
106LDFLAGS64		+= $(ZTEXT)
107ASFLAGS			+= -P
108AS_CPPFLAGS		+= -D_ASM
109
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 =
116
117# Modules aren't allowed to export symbols
118MAPFILE		= $(SRC)/cmd/mdb/common/modules/conf/mapfile
119
120# Modules typically make external references.  To provide for -zdefs use
121# and clean ldd(1) processing, explicitly define all external references.
122MAPFILE-EXT	= $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
123
124#
125# kmdb is a kernel module, so we'll use the kernel's build flags.
126$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
127
128#
129# Override this to pull source files from another directory
130#
131MODSRCS_DIR = ../../../common/modules/genunix
132
133all: $$(TARGETS)
134
135install: all $$(ROOTTGTS)
136
137dmods: install
138
139clean.lint:
140	$(RM) $(LINTFILES) $(MODSRCS:.c=.ln)
141
142clean:
143	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
144
145clobber: clean clean.lint
146	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
147
148lint: $$(LINTFILES)
149
150.NO_PARALLEL:
151.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
152	$(TARGETS) $(LINTFILES)
153
154$(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
155	$(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \
156	    $(MODOBJS) -o $@ $(LDLIBS) -lc
157	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
158	$(POST_PROCESS_SO)
159
160#
161# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
162# we try to link them, at build time, against an object that exports the symbols
163# that they can legally use.  The link test object is, however, only built when
164# kmdb itself is built.  Requiring module developers to build kmdb first would
165# be painful, so by default, module-level builds don't do the link test (the
166# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
167# tree can, however, guarantee the construction of kmdb first, and as such can
168# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
169# link test to be run.
170#
171# Developers wanting to force a link test for a single module can use the
172# `linktest' target from within a module directory.
173#
174LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
175
176KMDB_LINKTEST = \
177	$(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
178	$(STANDOBJS) $(LINKTESTOBJ) && \
179	$(RM) $@.linktest
180
181KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
182$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
183
184#
185# Ensure that dmods don't use floating point
186#
187KMDB_FPTEST_CMD = $(KMDB_FPTEST)
188
189$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
190	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
191	$(STANDOBJS)
192	$(KMDB_LINKTEST_CMD)
193	$(KMDB_FPTEST_CMD)
194	$(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
195	$(POST_PROCESS)
196	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
197
198linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
199	$(KMDB_LINKTEST)
200
201linktest_check:
202	@if [ "$(MDBTGT)" != "kvm" ] ; then \
203		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
204		    >&2 ; \
205		exit 1 ; \
206	fi
207
208#
209# Dynamic rules for object construction
210#
211dmod/%.o kmod/%.o: %.c
212	$(COMPILE.c) -o $@ $<
213	$(CTFCONVERT_O)
214
215dmod/%.o kmod%.o: %.s
216	$(COMPILE.s) -o $@ $<
217	$(CTFCONVERT_O)
218
219dmod/%.o kmod/%.o: ../%.c
220	$(COMPILE.c) -o $@ $<
221	$(CTFCONVERT_O)
222
223dmod/%.o kmod%.o: ../%.s
224	$(COMPILE.s) -o $@ $<
225	$(CTFCONVERT_O)
226
227dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
228	$(COMPILE.c) -o $@ $<
229	$(CTFCONVERT_O)
230
231dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
232	$(COMPILE.s) -o $@ $<
233	$(CTFCONVERT_O)
234
235dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
236	$(COMPILE.c) -o $@ $<
237	$(CTFCONVERT_O)
238
239dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
240	$(COMPILE.s) -o $@ $<
241	$(CTFCONVERT_O)
242
243#
244# Lint
245#
246dmod/%.ln kmod/%.ln: %.c
247	$(LINT.c) -dirout=$(@D) -c $<
248
249dmod/%.ln kmod/%.ln: %.s
250	$(LINT.s) -dirout=$(@D) -c $<
251
252dmod/%.ln kmod/%.ln: ../%.c
253	$(LINT.c) -dirout=$(@D) -c $<
254
255dmod/%.ln kmod/%.ln: ../%.s
256	$(LINT.s) -dirout=$(@D) -c $<
257
258dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
259	$(LINT.c) -dirout=$(@D) -c $<
260
261dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.s
262	$(LINT.s) -dirout=$(@D) -c $<
263
264dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
265	$(LINT.c) -dirout=$(@D) -c $<
266
267dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.s
268	$(LINT.s) -dirout=$(@D) -c $<
269
270#
271# Installation targets
272#
273
274$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
275	$(INS.dir)
276
277$(ROOT)/usr/lib/mdb:
278	$(INS.dir)
279
280$(ROOT)/kernel/kmdb:
281	$(INS.dir)
282
283$(ROOTMOD)/$(MODULE): $(ROOTMOD)
284
285$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
286
287kmod dmod:
288	-@mkdir -p $@
289