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