xref: /titanic_50/usr/src/cmd/mdb/Makefile.module (revision dd33c4e482cc902d14d3ad7f44931dc0e195a861)
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 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_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_raw		= $(MODFILE)
75TARGETS			= $(TARGETS_$(MDBTGT))
76
77# Where should we install that which we've built?
78ROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
79ROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
80ROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
81ROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
82ROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
83ROOTTGTS_disasm_kmdb	= $(ROOTKMOD)/$(KMODULE)
84ROOTTGTS_disasm_mdb	= $(ROOTMOD)/$(MODULE)
85ROOTTGTS_disasm_both	= $(ROOTTGTS_disasm_mdb) $(ROOTTGTS_disasm_kmdb)
86ROOTTGTS_disasm		= $(ROOTTGTS_disasm_$(TARGETS_kvm_type))
87ROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
88ROOTTGTS_raw		= $(ROOTMOD)/$(MODULE)
89ROOTTGTS		= $(ROOTTGTS_$(MDBTGT))
90
91# What should we lint?
92KLINTOBJS		= $(KMODOBJS:%.o=%.ln)
93LINTOBJS		= $(MODOBJS:%.o=%.ln)
94
95LINTFILES_kvm_type	= $(TARGETS_kvm_type)
96LINTFILES_kvm_both	= $(KLINTOBJS) $(LINTOBJS)
97LINTFILES_kvm_mdb	= $(LINTOBJS)
98LINTFILES_kvm		= $(LINTFILES_kvm_$(LINTFILES_kvm_type))
99LINTFILES_disasm_both	= $(KLINTOBJS) $(LINTOBJS)
100LINTFILES_disasm_mdb	= $(LINTOBJS)
101LINTFILES_disasm	= $(LINTFILES_disasm_$(TARGETS_kvm_type))
102LINTFILES_proc		= $(LINTOBJS)
103LINTFILES_raw		= $(LINTOBJS)
104LINTFILES		= $(LINTFILES_$(MDBTGT))
105
106kvm_TGTFLAGS		= -D_KERNEL
107proc_TGTFLAGS		= -D_USER
108
109CFLAGS			+= $(CCVERBOSE)
110CFLAGS64		+= $(CCVERBOSE)
111CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
112LDFLAGS			+= $(ZTEXT) $(ZCOMBRELOC)
113LDFLAGS64		+= $(ZTEXT) $(ZCOMBRELOC)
114
115# Module type-specific compiler flags
116$(MODOBJS) :=			CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
117$(MODOBJS) :=			CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
118$(KMODOBJS) $(KLINTOBJS) :=	CPPFLAGS += -D_KMDB
119$(KMODOBJS) :=			V9CODESIZE = $(CCABS32)
120$(KMODOBJS) :=			DTS_ERRNO =
121
122# Modules aren't allowed to export symbols
123MAPFILE			= $(SRC)/cmd/mdb/common/modules/conf/mapfile
124
125#
126# kmdb is a kernel module, so we'll use the kernel's build flags.
127$(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
128$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
129
130#
131# Override this to pull source files from another directory
132#
133MODSRCS_DIR = ../../../common/modules/genunix
134
135GROUP = sys
136
137all: $$(TARGETS)
138
139install: all $$(ROOTTGTS)
140
141dmods: install
142
143clean.lint:
144	$(RM) $(LINTFILES)
145
146clean:
147	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
148
149clobber: clean clean.lint
150	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
151
152lint: $$(LINTFILES)
153
154.NO_PARALLEL:
155.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
156	$(TARGETS) $(LINTFILES)
157
158$(MODFILE): dmod .WAIT $(MODOBJS)
159	$(LINK.c) $(GSHARED) $(MODOBJS) -o $@ $(LDLIBS)
160	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
161	$(POST_PROCESS_SO)
162
163#
164# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
165# we try to link them, at build time, against an object that exports the symbols
166# that they can legally use.  The link test object is, however, only built when
167# kmdb itself is built.  Requiring module developers to build kmdb first would
168# be painful, so by default, module-level builds don't do the link test (the
169# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
170# tree can, however, guarantee the construction of kmdb first, and as such can
171# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
172# link test to be run.
173#
174# Developers wanting to force a link test for a single module can use the
175# `linktest' target from within a module directory.
176#
177LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
178
179KMDB_LINKTEST = \
180	$(LD) -zdefs -dy -r -o $@.linktest $(KMODOBJS) $(LINKTESTOBJ) && \
181	$(RM) $@.linktest
182
183KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
184$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
185
186#
187# Ensure that dmods don't use floating point
188#
189KMDB_FPTEST_CMD = $(KMDB_FPTEST)
190
191$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
192	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS)
193	$(KMDB_LINKTEST_CMD)
194	$(KMDB_FPTEST_CMD)
195	$(CTFMERGE) -L VERSION -o $@ $(KMODOBJS)
196	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
197
198linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
199	$(KMDB_LINKTEST)
200
201linktest_check:
202	@if [ "$(MDBTGT)" != "kvm" ] && [ "$(MDBTGT)" != "disasm" ] ; then \
203		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
204		    >&2 ; \
205		exit 1 ; \
206	fi
207
208#
209# Dynamic rules for object construction
210#
211dmod/%.o kmod/%.o: %.c
212	$(COMPILE.c) -o $@ $<
213	$(CTFCONVERT_O)
214
215dmod/%.o kmod/%.o: ../%.c
216	$(COMPILE.c) -o $@ $<
217	$(CTFCONVERT_O)
218
219dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
220	$(COMPILE.c) -o $@ $<
221	$(CTFCONVERT_O)
222
223dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
224	$(COMPILE.c) -o $@ $<
225	$(CTFCONVERT_O)
226
227#
228# Lint
229#
230dmod/%.ln kmod/%.ln: %.c
231	$(LINT.c) -dirout=$(@D) -c $<
232
233dmod/%.ln kmod/%.ln: ../%.c
234	$(LINT.c) -dirout=$(@D) -c $<
235
236dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
237	$(LINT.c) -dirout=$(@D) -c $<
238
239dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
240	$(LINT.c) -dirout=$(@D) -c $<
241
242#
243# Installation targets
244#
245
246$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
247	$(INS.dir)
248
249$(ROOT)/usr/lib/mdb:
250	$(INS.dir)
251
252$(ROOT)/kernel/kmdb:
253	$(INS.dir)
254
255$(ROOTMOD)/$(MODULE): $(ROOTMOD)
256
257$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
258
259kmod dmod:
260	-@mkdir -p $@
261