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, Version 1.0 only 6# (the "License"). You may not use this file except in compliance 7# with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22# 23# Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24# Use is subject to license terms. 25# 26# ident "%Z%%M% %I% %E% SMI" 27 28.KEEP_STATE: 29.SUFFIXES: 30 31include $(SRC)/cmd/mdb/Makefile.tools 32 33$(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS) 34 35MODOBJS = $(MODSRCS:%.c=dmod/%.o) 36KMODOBJS = $(KMODSRCS:%.c=kmod/%.o) 37 38MODNAME = $(MODULE:%.so=%) 39KMODULE = $(MODNAME) 40 41MODFILE = dmod/$(MODULE) 42KMODFILE = 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? 59TARGETS_kvm_type_ = both # Build both if $(MODULE_BUILD_TYPE) is unset 60TARGETS_kvm_type_kmdb = both 61TARGETS_kvm_type_mdb = mdb 62TARGETS_kvm_type = $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE)) 63 64# What should we build? 65TARGETS_kvm_kmdb = $(KMODFILE) 66TARGETS_kvm_mdb = $(MODFILE) 67TARGETS_kvm_both = $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb) 68TARGETS_kvm = $(TARGETS_kvm_$(TARGETS_kvm_type)) 69TARGETS_disasm_kmdb = $(KMODFILE) 70TARGETS_disasm_mdb = $(MODFILE) 71TARGETS_disasm_both = $(TARGETS_disasm_mdb) $(TARGETS_disasm_kmdb) 72TARGETS_disasm = $(TARGETS_disasm_$(TARGETS_kvm_type)) 73TARGETS_proc = $(MODFILE) 74TARGETS_raw = $(MODFILE) 75TARGETS = $(TARGETS_$(MDBTGT)) 76 77# Where should we install that which we've built? 78ROOTTGTS_kvm_type = $(TARGETS_kvm_type) # overridden by mdb_ks 79ROOTTGTS_kvm_kmdb = $(ROOTKMOD)/$(KMODULE) 80ROOTTGTS_kvm_mdb = $(ROOTMOD)/$(MODULE) 81ROOTTGTS_kvm_both = $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb) 82ROOTTGTS_kvm = $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type)) 83ROOTTGTS_disasm_kmdb = $(ROOTKMOD)/$(KMODULE) 84ROOTTGTS_disasm_mdb = $(ROOTMOD)/$(MODULE) 85ROOTTGTS_disasm_both = $(ROOTTGTS_disasm_mdb) $(ROOTTGTS_disasm_kmdb) 86ROOTTGTS_disasm = $(ROOTTGTS_disasm_$(TARGETS_kvm_type)) 87ROOTTGTS_proc = $(ROOTMOD)/$(MODULE) 88ROOTTGTS_raw = $(ROOTMOD)/$(MODULE) 89ROOTTGTS = $(ROOTTGTS_$(MDBTGT)) 90 91# What should we lint? 92KLINTOBJS = $(KMODOBJS:%.o=%.ln) 93LINTOBJS = $(MODOBJS:%.o=%.ln) 94 95LINTFILES_kvm_type = $(TARGETS_kvm_type) 96LINTFILES_kvm_both = $(KLINTOBJS) $(LINTOBJS) 97LINTFILES_kvm_mdb = $(LINTOBJS) 98LINTFILES_kvm = $(LINTFILES_kvm_$(LINTFILES_kvm_type)) 99LINTFILES_disasm_both = $(KLINTOBJS) $(LINTOBJS) 100LINTFILES_disasm_mdb = $(LINTOBJS) 101LINTFILES_disasm = $(LINTFILES_disasm_$(TARGETS_kvm_type)) 102LINTFILES_proc = $(LINTOBJS) 103LINTFILES_raw = $(LINTOBJS) 104LINTFILES = $(LINTFILES_$(MDBTGT)) 105 106kvm_TGTFLAGS = -D_KERNEL 107proc_TGTFLAGS = -D_USER 108 109CFLAGS += $(CCVERBOSE) 110CFLAGS64 += $(CCVERBOSE) 111CPPFLAGS += $($(MDBTGT)_TGTFLAGS) -I../../../common 112LDFLAGS += $(ZTEXT) $(ZCOMBRELOC) 113LDFLAGS64 += $(ZTEXT) $(ZCOMBRELOC) 114 115# Module type-specific compiler flags 116$(MODOBJS) := CFLAGS += $(C_BIGPICFLAGS) $(XREGSFLAG) 117$(MODOBJS) := CFLAGS64 += $(C_BIGPICFLAGS) $(XREGSFLAG) 118$(KMODOBJS) $(KLINTOBJS) := CPPFLAGS += -D_KMDB 119$(KMODOBJS) := V9CODESIZE = $(CCABS32) 120$(KMODOBJS) := DTS_ERRNO = 121 122# Modules aren't allowed to export symbols 123MAPFILE = $(SRC)/cmd/mdb/common/modules/conf/mapfile 124 125# 126# kmdb is a kernel module, so we'll use the kernel's build flags. 127$(KMODOBJS) := CFLAGS += $(STAND_FLAGS_32) 128$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64) 129 130# 131# Override this to pull source files from another directory 132# 133MODSRCS_DIR = ../../../common/modules/genunix 134 135# 136# Reset STRIPFLAG to the empty string. MDB modules are intentionally installed 137# with symbol tables in order to help module developers. 138# 139STRIPFLAG = 140GROUP = sys 141 142all: $$(TARGETS) 143 144install: all $$(ROOTTGTS) 145 146dmods: install 147 148clean.lint: 149 $(RM) $(LINTFILES) 150 151clean: 152 $(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES) 153 154clobber: clean clean.lint 155 $(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES) 156 157lint: $$(LINTFILES) 158 159.NO_PARALLEL: 160.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \ 161 $(TARGETS) $(LINTFILES) 162 163$(MODFILE): dmod .WAIT $(MODOBJS) 164 $(LINK.c) $(GSHARED) $(MODOBJS) -o $@ $(LDLIBS) 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) $(LINKTESTOBJ) && \ 186 $(RM) $@.linktest 187 188KMDB_LINKTEST_ENABLE=$(POUND_SIGN) 189$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST) 190 191# 192# Ensure that dmods don't use floating point 193# 194KMDB_FPTEST_CMD = $(KMDB_FPTEST) 195 196$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE) 197 $(LD) -dy -r $(MAPFILE:%=-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) 198 $(KMDB_LINKTEST_CMD) 199 $(KMDB_FPTEST_CMD) 200 $(CTFMERGE) -L VERSION -o $@ $(KMODOBJS) 201 $(SETDYNFLAG) -f DF_1_NOKSYMS $@ 202 203linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS) 204 $(KMDB_LINKTEST) 205 206linktest_check: 207 @if [ "$(MDBTGT)" != "kvm" ] && [ "$(MDBTGT)" != "disasm" ] ; then \ 208 echo "ERROR: linktest is not supported non-kvm/disasm dmods" \ 209 >&2 ; \ 210 exit 1 ; \ 211 fi 212 213# 214# Dynamic rules for object construction 215# 216dmod/%.o kmod/%.o: %.c 217 $(COMPILE.c) -o $@ $< 218 $(CTFCONVERT_O) 219 220dmod/%.o kmod/%.o: ../%.c 221 $(COMPILE.c) -o $@ $< 222 $(CTFCONVERT_O) 223 224dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c 225 $(COMPILE.c) -o $@ $< 226 $(CTFCONVERT_O) 227 228dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c 229 $(COMPILE.c) -o $@ $< 230 $(CTFCONVERT_O) 231 232# 233# Lint 234# 235dmod/%.ln kmod/%.ln: %.c 236 $(LINT.c) -dirout=$(@D) -c $< 237 238dmod/%.ln kmod/%.ln: ../%.c 239 $(LINT.c) -dirout=$(@D) -c $< 240 241dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c 242 $(LINT.c) -dirout=$(@D) -c $< 243 244dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c 245 $(LINT.c) -dirout=$(@D) -c $< 246 247# 248# Installation targets 249# 250 251$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb 252 $(INS.dir) 253 254$(ROOT)/usr/lib/mdb: 255 $(INS.dir) 256 257$(ROOT)/kernel/kmdb: 258 $(INS.dir) 259 260$(ROOTMOD)/$(MODULE): $(ROOTMOD) 261 262$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD) 263 264kmod dmod: 265 -@mkdir -p $@ 266