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