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]
22 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 # Use is subject to license terms.
29 include $(SRC)/cmd/mdb/Makefile.tools
31 $(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
33 MODOBJS = $(MODSRCS:%.c=dmod/%.o)
34 KMODOBJS = $(KMODSRCS:%.c=kmod/%.o)
36 MODNAME = $(MODULE:%.so=%)
39 MODFILE = dmod/$(MODULE)
40 KMODFILE = kmod/$(KMODULE)
43 # The mess below is designed to pick the right set of objects to build and/or
44 # lint. We have three flavors:
46 # 1. proc and raw modules. Only $(MODOBJS) are built.
47 # 2. kvm modules for systems without kmdb. Only $(MODOBJS) are built.
48 # 3. kvm modules for systems with kmdb. $(MODOBJS) and $(KMODOBJS) are built.
50 # Complicating matters, we'd like to make the distinction between 2 and 3 before
51 # this Makefile is loaded. By default, we'll assume that all kvm modules should
52 # be built for kmdb. If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb',
53 # the kmdb variant of the module won't be built.
56 # Which flavors are to be built?
57 TARGETS_kvm_type_ = both # Build both if $(MODULE_BUILD_TYPE) is unset
58 TARGETS_kvm_type_kmdb = both
59 TARGETS_kvm_type_mdb = mdb
60 TARGETS_kvm_type = $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))
62 # What should we build?
63 TARGETS_kvm_kmdb = $(KMODFILE)
64 TARGETS_kvm_mdb = $(MODFILE)
65 TARGETS_kvm_both = $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
66 TARGETS_kvm = $(TARGETS_kvm_$(TARGETS_kvm_type))
67 TARGETS_proc = $(MODFILE)
68 TARGETS_raw = $(MODFILE)
69 TARGETS = $(TARGETS_$(MDBTGT))
71 # Where should we install that which we've built?
72 ROOTTGTS_kvm_type = $(TARGETS_kvm_type) # overridden by mdb_ks
73 ROOTTGTS_kvm_kmdb = $(ROOTKMOD)/$(KMODULE)
74 ROOTTGTS_kvm_mdb = $(ROOTMOD)/$(MODULE)
75 ROOTTGTS_kvm_both = $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
76 ROOTTGTS_kvm = $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
77 ROOTTGTS_proc = $(ROOTMOD)/$(MODULE)
78 ROOTTGTS_raw = $(ROOTMOD)/$(MODULE)
79 ROOTTGTS = $(ROOTTGTS_$(MDBTGT))
81 # What should we lint?
82 KLINTOBJS = $(KMODOBJS:%.o=%.ln)
83 LINTOBJS = $(MODOBJS:%.o=%.ln)
85 LINTFILES_kvm_type = $(TARGETS_kvm_type)
86 LINTFILES_kvm_both = $(KLINTOBJS) $(LINTOBJS)
87 LINTFILES_kvm_mdb = $(LINTOBJS)
88 LINTFILES_kvm = $(LINTFILES_kvm_$(LINTFILES_kvm_type))
89 LINTFILES_proc = $(LINTOBJS)
90 LINTFILES_raw = $(LINTOBJS)
91 LINTFILES = $(LINTFILES_$(MDBTGT))
93 kvm_TGTFLAGS = -D_KERNEL
94 proc_TGTFLAGS = -D_USER
96 CFLAGS += $(CCVERBOSE)
97 CFLAGS64 += $(CCVERBOSE)
98 CPPFLAGS += $($(MDBTGT)_TGTFLAGS) -I../../../common
100 LDFLAGS64 += $(ZTEXT)
102 # Module type-specific compiler flags
103 $(MODOBJS) := CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
104 $(MODOBJS) := CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
105 $(KMODOBJS) $(KLINTOBJS) := CPPFLAGS += -D_KMDB
106 $(KMODOBJS) := V9CODESIZE = $(CCABS32)
107 $(KMODOBJS) := DTS_ERRNO =
109 # Modules aren't allowed to export symbols
110 MAPFILE = $(SRC)/cmd/mdb/common/modules/conf/mapfile
112 # Modules typically make external references. To provide for -zdefs use
113 # and clean ldd(1) processing, explicitly define all external references.
114 MAPFILE-EXT = $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
117 # kmdb is a kernel module, so we'll use the kernel's build flags.
118 $(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32)
119 $(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
122 # Override this to pull source files from another directory
124 MODSRCS_DIR = ../../../common/modules/genunix
128 install: all $$(ROOTTGTS)
136 $(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
138 clobber: clean clean.lint
139 $(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
144 .PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
145 $(TARGETS) $(LINTFILES)
147 $(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
148 $(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \
149 $(MODOBJS) -o $@ $(LDLIBS) -lc
150 $(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
154 # kmdb dmods must *not* stray from the module API. To ensure that they don't,
155 # we try to link them, at build time, against an object that exports the symbols
156 # that they can legally use. The link test object is, however, only built when
157 # kmdb itself is built. Requiring module developers to build kmdb first would
158 # be painful, so by default, module-level builds don't do the link test (the
159 # $(POUND_SIGN) assignment below takes care of that). Builds of the entire
160 # tree can, however, guarantee the construction of kmdb first, and as such can
161 # override the setting of $(KMDB_LINKTEST_ENABLE). This override causes the
162 # link test to be run.
164 # Developers wanting to force a link test for a single module can use the
165 # `linktest' target from within a module directory.
167 LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
170 $(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
171 $(STANDOBJS) $(LINKTESTOBJ) && \
174 KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
175 $(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
178 # Ensure that dmods don't use floating point
180 KMDB_FPTEST_CMD = $(KMDB_FPTEST)
182 $(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
183 $(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
187 $(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
188 $(SETDYNFLAG) -f DF_1_NOKSYMS $@
190 linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
194 @if [ "$(MDBTGT)" != "kvm" ] ; then \
195 echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
201 # Dynamic rules for object construction
203 dmod/%.o kmod/%.o: %.c
204 $(COMPILE.c) -o $@ $<
207 dmod/%.o kmod/%.o: ../%.c
208 $(COMPILE.c) -o $@ $<
211 dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
212 $(COMPILE.c) -o $@ $<
215 dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
216 $(COMPILE.c) -o $@ $<
222 dmod/%.ln kmod/%.ln: %.c
223 $(LINT.c) -dirout=$(@D) -c $<
225 dmod/%.ln kmod/%.ln: ../%.c
226 $(LINT.c) -dirout=$(@D) -c $<
228 dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
229 $(LINT.c) -dirout=$(@D) -c $<
231 dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
232 $(LINT.c) -dirout=$(@D) -c $<
235 # Installation targets
238 $(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
247 $(ROOTMOD)/$(MODULE): $(ROOTMOD)
249 $(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)