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