Makefiles need to specify C99 mode consistently
[unleashed.git] / usr / src / cmd / mdb / Makefile.module
blobe64cc557e88ba43c12c0d000c410e5e5b0e19b0b
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.  We
55 # 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))
93 # Python specific flags. To try and make life easier for folks how are
94 # building with an LFS python.
96 PYCPPFLAGS              = -isystem $(ADJUNCT_PROTO)/usr/include/python$(PYTHON_VERSION)
98 kvm_TGTFLAGS            = -D_KERNEL
99 proc_TGTFLAGS           = -D_USER
101 CSTD                    = $(CSTD_GNU99)
103 CPPFLAGS                += $($(MDBTGT)_TGTFLAGS) -I../../../common
104 CPPFLAGS                += -I$(SRCTOP)/include
105 LDFLAGS                 += $(ZTEXT)
106 LDFLAGS64               += $(ZTEXT)
107 AS_CPPFLAGS             += -D_ASM
109 # Module type-specific compiler flags
110 $(MODOBJS) :=                   CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG)
111 $(MODOBJS) :=                   CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG)
112 $(KMODOBJS) :=                  CPPFLAGS += -D_KMDB
113 $(KMODOBJS) :=                  V9CODESIZE = $(CCABS32)
115 # Modules aren't allowed to export symbols
116 MAPFILE         = $(SRC)/cmd/mdb/common/modules/conf/mapfile
118 # Modules typically make external references.  To provide for -zdefs use
119 # and clean ldd(1) processing, explicitly define all external references.
120 MAPFILE-EXT     = $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
123 # kmdb is a kernel module, so we'll use the kernel's build flags.
124 $(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
127 # Override this to pull source files from another directory
129 MODSRCS_DIR = ../../../common/modules/genunix
131 all: $$(TARGETS)
133 install: all $$(ROOTTGTS)
135 dmods: install
137 clean:
138         $(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
140 clobber: clean
141         $(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
143 .NO_PARALLEL:
144 .PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
145         $(TARGETS)
147 $(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
148         $(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-Wl,-M%) $(GSHARED) \
149             $(MODOBJS) -o $@ $(LDLIBS) -lc
150         $(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
151         $(POST_PROCESS_SO)
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
169 KMDB_LINKTEST = \
170         $(LD) $(LD_ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
171         $(STANDOBJS) $(LINKTESTOBJ) && \
172         $(RM) $@.linktest
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) \
184         $(STANDOBJS)
185         $(KMDB_LINKTEST_CMD)
186         $(KMDB_FPTEST_CMD)
187         $(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS)
188         $(POST_PROCESS)
189         $(SETDYNFLAG) -f DF_1_NOKSYMS $@
191 linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
192         $(KMDB_LINKTEST)
194 linktest_check:
195         @if [ "$(MDBTGT)" != "kvm" ] ; then \
196                 echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
197                     >&2 ; \
198                 exit 1 ; \
199         fi
202 # Dynamic rules for object construction
204 dmod/%.o kmod/%.o: %.c
205         $(COMPILE.c) -o $@ $<
206         $(CTFCONVERT_O)
208 dmod/%.o kmod%.o: %.s
209         $(COMPILE.s) -o $@ $<
210         $(CTFCONVERT_O)
212 dmod/%.o kmod/%.o: ../%.c
213         $(COMPILE.c) -o $@ $<
214         $(CTFCONVERT_O)
216 dmod/%.o kmod%.o: ../%.s
217         $(COMPILE.s) -o $@ $<
218         $(CTFCONVERT_O)
220 dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
221         $(COMPILE.c) -o $@ $<
222         $(CTFCONVERT_O)
224 dmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.s
225         $(COMPILE.s) -o $@ $<
226         $(CTFCONVERT_O)
228 dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
229         $(COMPILE.c) -o $@ $<
230         $(CTFCONVERT_O)
232 dmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.s
233         $(COMPILE.s) -o $@ $<
234         $(CTFCONVERT_O)
237 # Installation targets
240 $(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
241         $(INS.dir)
243 $(ROOT)/usr/lib/mdb:
244         $(INS.dir)
246 $(ROOT)/kernel/kmdb:
247         $(INS.dir)
249 $(ROOTMOD)/$(MODULE): $(ROOTMOD)
251 $(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
253 kmod dmod:
254         -@mkdir -p $@