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 # 27 28 .KEEP_STATE: 29 .SUFFIXES: 30 31 include $(SRC)/cmd/mdb/Makefile.tools 32 33 $(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS) 34 35 MODOBJS = $(MODSRCS:%.c=dmod/%.o) 36 KMODOBJS = $(KMODSRCS:%.c=kmod/%.o) 37 38 MODNAME = $(MODULE:%.so=%) 39 KMODULE = $(MODNAME) 40 41 MODFILE = dmod/$(MODULE) 42 KMODFILE = kmod/$(KMODULE) 43 44 # 45 # The mess below is designed to pick the right set of objects to build and/or 46 # lint. We have three flavors: 47 # 48 # 1. proc and raw modules. Only $(MODOBJS) are built. 49 # 2. kvm modules for systems without kmdb. Only $(MODOBJS) are built. 50 # 3. kvm modules for systems with kmdb. $(MODOBJS) and $(KMODOBJS) are built. 51 # 52 # Complicating matters, we'd like to make the distinction between 2 and 3 before 53 # this Makefile is loaded. By default, we'll assume that all kvm modules should 54 # be built for kmdb. If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb', 55 # the kmdb variant of the module won't be built. 56 # 57 58 # Which flavors are to be built? 59 TARGETS_kvm_type_ = both # Build both if $(MODULE_BUILD_TYPE) is unset 60 TARGETS_kvm_type_kmdb = both 61 TARGETS_kvm_type_mdb = mdb 62 TARGETS_kvm_type = $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE)) 63 64 # What should we build? 65 TARGETS_kvm_kmdb = $(KMODFILE) 66 TARGETS_kvm_mdb = $(MODFILE) 67 TARGETS_kvm_both = $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb) 68 TARGETS_kvm = $(TARGETS_kvm_$(TARGETS_kvm_type)) 69 TARGETS_proc = $(MODFILE) 70 TARGETS_raw = $(MODFILE) 71 TARGETS = $(TARGETS_$(MDBTGT)) 72 73 # Where should we install that which we've built? 74 ROOTTGTS_kvm_type = $(TARGETS_kvm_type) # overridden by mdb_ks 75 ROOTTGTS_kvm_kmdb = $(ROOTKMOD)/$(KMODULE) 76 ROOTTGTS_kvm_mdb = $(ROOTMOD)/$(MODULE) 77 ROOTTGTS_kvm_both = $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb) 78 ROOTTGTS_kvm = $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type)) 79 ROOTTGTS_proc = $(ROOTMOD)/$(MODULE) 80 ROOTTGTS_raw = $(ROOTMOD)/$(MODULE) 81 ROOTTGTS = $(ROOTTGTS_$(MDBTGT)) 82 83 # What should we lint? 84 KLINTOBJS = $(KMODOBJS:%.o=%.ln) 85 LINTOBJS = $(MODOBJS:%.o=%.ln) 86 87 LINTFILES_kvm_type = $(TARGETS_kvm_type) 88 LINTFILES_kvm_both = $(KLINTOBJS) $(LINTOBJS) 89 LINTFILES_kvm_mdb = $(LINTOBJS) 90 LINTFILES_kvm = $(LINTFILES_kvm_$(LINTFILES_kvm_type)) 91 LINTFILES_proc = $(LINTOBJS) 92 LINTFILES_raw = $(LINTOBJS) 93 LINTFILES = $(LINTFILES_$(MDBTGT)) 94 95 kvm_TGTFLAGS = -D_KERNEL 96 proc_TGTFLAGS = -D_USER 97 98 C99MODE = $(C99_ENABLE) 99 100 CFLAGS += $(CCVERBOSE) 101 CFLAGS64 += $(CCVERBOSE) 102 CPPFLAGS += $($(MDBTGT)_TGTFLAGS) -I../../../common 103 LDFLAGS += $(ZTEXT) 104 LDFLAGS64 += $(ZTEXT) 105 106 # Module type-specific compiler flags 107 $(MODOBJS) := CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG) 108 $(MODOBJS) := CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG) 109 $(KMODOBJS) $(KLINTOBJS) := CPPFLAGS += -D_KMDB 110 $(KMODOBJS) := V9CODESIZE = $(CCABS32) 111 $(KMODOBJS) := DTS_ERRNO = 112 113 # Modules aren't allowed to export symbols 114 MAPFILE = $(SRC)/cmd/mdb/common/modules/conf/mapfile 115 116 # Modules typically make external references. To provide for -zdefs use 117 # and clean ldd(1) processing, explicitly define all external references. 118 MAPFILE-EXT = $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern 119 120 # 121 # kmdb is a kernel module, so we'll use the kernel's build flags. 122 $(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32) 123 $(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64) 124 125 # 126 # Override this to pull source files from another directory 127 # 128 MODSRCS_DIR = ../../../common/modules/genunix 129 130 all: $$(TARGETS) 131 132 install: all $$(ROOTTGTS) 133 134 dmods: install 135 136 clean.lint: 137 $(RM) $(LINTFILES) 138 139 clean: 140 $(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES) 141 142 clobber: clean clean.lint 143 $(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES) 144 145 lint: $$(LINTFILES) 146 147 .NO_PARALLEL: 148 .PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \ 149 $(TARGETS) $(LINTFILES) 150 151 $(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT) 152 $(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-M%) $(GSHARED) \ 153 $(MODOBJS) -o $@ $(LDLIBS) -lc 154 $(CTFMERGE) -L VERSION -o $@ $(MODOBJS) 155 $(POST_PROCESS_SO) 156 157 # 158 # kmdb dmods must *not* stray from the module API. To ensure that they don't, 159 # we try to link them, at build time, against an object that exports the symbols 160 # that they can legally use. The link test object is, however, only built when 161 # kmdb itself is built. Requiring module developers to build kmdb first would 162 # be painful, so by default, module-level builds don't do the link test (the 163 # $(POUND_SIGN) assignment below takes care of that). Builds of the entire 164 # tree can, however, guarantee the construction of kmdb first, and as such can 165 # override the setting of $(KMDB_LINKTEST_ENABLE). This override causes the 166 # link test to be run. 167 # 168 # Developers wanting to force a link test for a single module can use the 169 # `linktest' target from within a module directory. 170 # 171 LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o 172 173 KMDB_LINKTEST = \ 174 $(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \ 175 $(STANDOBJS) $(LINKTESTOBJ) && \ 176 $(RM) $@.linktest 177 178 KMDB_LINKTEST_ENABLE=$(POUND_SIGN) 179 $(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST) 180 181 # 182 # Ensure that dmods don't use floating point 183 # 184 KMDB_FPTEST_CMD = $(KMDB_FPTEST) 185 186 $(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE) 187 $(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \ 188 $(STANDOBJS) 189 $(KMDB_LINKTEST_CMD) 190 $(KMDB_FPTEST_CMD) 191 $(CTFMERGE) -f -L VERSION -o $@ $(KMODOBJS) 192 $(SETDYNFLAG) -f DF_1_NOKSYMS $@ 193 194 linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS) 195 $(KMDB_LINKTEST) 196 197 linktest_check: 198 @if [ "$(MDBTGT)" != "kvm" ] ; then \ 199 echo "ERROR: linktest is not supported non-kvm/disasm dmods" \ 200 >&2 ; \ 201 exit 1 ; \ 202 fi 203 204 # 205 # Dynamic rules for object construction 206 # 207 dmod/%.o kmod/%.o: %.c 208 $(COMPILE.c) -o $@ $< 209 $(CTFCONVERT_O) 210 211 dmod/%.o kmod/%.o: ../%.c 212 $(COMPILE.c) -o $@ $< 213 $(CTFCONVERT_O) 214 215 dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c 216 $(COMPILE.c) -o $@ $< 217 $(CTFCONVERT_O) 218 219 dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c 220 $(COMPILE.c) -o $@ $< 221 $(CTFCONVERT_O) 222 223 # 224 # Lint 225 # 226 dmod/%.ln kmod/%.ln: %.c 227 $(LINT.c) -dirout=$(@D) -c $< 228 229 dmod/%.ln kmod/%.ln: ../%.c 230 $(LINT.c) -dirout=$(@D) -c $< 231 232 dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c 233 $(LINT.c) -dirout=$(@D) -c $< 234 235 dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c 236 $(LINT.c) -dirout=$(@D) -c $< 237 238 # 239 # Installation targets 240 # 241 242 $(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb 243 $(INS.dir) 244 245 $(ROOT)/usr/lib/mdb: 246 $(INS.dir) 247 248 $(ROOT)/kernel/kmdb: 249 $(INS.dir) 250 251 $(ROOTMOD)/$(MODULE): $(ROOTMOD) 252 253 $(ROOTKMOD)/$(KMODULE): $(ROOTKMOD) 254 255 kmod dmod: 256 -@mkdir -p $@