xref: /titanic_41/usr/src/cmd/mdb/Makefile.module (revision 74e20cfe817b82802b16fac8690dadcda76f54f5)
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 2006 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) $(ZCOMBRELOC)
101LDFLAGS64		+= $(ZTEXT) $(ZCOMBRELOC)
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#
114# kmdb is a kernel module, so we'll use the kernel's build flags.
115$(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
116$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
117
118#
119# Override this to pull source files from another directory
120#
121MODSRCS_DIR = ../../../common/modules/genunix
122
123GROUP = sys
124
125all: $$(TARGETS)
126
127install: all $$(ROOTTGTS)
128
129dmods: install
130
131clean.lint:
132	$(RM) $(LINTFILES)
133
134clean:
135	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
136
137clobber: clean clean.lint
138	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
139
140lint: $$(LINTFILES)
141
142.NO_PARALLEL:
143.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
144	$(TARGETS) $(LINTFILES)
145
146$(MODFILE): dmod .WAIT $(MODOBJS)
147	$(LINK.c) $(GSHARED) $(MODOBJS) -o $@ $(LDLIBS)
148	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
149	$(POST_PROCESS_SO)
150
151#
152# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
153# we try to link them, at build time, against an object that exports the symbols
154# that they can legally use.  The link test object is, however, only built when
155# kmdb itself is built.  Requiring module developers to build kmdb first would
156# be painful, so by default, module-level builds don't do the link test (the
157# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
158# tree can, however, guarantee the construction of kmdb first, and as such can
159# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
160# link test to be run.
161#
162# Developers wanting to force a link test for a single module can use the
163# `linktest' target from within a module directory.
164#
165LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
166
167KMDB_LINKTEST = \
168	$(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
169	$(STANDOBJS) $(LINKTESTOBJ) && \
170	$(RM) $@.linktest
171
172KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
173$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
174
175#
176# Ensure that dmods don't use floating point
177#
178KMDB_FPTEST_CMD = $(KMDB_FPTEST)
179
180$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
181	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
182	$(STANDOBJS)
183	$(KMDB_LINKTEST_CMD)
184	$(KMDB_FPTEST_CMD)
185	$(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
186	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
187
188linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
189	$(KMDB_LINKTEST)
190
191linktest_check:
192	@if [ "$(MDBTGT)" != "kvm" ] ; then \
193		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
194		    >&2 ; \
195		exit 1 ; \
196	fi
197
198#
199# Dynamic rules for object construction
200#
201dmod/%.o kmod/%.o: %.c
202	$(COMPILE.c) -o $@ $<
203	$(CTFCONVERT_O)
204
205dmod/%.o kmod/%.o: ../%.c
206	$(COMPILE.c) -o $@ $<
207	$(CTFCONVERT_O)
208
209dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
210	$(COMPILE.c) -o $@ $<
211	$(CTFCONVERT_O)
212
213dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
214	$(COMPILE.c) -o $@ $<
215	$(CTFCONVERT_O)
216
217#
218# Lint
219#
220dmod/%.ln kmod/%.ln: %.c
221	$(LINT.c) -dirout=$(@D) -c $<
222
223dmod/%.ln kmod/%.ln: ../%.c
224	$(LINT.c) -dirout=$(@D) -c $<
225
226dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
227	$(LINT.c) -dirout=$(@D) -c $<
228
229dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
230	$(LINT.c) -dirout=$(@D) -c $<
231
232#
233# Installation targets
234#
235
236$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
237	$(INS.dir)
238
239$(ROOT)/usr/lib/mdb:
240	$(INS.dir)
241
242$(ROOT)/kernel/kmdb:
243	$(INS.dir)
244
245$(ROOTMOD)/$(MODULE): $(ROOTMOD)
246
247$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
248
249kmod dmod:
250	-@mkdir -p $@
251