Home | History | Annotate | Download | only in mdb
      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 
     26 .KEEP_STATE:
     27 .SUFFIXES:
     28 
     29 include $(SRC)/cmd/mdb/Makefile.tools
     30 
     31 $(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
     32 
     33 MODOBJS = $(MODSRCS:%.c=dmod/%.o)
     34 KMODOBJS = $(KMODSRCS:%.c=kmod/%.o)
     35 
     36 MODNAME = $(MODULE:%.so=%)
     37 KMODULE = $(MODNAME)
     38 
     39 MODFILE = dmod/$(MODULE)
     40 KMODFILE = kmod/$(KMODULE)
     41 
     42 #
     43 # The mess below is designed to pick the right set of objects to build and/or
     44 # lint.  We have three flavors:
     45 #
     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.
     49 #
     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.
     54 #
     55 
     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))
     61 
     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))
     70 
     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))
     80 
     81 # What should we lint?
     82 KLINTOBJS		= $(KMODOBJS:%.o=%.ln)
     83 LINTOBJS		= $(MODOBJS:%.o=%.ln)
     84 
     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))
     92 
     93 kvm_TGTFLAGS		= -D_KERNEL
     94 proc_TGTFLAGS		= -D_USER
     95 
     96 CFLAGS			+= $(CCVERBOSE)
     97 CFLAGS64		+= $(CCVERBOSE)
     98 CPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
     99 LDFLAGS			+= $(ZTEXT)
    100 LDFLAGS64		+= $(ZTEXT)
    101 
    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 =
    108 
    109 # Modules aren't allowed to export symbols
    110 MAPFILE		= $(SRC)/cmd/mdb/common/modules/conf/mapfile
    111 
    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
    115 
    116 #
    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)
    120 
    121 #
    122 # Override this to pull source files from another directory
    123 #
    124 MODSRCS_DIR = ../../../common/modules/genunix
    125 
    126 all: $$(TARGETS)
    127 
    128 install: all $$(ROOTTGTS)
    129 
    130 dmods: install
    131 
    132 clean.lint:
    133 	$(RM) $(LINTFILES)
    134 
    135 clean:
    136 	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
    137 
    138 clobber: clean clean.lint
    139 	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
    140 
    141 lint: $$(LINTFILES)
    142 
    143 .NO_PARALLEL:
    144 .PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
    145 	$(TARGETS) $(LINTFILES)
    146 
    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)
    151 	$(POST_PROCESS_SO)
    152 
    153 #
    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.
    163 #
    164 # Developers wanting to force a link test for a single module can use the
    165 # `linktest' target from within a module directory.
    166 #
    167 LINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
    168 
    169 KMDB_LINKTEST = \
    170 	$(LD) $(ZDEFS) -dy -r -o $@.linktest $(KMODOBJS) \
    171 	$(STANDOBJS) $(LINKTESTOBJ) && \
    172 	$(RM) $@.linktest
    173 
    174 KMDB_LINKTEST_ENABLE=$(POUND_SIGN)
    175 $(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
    176 
    177 #
    178 # Ensure that dmods don't use floating point
    179 #
    180 KMDB_FPTEST_CMD = $(KMDB_FPTEST)
    181 
    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 	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
    189 
    190 linktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
    191 	$(KMDB_LINKTEST)
    192 
    193 linktest_check:
    194 	@if [ "$(MDBTGT)" != "kvm" ] ; then \
    195 		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
    196 		    >&2 ; \
    197 		exit 1 ; \
    198 	fi
    199 
    200 #
    201 # Dynamic rules for object construction
    202 #
    203 dmod/%.o kmod/%.o: %.c
    204 	$(COMPILE.c) -o $@ $<
    205 	$(CTFCONVERT_O)
    206 
    207 dmod/%.o kmod/%.o: ../%.c
    208 	$(COMPILE.c) -o $@ $<
    209 	$(CTFCONVERT_O)
    210 
    211 dmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
    212 	$(COMPILE.c) -o $@ $<
    213 	$(CTFCONVERT_O)
    214 
    215 dmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
    216 	$(COMPILE.c) -o $@ $<
    217 	$(CTFCONVERT_O)
    218 
    219 #
    220 # Lint
    221 #
    222 dmod/%.ln kmod/%.ln: %.c
    223 	$(LINT.c) -dirout=$(@D) -c $<
    224 
    225 dmod/%.ln kmod/%.ln: ../%.c
    226 	$(LINT.c) -dirout=$(@D) -c $<
    227 
    228 dmod/%.ln kmod/%.ln: ../../../common/modules/$(MODNAME)/%.c
    229 	$(LINT.c) -dirout=$(@D) -c $<
    230 
    231 dmod/%.ln kmod/%.ln: $$(MODSRCS_DIR)/%.c
    232 	$(LINT.c) -dirout=$(@D) -c $<
    233 
    234 #
    235 # Installation targets
    236 #
    237 
    238 $(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
    239 	$(INS.dir)
    240 
    241 $(ROOT)/usr/lib/mdb:
    242 	$(INS.dir)
    243 
    244 $(ROOT)/kernel/kmdb:
    245 	$(INS.dir)
    246 
    247 $(ROOTMOD)/$(MODULE): $(ROOTMOD)
    248 
    249 $(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
    250 
    251 kmod dmod:
    252 	-@mkdir -p $@
    253