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