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