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