xref: /illumos-gate/usr/src/cmd/mdb/Makefile.module (revision ba5ca68405ba4441c86a6cfc87f4ddcb3565c81d)
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 .
57# 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#
95# Python specific flags. To try and make life easier for folks how are
96# building with an LFS python, we attempt to use -isystem when it's
97# available.
98#
99PYCPPFLAGS		= -_gcc=-isystem -_gcc=$(ADJUNCT_PROTO)/usr/include/python$(PYTHON3_VERSION)$(PYTHON3_SUFFIX)
100PYCPPFLAGS		+= -_cc=-I$(ADJUNCT_PROTO)/usr/include/python$(PYTHON3_VERSION)$(PYTHON3_SUFFIX)
101PYLNFLAGS		= -I$(ADJUNCT_PROTO)/usr/include/python$(PYTHON3_VERSION)$(PYTHON3_SUFFIX)
102
103kvm_TGTFLAGS		= -D_KERNEL
104proc_TGTFLAGS		= -D_USER
105
106CSTD			= $(CSTD_GNU99)
107
108CFLAGS			+= $(CCVERBOSE)
109CFLAGS64		+= $(CCVERBOSE)
110CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
111LDFLAGS			+= $(ZTEXT)
112LDFLAGS64		+= $(ZTEXT)
113ASFLAGS			+= -P
114AS_CPPFLAGS		+= -D_ASM
115
116SMOFF += all_func_returns,index_overflow
117
118# Module type-specific compiler flags
119$(MODOBJS) :=	CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
120$(MODOBJS) :=	CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
121$(KMODOBJS) :=	CPPFLAGS += -D_KMDB
122$(KMODOBJS) :=	V9CODESIZE = $(CCABS32)
123$(KMODOBJS) :=	DTS_ERRNO =
124$(KMODFILE) :=	STACKPROTECT = none
125
126# Modules aren't allowed to export symbols
127MAPFILE		= $(SRC)/cmd/mdb/common/modules/conf/mapfile
128
129# Modules typically make external references.  To provide for -zdefs use
130# and clean ldd(1) processing, explicitly define all external references.
131MAPFILE-EXT	= $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
132
133#
134# kmdb is a kernel module, so we'll use the kernel's build flags.
135$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
136
137#
138# Override this to pull source files from another directory
139#
140MODSRCS_DIR = ../../../common/modules/genunix
141
142all: $$(TARGETS)
143
144install: all $$(ROOTTGTS)
145
146dmods: install
147
148clean:
149	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
150
151clobber: clean
152	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
153
154.NO_PARALLEL:
155.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
156	$(TARGETS)
157
158$(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
159	$(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-Wl,-M%) $(GSHARED) \
160	    $(MODOBJS) -o $@ $(LDLIBS) -lc -lproc
161	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
162	$(POST_PROCESS_SO)
163
164#
165# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
166# we try to link them, at build time, against an object that exports the symbols
167# that they can legally use.  The link test object is, however, only built when
168# kmdb itself is built.  Requiring module developers to build kmdb first would
169# be painful, so by default, module-level builds don't do the link test (the
170# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
171# tree can, however, guarantee the construction of kmdb first, and as such can
172# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
173# link test to be run.
174#
175# Developers wanting to force a link test for a single module can use the
176# `linktest' target from within a module directory.
177#
178LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
179
180KMDB_LINKTEST = \
181	$(LD) $(ZDEFS) -ztype=kmod -o $@.linktest $(KMODOBJS) \
182	$(STANDOBJS) $(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# Allow overriding this because mdb_ks is special case fake module,
194# see Makefile.mdb_ks
195KMODFLAG = -ztype=kmod
196
197$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
198	$(LD) $(KMODFLAG) $(MAPFILE:%=-Wl,-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
199	$(STANDOBJS)
200	$(KMDB_LINKTEST_CMD)
201	$(KMDB_FPTEST_CMD)
202	$(CTFMERGE) -l "$(UTS_LABEL)" -o $@ $(KMODOBJS)
203	$(POST_PROCESS)
204	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
205
206linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
207	$(KMDB_LINKTEST)
208
209linktest_check:
210	@if [ "$(MDBTGT)" != "kvm" ] ; then \
211		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
212		    >&2 ; \
213		exit 1 ; \
214	fi
215
216#
217# Dynamic rules for object construction
218#
219dmod/%.o kmod/%.o: %.c
220	$(COMPILE.c) -o $@ $<
221	$(CTFCONVERT_O)
222
223dmod/%.o kmod%.o: %.s
224	$(COMPILE.s) -o $@ $<
225
226dmod/%.o kmod/%.o: ../%.c
227	$(COMPILE.c) -o $@ $<
228	$(CTFCONVERT_O)
229
230dmod/%.o kmod%.o: ../%.s
231	$(COMPILE.s) -o $@ $<
232
233dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
234	$(COMPILE.c) -o $@ $<
235	$(CTFCONVERT_O)
236
237dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
238	$(COMPILE.s) -o $@ $<
239
240dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
241	$(COMPILE.c) -o $@ $<
242	$(CTFCONVERT_O)
243
244dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
245	$(COMPILE.s) -o $@ $<
246
247#
248# Installation targets
249#
250
251$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
252	$(INS.dir)
253
254$(ROOT)/usr/lib/mdb:
255	$(INS.dir)
256
257$(ROOT)/kernel/kmdb:
258	$(INS.dir)
259
260$(ROOTMOD)/$(MODULE): $(ROOTMOD)
261
262$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
263
264kmod dmod:
265	-@mkdir -p $@
266