xref: /titanic_44/usr/src/cmd/mdb/Makefile.module (revision 48a4016cae8aa2b8b3d8b258eb22e0c781912bed)
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) := CFLAGS += $(STAND_FLAGS_32)
127$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
128
129#
130# Override this to pull source files from another directory
131#
132MODSRCS_DIR = ../../../common/modules/genunix
133
134all: $$(TARGETS)
135
136install: all $$(ROOTTGTS)
137
138dmods: install
139
140clean.lint:
141	$(RM) $(LINTFILES) $(MODSRCS:.c=.ln)
142
143clean:
144	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
145
146clobber: clean clean.lint
147	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
148
149lint: $$(LINTFILES)
150
151.NO_PARALLEL:
152.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
153	$(TARGETS) $(LINTFILES)
154
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)
160
161#
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.
171#
172# Developers wanting to force a link test for a single module can use the
173# `linktest' target from within a module directory.
174#
175LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
176
177KMDB_LINKTEST = \
178	$(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
179	$(STANDOBJS) $(LINKTESTOBJ) && \
180	$(RM) $@.linktest
181
182KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
183$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
184
185#
186# Ensure that dmods don't use floating point
187#
188KMDB_FPTEST_CMD = $(KMDB_FPTEST)
189
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 $@
198
199linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
200	$(KMDB_LINKTEST)
201
202linktest_check:
203	@if [ "$(MDBTGT)" != "kvm" ] ; then \
204		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
205		    >&2 ; \
206		exit 1 ; \
207	fi
208
209#
210# Dynamic rules for object construction
211#
212dmod/%.o kmod/%.o: %.c
213	$(COMPILE.c) -o $@ $<
214	$(CTFCONVERT_O)
215
216dmod/%.o kmod%.o: %.s
217	$(COMPILE.s) -o $@ $<
218	$(CTFCONVERT_O)
219
220dmod/%.o kmod/%.o: ../%.c
221	$(COMPILE.c) -o $@ $<
222	$(CTFCONVERT_O)
223
224dmod/%.o kmod%.o: ../%.s
225	$(COMPILE.s) -o $@ $<
226	$(CTFCONVERT_O)
227
228dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
229	$(COMPILE.c) -o $@ $<
230	$(CTFCONVERT_O)
231
232dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
233	$(COMPILE.s) -o $@ $<
234	$(CTFCONVERT_O)
235
236dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
237	$(COMPILE.c) -o $@ $<
238	$(CTFCONVERT_O)
239
240dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
241	$(COMPILE.s) -o $@ $<
242	$(CTFCONVERT_O)
243
244#
245# Lint
246#
247dmod/%.ln kmod/%.ln: %.c
248	$(LINT.c) -dirout=$(@D) -c $<
249
250dmod/%.ln kmod/%.ln: %.s
251	$(LINT.s) -dirout=$(@D) -c $<
252
253dmod/%.ln kmod/%.ln: ../%.c
254	$(LINT.c) -dirout=$(@D) -c $<
255
256dmod/%.ln kmod/%.ln: ../%.s
257	$(LINT.s) -dirout=$(@D) -c $<
258
259dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
260	$(LINT.c) -dirout=$(@D) -c $<
261
262dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.s
263	$(LINT.s) -dirout=$(@D) -c $<
264
265dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
266	$(LINT.c) -dirout=$(@D) -c $<
267
268dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.s
269	$(LINT.s) -dirout=$(@D) -c $<
270
271#
272# Installation targets
273#
274
275$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
276	$(INS.dir)
277
278$(ROOT)/usr/lib/mdb:
279	$(INS.dir)
280
281$(ROOT)/kernel/kmdb:
282	$(INS.dir)
283
284$(ROOTMOD)/$(MODULE): $(ROOTMOD)
285
286$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
287
288kmod dmod:
289	-@mkdir -p $@
290