summaryrefslogtreecommitdiff
path: root/usr/src/cmd/mdb/Makefile.module
blob: 5b8ae3940520a03c95e2f3ba121aafc44b1c3154 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 2013 by Delphix. All rights reserved.
# Copyright 2015, Joyent, Inc.
#

.KEEP_STATE:
.SUFFIXES:

include $(SRC)/cmd/mdb/Makefile.tools

#
# Make sure we're getting a consistent execution environment for the
# embedded scripts.
#
SHELL= /usr/bin/ksh93

$(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
$(KMOD_SOURCES_DIFFERENT)KMODASMSRCS = $(MODASMSRCS)

MODOBJS = $(MODSRCS:%.c=dmod/%.o) $(MODASMSRCS:%.s=dmod/%.o)
KMODOBJS = $(KMODSRCS:%.c=kmod/%.o) $(KMODASMSRCS:%.s=kmod/%.o)

MODNAME_cmd = if [ -n "$(MODULE_NAME)" ]; then print $(MODULE_NAME); else print $(MODULE)| sed -e 's:\.so$$::'; fi
MODNAME = $(MODNAME_cmd:sh)
KMODULE = $(MODNAME)

MODFILE = dmod/$(MODULE)
KMODFILE = kmod/$(KMODULE)

#
# The mess below is designed to pick the right set of objects to build and/or
# lint.  We have three flavors:
#
#  1. proc and raw modules.  Only $(MODOBJS) are built.
#  2. kvm modules for systems without kmdb.  Only $(MODOBJS) are built.
#  3. kvm modules for systems with kmdb.  $(MODOBJS) and $(KMODOBJS) are built.
#
# Complicating matters, we'd like to make the distinction between 2 and 3 before
# this Makefile is loaded.  By default, we'll assume that all kvm modules should
# be built for kmdb.  If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb',
# the kmdb variant of the module won't be built.
#

# Which flavors are to be built?
TARGETS_kvm_type_	= both	# Build both if $(MODULE_BUILD_TYPE) is unset
TARGETS_kvm_type_kmdb	= both
TARGETS_kvm_type_mdb	= mdb
TARGETS_kvm_type	= $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))

# What should we build?
TARGETS_kvm_kmdb	= $(KMODFILE)
TARGETS_kvm_mdb		= $(MODFILE)
TARGETS_kvm_both	= $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
TARGETS_kvm		= $(TARGETS_kvm_$(TARGETS_kvm_type))
TARGETS_proc		= $(MODFILE)
TARGETS_raw		= $(MODFILE)
TARGETS			= $(TARGETS_$(MDBTGT))

# Where should we install that which we've built?
ROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
ROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
ROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
ROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
ROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
ROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
ROOTTGTS_raw		= $(ROOTMOD)/$(MODULE)
ROOTTGTS		= $(ROOTTGTS_$(MDBTGT))

# What should we lint?
KLINTOBJS		= $(KMODOBJS:%.o=%.ln)
LINTOBJS		= $(MODOBJS:%.o=%.ln)

LINTFILES_kvm_type	= $(TARGETS_kvm_type)
LINTFILES_kvm_both	= $(KLINTOBJS) $(LINTOBJS)
LINTFILES_kvm_mdb	= $(LINTOBJS)
LINTFILES_kvm		= $(LINTFILES_kvm_$(LINTFILES_kvm_type))
LINTFILES_proc		= $(LINTOBJS)
LINTFILES_raw		= $(LINTOBJS)
LINTFILES		= $(LINTFILES_$(MDBTGT))

#
# Python specific flags. To try and make life easier for folks who are
# building with an LFS python, we attempt to use -isystem when it's
# available.
#
PYCPPFLAGS		= -_gcc=-isystem -_gcc=$(ADJUNCT_PROTO)/usr/include/python$(PYTHON_VERSION)
PYCPPFLAGS		+= -_cc=-I$(ADJUNCT_PROTO)/usr/include/python$(PYTHON_VERSION)
PYLNFLAGS		= -I$(ADJUNCT_PROTO)/usr/include/python$(PYTHON_VERSION)

#
# At this time, we do not have python27 in the adjunct proto area, only
# python26. As such, we explicitly override the python version dmod here.
#
PYTHON_VERSION		= 2.6

