xref: /titanic_51/usr/src/cmd/mdb/Makefile.module (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate#
2*7c478bd9Sstevel@tonic-gate# CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate#
4*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate# (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate# with the License.
8*7c478bd9Sstevel@tonic-gate#
9*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate# and limitations under the License.
13*7c478bd9Sstevel@tonic-gate#
14*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate#
20*7c478bd9Sstevel@tonic-gate# CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate#
22*7c478bd9Sstevel@tonic-gate#
23*7c478bd9Sstevel@tonic-gate# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate# Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate#
26*7c478bd9Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate.KEEP_STATE:
29*7c478bd9Sstevel@tonic-gate.SUFFIXES:
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gateinclude $(SRC)/cmd/mdb/Makefile.tools
32*7c478bd9Sstevel@tonic-gate
33*7c478bd9Sstevel@tonic-gate$(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
34*7c478bd9Sstevel@tonic-gate
35*7c478bd9Sstevel@tonic-gateMODOBJS = $(MODSRCS:%.c=dmod/%.o)
36*7c478bd9Sstevel@tonic-gateKMODOBJS = $(KMODSRCS:%.c=kmod/%.o)
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gateMODNAME = $(MODULE:%.so=%)
39*7c478bd9Sstevel@tonic-gateKMODULE = $(MODNAME)
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gateMODFILE = dmod/$(MODULE)
42*7c478bd9Sstevel@tonic-gateKMODFILE = kmod/$(KMODULE)
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate#
45*7c478bd9Sstevel@tonic-gate# The mess below is designed to pick the right set of objects to build and/or
46*7c478bd9Sstevel@tonic-gate# lint.  We have three flavors:
47*7c478bd9Sstevel@tonic-gate#
48*7c478bd9Sstevel@tonic-gate#  1. proc modules.  Only $(MODOBJS) are built.
49*7c478bd9Sstevel@tonic-gate#  2. kvm modules for systems without kmdb.  Only $(MODOBJS) are built.
50*7c478bd9Sstevel@tonic-gate#  3. kvm modules for systems with kmdb.  $(MODOBJS) and $(KMODOBJS) are built.
51*7c478bd9Sstevel@tonic-gate#
52*7c478bd9Sstevel@tonic-gate# Complicating matters, we'd like to make the distinction between 2 and 3 before
53*7c478bd9Sstevel@tonic-gate# this Makefile is loaded.  By default, we'll assume that all kvm modules should
54*7c478bd9Sstevel@tonic-gate# be built for kmdb.  If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb',
55*7c478bd9Sstevel@tonic-gate# the kmdb variant of the module won't be built.
56*7c478bd9Sstevel@tonic-gate#
57*7c478bd9Sstevel@tonic-gate
58*7c478bd9Sstevel@tonic-gate# Which flavors are to be built?
59*7c478bd9Sstevel@tonic-gateTARGETS_kvm_type_	= both	# Build both if $(MODULE_BUILD_TYPE) is unset
60*7c478bd9Sstevel@tonic-gateTARGETS_kvm_type_kmdb	= both
61*7c478bd9Sstevel@tonic-gateTARGETS_kvm_type_mdb	= mdb
62*7c478bd9Sstevel@tonic-gateTARGETS_kvm_type	= $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate# What should we build?
65*7c478bd9Sstevel@tonic-gateTARGETS_kvm_kmdb	= $(KMODFILE)
66*7c478bd9Sstevel@tonic-gateTARGETS_kvm_mdb		= $(MODFILE)
67*7c478bd9Sstevel@tonic-gateTARGETS_kvm_both	= $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
68*7c478bd9Sstevel@tonic-gateTARGETS_kvm		= $(TARGETS_kvm_$(TARGETS_kvm_type))
69*7c478bd9Sstevel@tonic-gateTARGETS_disasm_kmdb	= $(KMODFILE)
70*7c478bd9Sstevel@tonic-gateTARGETS_disasm_mdb	= $(MODFILE)
71*7c478bd9Sstevel@tonic-gateTARGETS_disasm_both	= $(TARGETS_disasm_mdb) $(TARGETS_disasm_kmdb)
72*7c478bd9Sstevel@tonic-gateTARGETS_disasm		= $(TARGETS_disasm_$(TARGETS_kvm_type))
73*7c478bd9Sstevel@tonic-gateTARGETS_proc		= $(MODFILE)
74*7c478bd9Sstevel@tonic-gateTARGETS			= $(TARGETS_$(MDBTGT))
75*7c478bd9Sstevel@tonic-gate
76*7c478bd9Sstevel@tonic-gate# Where should we install that which we've built?
77*7c478bd9Sstevel@tonic-gateROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
78*7c478bd9Sstevel@tonic-gateROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
79*7c478bd9Sstevel@tonic-gateROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
80*7c478bd9Sstevel@tonic-gateROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
81*7c478bd9Sstevel@tonic-gateROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
82*7c478bd9Sstevel@tonic-gateROOTTGTS_disasm_kmdb	= $(ROOTKMOD)/$(KMODULE)
83*7c478bd9Sstevel@tonic-gateROOTTGTS_disasm_mdb	= $(ROOTMOD)/$(MODULE)
84*7c478bd9Sstevel@tonic-gateROOTTGTS_disasm_both	= $(ROOTTGTS_disasm_mdb) $(ROOTTGTS_disasm_kmdb)
85*7c478bd9Sstevel@tonic-gateROOTTGTS_disasm		= $(ROOTTGTS_disasm_$(TARGETS_kvm_type))
86*7c478bd9Sstevel@tonic-gateROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
87*7c478bd9Sstevel@tonic-gateROOTTGTS		= $(ROOTTGTS_$(MDBTGT))
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate# What should we lint?
90*7c478bd9Sstevel@tonic-gateKLINTOBJS		= $(KMODOBJS:%.o=%.ln)
91*7c478bd9Sstevel@tonic-gateLINTOBJS		= $(MODOBJS:%.o=%.ln)
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gateLINTFILES_kvm_type	= $(TARGETS_kvm_type)
94*7c478bd9Sstevel@tonic-gateLINTFILES_kvm_both	= $(KLINTOBJS) $(LINTOBJS)
95*7c478bd9Sstevel@tonic-gateLINTFILES_kvm_mdb	= $(LINTOBJS)
96*7c478bd9Sstevel@tonic-gateLINTFILES_kvm		= $(LINTFILES_kvm_$(LINTFILES_kvm_type))
97*7c478bd9Sstevel@tonic-gateLINTFILES_disasm_both	= $(KLINTOBJS) $(LINTOBJS)
98*7c478bd9Sstevel@tonic-gateLINTFILES_disasm_mdb	= $(LINTOBJS)
99*7c478bd9Sstevel@tonic-gateLINTFILES_disasm	= $(LINTFILES_disasm_$(TARGETS_kvm_type))
100*7c478bd9Sstevel@tonic-gateLINTFILES_proc		= $(LINTOBJS)
101*7c478bd9Sstevel@tonic-gateLINTFILES		= $(LINTFILES_$(MDBTGT))
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gatekvm_TGTFLAGS		= -D_KERNEL
104*7c478bd9Sstevel@tonic-gateproc_TGTFLAGS		= -D_USER
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gateCFLAGS			+= $(CCVERBOSE)
107*7c478bd9Sstevel@tonic-gateCFLAGS64		+= $(CCVERBOSE)
108*7c478bd9Sstevel@tonic-gateCPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
109*7c478bd9Sstevel@tonic-gateLDFLAGS			+= $(ZTEXT) $(ZCOMBRELOC)
110*7c478bd9Sstevel@tonic-gateLDFLAGS64		+= $(ZTEXT) $(ZCOMBRELOC)
111*7c478bd9Sstevel@tonic-gate
112*7c478bd9Sstevel@tonic-gate# Module type-specific compiler flags
113*7c478bd9Sstevel@tonic-gate$(MODOBJS) :=			CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
114*7c478bd9Sstevel@tonic-gate$(MODOBJS) :=			CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
115*7c478bd9Sstevel@tonic-gate$(KMODOBJS) $(KLINTOBJS) :=	CPPFLAGS += -D_KMDB
116*7c478bd9Sstevel@tonic-gate$(KMODOBJS) :=			V9CODESIZE = $(CCABS32)
117*7c478bd9Sstevel@tonic-gate$(KMODOBJS) :=			DTS_ERRNO =
118*7c478bd9Sstevel@tonic-gate
119*7c478bd9Sstevel@tonic-gate# Modules aren't allowed to export symbols
120*7c478bd9Sstevel@tonic-gateMAPFILE			= $(SRC)/cmd/mdb/common/modules/conf/mapfile
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate#
123*7c478bd9Sstevel@tonic-gate# kmdb is a kernel module, so we'll use the kernel's build flags.
124*7c478bd9Sstevel@tonic-gate$(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
125*7c478bd9Sstevel@tonic-gate$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate#
128*7c478bd9Sstevel@tonic-gate# Override this to pull source files from another directory
129*7c478bd9Sstevel@tonic-gate#
130*7c478bd9Sstevel@tonic-gateMODSRCS_DIR = ../../../common/modules/genunix
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate#
133*7c478bd9Sstevel@tonic-gate# Reset STRIPFLAG to the empty string.  MDB modules are intentionally installed
134*7c478bd9Sstevel@tonic-gate# with symbol tables in order to help module developers.
135*7c478bd9Sstevel@tonic-gate#
136*7c478bd9Sstevel@tonic-gateSTRIPFLAG =
137*7c478bd9Sstevel@tonic-gateGROUP = sys
138*7c478bd9Sstevel@tonic-gate
139*7c478bd9Sstevel@tonic-gateall: $$(TARGETS)
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gateinstall: all $$(ROOTTGTS)
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gatedmods: install
144*7c478bd9Sstevel@tonic-gate
145*7c478bd9Sstevel@tonic-gateclean.lint:
146*7c478bd9Sstevel@tonic-gate	$(RM) $(LINTFILES)
147*7c478bd9Sstevel@tonic-gate
148*7c478bd9Sstevel@tonic-gateclean:
149*7c478bd9Sstevel@tonic-gate	$(RM) $(MODOBJS) $(KMODOBJS)
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gateclobber: clean clean.lint
152*7c478bd9Sstevel@tonic-gate	$(RM) $(MODFILE) $(KMODFILE)
153*7c478bd9Sstevel@tonic-gate
154*7c478bd9Sstevel@tonic-gatelint: $$(LINTFILES)
155*7c478bd9Sstevel@tonic-gate
156*7c478bd9Sstevel@tonic-gate.NO_PARALLEL:
157*7c478bd9Sstevel@tonic-gate.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
158*7c478bd9Sstevel@tonic-gate	$(TARGETS) $(LINTFILES)
159*7c478bd9Sstevel@tonic-gate
160*7c478bd9Sstevel@tonic-gate$(MODFILE): dmod .WAIT $(MODOBJS)
161*7c478bd9Sstevel@tonic-gate	$(LINK.c) $(GSHARED) $(MODOBJS) -o $@ $(LDLIBS)
162*7c478bd9Sstevel@tonic-gate	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
163*7c478bd9Sstevel@tonic-gate	$(POST_PROCESS_SO)
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate#
166*7c478bd9Sstevel@tonic-gate# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
167*7c478bd9Sstevel@tonic-gate# we try to link them, at build time, against an object that exports the symbols
168*7c478bd9Sstevel@tonic-gate# that they can legally use.  The link test object is, however, only built when
169*7c478bd9Sstevel@tonic-gate# kmdb itself is built.  Requiring module developers to build kmdb first would
170*7c478bd9Sstevel@tonic-gate# be painful, so by default, module-level builds don't do the link test (the
171*7c478bd9Sstevel@tonic-gate# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
172*7c478bd9Sstevel@tonic-gate# tree can, however, guarantee the construction of kmdb first, and as such can
173*7c478bd9Sstevel@tonic-gate# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
174*7c478bd9Sstevel@tonic-gate# link test to be run.
175*7c478bd9Sstevel@tonic-gate#
176*7c478bd9Sstevel@tonic-gate# Developers wanting to force a link test for a single module can use the
177*7c478bd9Sstevel@tonic-gate# `linktest' target from within a module directory.
178*7c478bd9Sstevel@tonic-gate#
179*7c478bd9Sstevel@tonic-gateLINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gateKMDB_LINKTEST = \
182*7c478bd9Sstevel@tonic-gate	$(LD) -zdefs -dy -r -o $@.linktest $(KMODOBJS) $(LINKTESTOBJ) && \
183*7c478bd9Sstevel@tonic-gate	$(RM) $@.linktest
184*7c478bd9Sstevel@tonic-gate
185*7c478bd9Sstevel@tonic-gateKMDB_LINKTEST_ENABLE=$(POUND_SIGN)
186*7c478bd9Sstevel@tonic-gate$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
187*7c478bd9Sstevel@tonic-gate
188*7c478bd9Sstevel@tonic-gate#
189*7c478bd9Sstevel@tonic-gate# Ensure that dmods don't use floating point
190*7c478bd9Sstevel@tonic-gate#
191*7c478bd9Sstevel@tonic-gateKMDB_FPTEST_CMD = $(KMDB_FPTEST)
192*7c478bd9Sstevel@tonic-gate
193*7c478bd9Sstevel@tonic-gate$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
194*7c478bd9Sstevel@tonic-gate	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS)
195*7c478bd9Sstevel@tonic-gate	$(KMDB_LINKTEST_CMD)
196*7c478bd9Sstevel@tonic-gate	$(KMDB_FPTEST_CMD)
197*7c478bd9Sstevel@tonic-gate	$(CTFMERGE) -L VERSION -o $@ $(KMODOBJS)
198*7c478bd9Sstevel@tonic-gate	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
199*7c478bd9Sstevel@tonic-gate
200*7c478bd9Sstevel@tonic-gatelinktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
201*7c478bd9Sstevel@tonic-gate	$(KMDB_LINKTEST)
202*7c478bd9Sstevel@tonic-gate
203*7c478bd9Sstevel@tonic-gatelinktest_check:
204*7c478bd9Sstevel@tonic-gate	@if [ "$(MDBTGT)" != "kvm" ] && [ "$(MDBTGT)" != "disasm" ] ; then \
205*7c478bd9Sstevel@tonic-gate		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
206*7c478bd9Sstevel@tonic-gate		    >&2 ; \
207*7c478bd9Sstevel@tonic-gate		exit 1 ; \
208*7c478bd9Sstevel@tonic-gate	fi
209*7c478bd9Sstevel@tonic-gate
210*7c478bd9Sstevel@tonic-gate#
211*7c478bd9Sstevel@tonic-gate# Dynamic rules for object construction
212*7c478bd9Sstevel@tonic-gate#
213*7c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: %.c
214*7c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
215*7c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: ../%.c
218*7c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
219*7c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
220*7c478bd9Sstevel@tonic-gate
221*7c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
222*7c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
223*7c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
226*7c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
227*7c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
228*7c478bd9Sstevel@tonic-gate
229*7c478bd9Sstevel@tonic-gate#
230*7c478bd9Sstevel@tonic-gate# Lint
231*7c478bd9Sstevel@tonic-gate#
232*7c478bd9Sstevel@tonic-gatedmod/%.ln kmod/%.ln: %.c
233*7c478bd9Sstevel@tonic-gate	$(LINT.c) -dirout=$(@D) -c $<
234*7c478bd9Sstevel@tonic-gate
235*7c478bd9Sstevel@tonic-gatedmod/%.ln kmod/%.ln: ../%.c
236*7c478bd9Sstevel@tonic-gate	$(LINT.c) -dirout=$(@D) -c $<
237*7c478bd9Sstevel@tonic-gate
238*7c478bd9Sstevel@tonic-gatedmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
239*7c478bd9Sstevel@tonic-gate	$(LINT.c) -dirout=$(@D) -c $<
240*7c478bd9Sstevel@tonic-gate
241*7c478bd9Sstevel@tonic-gatedmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
242*7c478bd9Sstevel@tonic-gate	$(LINT.c) -dirout=$(@D) -c $<
243*7c478bd9Sstevel@tonic-gate
244*7c478bd9Sstevel@tonic-gate#
245*7c478bd9Sstevel@tonic-gate# Installation targets
246*7c478bd9Sstevel@tonic-gate#
247*7c478bd9Sstevel@tonic-gate
248*7c478bd9Sstevel@tonic-gate$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
249*7c478bd9Sstevel@tonic-gate	$(INS.dir)
250*7c478bd9Sstevel@tonic-gate
251*7c478bd9Sstevel@tonic-gate$(ROOT)/usr/lib/mdb:
252*7c478bd9Sstevel@tonic-gate	$(INS.dir)
253*7c478bd9Sstevel@tonic-gate
254*7c478bd9Sstevel@tonic-gate$(ROOT)/kernel/kmdb:
255*7c478bd9Sstevel@tonic-gate	$(INS.dir)
256*7c478bd9Sstevel@tonic-gate
257*7c478bd9Sstevel@tonic-gate$(ROOTMOD)/$(MODULE): $(ROOTMOD)
258*7c478bd9Sstevel@tonic-gate
259*7c478bd9Sstevel@tonic-gate$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
260*7c478bd9Sstevel@tonic-gate
261*7c478bd9Sstevel@tonic-gatekmod dmod:
262*7c478bd9Sstevel@tonic-gate	-@mkdir -p $@
263