xref: /titanic_51/usr/src/cmd/mdb/Makefile.module (revision 8eea8e29cc4374d1ee24c25a07f45af132db3499)
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, Version 1.0 only
6# (the "License").  You may not use this file except in compliance
7# with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26# ident	"%Z%%M%	%I%	%E% SMI"
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 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_disasm_kmdb	= $(KMODFILE)
70TARGETS_disasm_mdb	= $(MODFILE)
71TARGETS_disasm_both	= $(TARGETS_disasm_mdb) $(TARGETS_disasm_kmdb)
72TARGETS_disasm		= $(TARGETS_disasm_$(TARGETS_kvm_type))
73TARGETS_proc		= $(MODFILE)
74TARGETS			= $(TARGETS_$(MDBTGT))
75
76# Where should we install that which we've built?
77ROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
78ROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
79ROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
80ROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
81ROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
82ROOTTGTS_disasm_kmdb	= $(ROOTKMOD)/$(KMODULE)
83ROOTTGTS_disasm_mdb	= $(ROOTMOD)/$(MODULE)
84ROOTTGTS_disasm_both	= $(ROOTTGTS_disasm_mdb) $(ROOTTGTS_disasm_kmdb)
85ROOTTGTS_disasm		= $(ROOTTGTS_disasm_$(TARGETS_kvm_type))
86ROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
87ROOTTGTS		= $(ROOTTGTS_$(MDBTGT))
88
89# What should we lint?
90KLINTOBJS		= $(KMODOBJS:%.o=%.ln)
91LINTOBJS		= $(MODOBJS:%.o=%.ln)
92
93LINTFILES_kvm_type	= $(TARGETS_kvm_type)
94LINTFILES_kvm_both	= $(KLINTOBJS) $(LINTOBJS)
95LINTFILES_kvm_mdb	= $(LINTOBJS)
96LINTFILES_kvm		= $(LINTFILES_kvm_$(LINTFILES_kvm_type))
97LINTFILES_disasm_both	= $(KLINTOBJS) $(LINTOBJS)
98LINTFILES_disasm_mdb	= $(LINTOBJS)
99LINTFILES_disasm	= $(LINTFILES_disasm_$(TARGETS_kvm_type))
100LINTFILES_proc		= $(LINTOBJS)
101LINTFILES		= $(LINTFILES_$(MDBTGT))
102
103kvm_TGTFLAGS		= -D_KERNEL
104proc_TGTFLAGS		= -D_USER
105
106CFLAGS			+= $(CCVERBOSE)
107CFLAGS64		+= $(CCVERBOSE)
108CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
109LDFLAGS			+= $(ZTEXT) $(ZCOMBRELOC)
110LDFLAGS64		+= $(ZTEXT) $(ZCOMBRELOC)
111
112# Module type-specific compiler flags
113$(MODOBJS) :=			CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
114$(MODOBJS) :=			CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
115$(KMODOBJS) $(KLINTOBJS) :=	CPPFLAGS += -D_KMDB
116$(KMODOBJS) :=			V9CODESIZE = $(CCABS32)
117$(KMODOBJS) :=			DTS_ERRNO =
118
119# Modules aren't allowed to export symbols
120MAPFILE			= $(SRC)/cmd/mdb/common/modules/conf/mapfile
121
122#
123# kmdb is a kernel module, so we'll use the kernel's build flags.
124$(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
125$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
126
127#
128# Override this to pull source files from another directory
129#
130MODSRCS_DIR = ../../../common/modules/genunix
131
132#
133# Reset STRIPFLAG to the empty string.  MDB modules are intentionally installed
134# with symbol tables in order to help module developers.
135#
136STRIPFLAG =
137GROUP = sys
138
139all: $$(TARGETS)
140
141install: all $$(ROOTTGTS)
142
143dmods: install
144
145clean.lint:
146	$(RM) $(LINTFILES)
147
148clean:
149	$(RM) $(MODOBJS) $(KMODOBJS)
150
151clobber: clean clean.lint
152	$(RM) $(MODFILE) $(KMODFILE)
153
154lint: $$(LINTFILES)
155
156.NO_PARALLEL:
157.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
158	$(TARGETS) $(LINTFILES)
159
160$(MODFILE): dmod .WAIT $(MODOBJS)
161	$(LINK.c) $(GSHARED) $(MODOBJS) -o $@ $(LDLIBS)
162	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
163	$(POST_PROCESS_SO)
164
165#
166# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
167# we try to link them, at build time, against an object that exports the symbols
168# that they can legally use.  The link test object is, however, only built when
169# kmdb itself is built.  Requiring module developers to build kmdb first would
170# be painful, so by default, module-level builds don't do the link test (the
171# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
172# tree can, however, guarantee the construction of kmdb first, and as such can
173# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
174# link test to be run.
175#
176# Developers wanting to force a link test for a single module can use the
177# `linktest' target from within a module directory.
178#
179LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
180
181KMDB_LINKTEST = \
182	$(LD) -zdefs -dy -r -o $@.linktest $(KMODOBJS) $(LINKTESTOBJ) && \
183	$(RM) $@.linktest
184
185KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
186$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
187
188#
189# Ensure that dmods don't use floating point
190#
191KMDB_FPTEST_CMD = $(KMDB_FPTEST)
192
193$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
194	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS)
195	$(KMDB_LINKTEST_CMD)
196	$(KMDB_FPTEST_CMD)
197	$(CTFMERGE) -L VERSION -o $@ $(KMODOBJS)
198	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
199
200linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
201	$(KMDB_LINKTEST)
202
203linktest_check:
204	@if [ "$(MDBTGT)" != "kvm" ] && [ "$(MDBTGT)" != "disasm" ] ; then \
205		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
206		    >&2 ; \
207		exit 1 ; \
208	fi
209
210#
211# Dynamic rules for object construction
212#
213dmod/%.o kmod/%.o: %.c
214	$(COMPILE.c) -o $@ $<
215	$(CTFCONVERT_O)
216
217dmod/%.o kmod/%.o: ../%.c
218	$(COMPILE.c) -o $@ $<
219	$(CTFCONVERT_O)
220
221dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
222	$(COMPILE.c) -o $@ $<
223	$(CTFCONVERT_O)
224
225dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
226	$(COMPILE.c) -o $@ $<
227	$(CTFCONVERT_O)
228
229#
230# Lint
231#
232dmod/%.ln kmod/%.ln: %.c
233	$(LINT.c) -dirout=$(@D) -c $<
234
235dmod/%.ln kmod/%.ln: ../%.c
236	$(LINT.c) -dirout=$(@D) -c $<
237
238dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
239	$(LINT.c) -dirout=$(@D) -c $<
240
241dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
242	$(LINT.c) -dirout=$(@D) -c $<
243
244#
245# Installation targets
246#
247
248$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
249	$(INS.dir)
250
251$(ROOT)/usr/lib/mdb:
252	$(INS.dir)
253
254$(ROOT)/kernel/kmdb:
255	$(INS.dir)
256
257$(ROOTMOD)/$(MODULE): $(ROOTMOD)
258
259$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
260
261kmod dmod:
262	-@mkdir -p $@
263