kvm_TGTFLAGS		= -D_KERNEL
proc_TGTFLAGS		= -D_USER

C99MODE			= $(C99_ENABLE)

CFLAGS			+= $(CCVERBOSE)
CFLAGS64		+= $(CCVERBOSE)
CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
LDFLAGS			+= $(ZTEXT)
LDFLAGS64		+= $(ZTEXT)
ASFLAGS			+= -P
AS_CPPFLAGS		+= -D_ASM

# Module type-specific compiler flags
$(MODOBJS) :=			CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
$(MODOBJS) :=			CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
$(KMODOBJS) $(KLINTOBJS) :=	CPPFLAGS += -D_KMDB
$(KMODOBJS) :=			V9CODESIZE = $(CCABS32)
$(KMODOBJS) :=			DTS_ERRNO =

# Modules aren't allowed to export symbols
MAPFILE		= $(SRC)/cmd/mdb/common/modules/conf/mapfile

# Modules typically make external references.  To provide for -zdefs use
# and clean ldd(1) processing, explicitly define all external references.
MAPFILE-EXT	= $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern

#
# kmdb is a kernel module, so we'll use the kernel's build flags.
$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)

#
# Override this to pull source files from another directory
#
MODSRCS_DIR = ../../../common/modules/genunix

all: $$(TARGETS)

install: all $$(ROOTTGTS)

dmods: install

clean.lint:
	$(RM) $(LINTFILES) $(MODSRCS:.c=.ln)

clean:
	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)

clobber: clean clean.lint
	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)

lint: $$(LINTFILES)

.NO_PARALLEL:
.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
	$(TARGETS) $(LINTFILES)

$(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
	$(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \
	    $(MODOBJS) -o $@ $(LDLIBS) -lc
	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
	$(POST_PROCESS_SO)

#
# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
# we try to link them, at build time, against an object that exports the symbols
# that they can legally use.  The link test object is, however, only built when
# kmdb itself is built.  Requiring module developers to build kmdb first would
# be painful, so by default, module-level builds don't do the link test (the
# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
# tree can, however, guarantee the construction of kmdb first, and as such can
# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
# link test to be run.
#
# Developers wanting to force a link test for a single module can use the
# `linktest' target from within a module directory.
#
LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o

KMDB_LINKTEST = \
	$(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
	$(STANDOBJS) $(LINKTESTOBJ) && \
	$(RM) $@.linktest

KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)

#
# Ensure that dmods don't use floating point
#
KMDB_FPTEST_CMD = $(KMDB_FPTEST)

$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
	$(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
	$(STANDOBJS)
	$(KMDB_LINKTEST_CMD)
	$(KMDB_FPTEST_CMD)
	$(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
	$(POST_PROCESS)
	$(SETDYNFLAG) -f DF_1_NOKSYMS $@

linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
	$(KMDB_LINKTEST)

linktest_check:
	@if [ "$(MDBTGT)" != "kvm" ] ; then \
		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
		    >&2 ; \
		exit 1 ; \
	fi

#
# Dynamic rules for object construction
#
dmod/%.o kmod/%.o: %.c
	$(COMPILE.c) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod%.o: %.s
	$(COMPILE.s) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod/%.o: ../%.c
	$(COMPILE.c) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod%.o: ../%.s
	$(COMPILE.s) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
	$(COMPILE.c) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
	$(COMPILE.s) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
	$(COMPILE.c) -o $@ $<
	$(CTFCONVERT_O)

dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
	$(COMPILE.s) -o $@ $<
	$(CTFCONVERT_O)

#
# Lint
#
dmod/%.ln kmod/%.ln: %.c
	$(LINT.c) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: %.s
	$(LINT.s) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: ../%.c
	$(LINT.c) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: ../%.s
	$(LINT.s) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
	$(LINT.c) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.s
	$(LINT.s) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
	$(LINT.c) -dirout=$(@D) -c $<

dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.s
	$(LINT.s) -dirout=$(@D) -c $<

#
# Installation targets
#

$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
	$(INS.dir)

$(ROOT)/usr/lib/mdb:
	$(INS.dir)

$(ROOT)/kernel/kmdb:
	$(INS.dir)

$(ROOTMOD)/$(MODULE): $(ROOTMOD)

$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)

kmod dmod:
	-@mkdir -p $@