xref: /illumos-gate/usr/src/cmd/mdb/Makefile.module (revision d17be682a2c70b4505d43c830bbd2603da11918d)
17c478bd9Sstevel@tonic-gate#
27c478bd9Sstevel@tonic-gate# CDDL HEADER START
37c478bd9Sstevel@tonic-gate#
47c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
5dc0093f4Seschrock# Common Development and Distribution License (the "License").
6dc0093f4Seschrock# You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate#
87c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate# and limitations under the License.
127c478bd9Sstevel@tonic-gate#
137c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate#
197c478bd9Sstevel@tonic-gate# CDDL HEADER END
207c478bd9Sstevel@tonic-gate#
217c478bd9Sstevel@tonic-gate#
2224fe0b3bSjmcp# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate#
252a12f85aSJeremy Jones# Copyright (c) 2013 by Delphix. All rights reserved.
26542a7b7fSCarlos Neira# Copyright (c) 2019 Carlos Neira <cneirabustos@gmail.com>
27542a7b7fSCarlos Neira# Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
2806abc743SJohn Levon# Copyright 2019 Joyent, Inc.
292a12f85aSJeremy Jones#
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate.KEEP_STATE:
327c478bd9Sstevel@tonic-gate.SUFFIXES:
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gateinclude $(SRC)/cmd/mdb/Makefile.tools
357c478bd9Sstevel@tonic-gate
369f923083SAlexander Pyhalov#
379f923083SAlexander Pyhalov# Make sure we're getting a consistent execution environment for the
389f923083SAlexander Pyhalov# embedded scripts.
399f923083SAlexander Pyhalov#
409f923083SAlexander PyhalovSHELL= /usr/bin/ksh93
419f923083SAlexander Pyhalov
427c478bd9Sstevel@tonic-gate$(KMOD_SOURCES_DIFFERENT)KMODSRCS = $(MODSRCS)
43799823bbSRobert Mustacchi$(KMOD_SOURCES_DIFFERENT)KMODASMSRCS = $(MODASMSRCS)
447c478bd9Sstevel@tonic-gate
455d9d9091SRichard LoweMODOBJS = $(MODSRCS:%.c=dmod/%.o) $(MODASMSRCS:%.S=dmod/%.o)
465d9d9091SRichard LoweKMODOBJS = $(KMODSRCS:%.c=kmod/%.o) $(KMODASMSRCS:%.S=kmod/%.o)
477c478bd9Sstevel@tonic-gate
489f923083SAlexander PyhalovMODNAME_cmd = if [ -n "$(MODULE_NAME)" ]; then print $(MODULE_NAME); else print $(MODULE)| sed -e 's:\.so$$::'; fi
499f923083SAlexander PyhalovMODNAME = $(MODNAME_cmd:sh)
507c478bd9Sstevel@tonic-gateKMODULE = $(MODNAME)
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gateMODFILE = dmod/$(MODULE)
537c478bd9Sstevel@tonic-gateKMODFILE = kmod/$(KMODULE)
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate#
5685f4cb87SRichard Lowe# The mess below is designed to pick the right set of objects to build .
5785f4cb87SRichard Lowe# We have three flavors:
587c478bd9Sstevel@tonic-gate#
591a7c1b72Smws#  1. proc and raw modules.  Only $(MODOBJS) are built.
607c478bd9Sstevel@tonic-gate#  2. kvm modules for systems without kmdb.  Only $(MODOBJS) are built.
617c478bd9Sstevel@tonic-gate#  3. kvm modules for systems with kmdb.  $(MODOBJS) and $(KMODOBJS) are built.
627c478bd9Sstevel@tonic-gate#
637c478bd9Sstevel@tonic-gate# Complicating matters, we'd like to make the distinction between 2 and 3 before
647c478bd9Sstevel@tonic-gate# this Makefile is loaded.  By default, we'll assume that all kvm modules should
657c478bd9Sstevel@tonic-gate# be built for kmdb.  If, however, the user sets $(MODULE_BUILD_TYPE) to `mdb',
667c478bd9Sstevel@tonic-gate# the kmdb variant of the module won't be built.
677c478bd9Sstevel@tonic-gate#
687c478bd9Sstevel@tonic-gate
697c478bd9Sstevel@tonic-gate# Which flavors are to be built?
707c478bd9Sstevel@tonic-gateTARGETS_kvm_type_	= both	# Build both if $(MODULE_BUILD_TYPE) is unset
717c478bd9Sstevel@tonic-gateTARGETS_kvm_type_kmdb	= both
727c478bd9Sstevel@tonic-gateTARGETS_kvm_type_mdb	= mdb
737c478bd9Sstevel@tonic-gateTARGETS_kvm_type	= $(TARGETS_kvm_type_$(MODULE_BUILD_TYPE))
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate# What should we build?
767c478bd9Sstevel@tonic-gateTARGETS_kvm_kmdb	= $(KMODFILE)
777c478bd9Sstevel@tonic-gateTARGETS_kvm_mdb		= $(MODFILE)
787c478bd9Sstevel@tonic-gateTARGETS_kvm_both	= $(TARGETS_kvm_mdb) $(TARGETS_kvm_kmdb)
797c478bd9Sstevel@tonic-gateTARGETS_kvm		= $(TARGETS_kvm_$(TARGETS_kvm_type))
807c478bd9Sstevel@tonic-gateTARGETS_proc		= $(MODFILE)
811a7c1b72SmwsTARGETS_raw		= $(MODFILE)
827c478bd9Sstevel@tonic-gateTARGETS			= $(TARGETS_$(MDBTGT))
837c478bd9Sstevel@tonic-gate
847c478bd9Sstevel@tonic-gate# Where should we install that which we've built?
857c478bd9Sstevel@tonic-gateROOTTGTS_kvm_type	= $(TARGETS_kvm_type)	# overridden by mdb_ks
867c478bd9Sstevel@tonic-gateROOTTGTS_kvm_kmdb	= $(ROOTKMOD)/$(KMODULE)
877c478bd9Sstevel@tonic-gateROOTTGTS_kvm_mdb	= $(ROOTMOD)/$(MODULE)
887c478bd9Sstevel@tonic-gateROOTTGTS_kvm_both	= $(ROOTTGTS_kvm_mdb) $(ROOTTGTS_kvm_kmdb)
897c478bd9Sstevel@tonic-gateROOTTGTS_kvm		= $(ROOTTGTS_kvm_$(ROOTTGTS_kvm_type))
907c478bd9Sstevel@tonic-gateROOTTGTS_proc		= $(ROOTMOD)/$(MODULE)
911a7c1b72SmwsROOTTGTS_raw		= $(ROOTMOD)/$(MODULE)
927c478bd9Sstevel@tonic-gateROOTTGTS		= $(ROOTTGTS_$(MDBTGT))
937c478bd9Sstevel@tonic-gate
94259e5438SRobert Mustacchi#
95259e5438SRobert Mustacchi# Python specific flags. To try and make life easier for folks how are
96259e5438SRobert Mustacchi# building with an LFS python, we attempt to use -isystem when it's
97259e5438SRobert Mustacchi# available.
98259e5438SRobert Mustacchi#
9970143b9fSRichard LowePYCPPFLAGS		= -_gcc=-isystem -_gcc=$(ADJUNCT_PROTO)/usr/include/python$(PYTHON3_VERSION)$(PYTHON3_SUFFIX)
10070143b9fSRichard LowePYLNFLAGS		= -I$(ADJUNCT_PROTO)/usr/include/python$(PYTHON3_VERSION)$(PYTHON3_SUFFIX)
101259e5438SRobert Mustacchi
1027c478bd9Sstevel@tonic-gatekvm_TGTFLAGS		= -D_KERNEL
1037c478bd9Sstevel@tonic-gateproc_TGTFLAGS		= -D_USER
1047c478bd9Sstevel@tonic-gate
105bd0ce624SYuri PankovCSTD			= $(CSTD_GNU99)
1062a12f85aSJeremy Jones
1077c478bd9Sstevel@tonic-gateCFLAGS			+= $(CCVERBOSE)
1087c478bd9Sstevel@tonic-gateCFLAGS64		+= $(CCVERBOSE)
109259e5438SRobert MustacchiCPPFLAGS		+= $($(MDBTGT)_TGTFLAGS) -I../../../common
11067e3a03eSrieLDFLAGS			+= $(ZTEXT)
11167e3a03eSrieLDFLAGS64		+= $(ZTEXT)
112799823bbSRobert MustacchiAS_CPPFLAGS		+= -D_ASM
1137c478bd9Sstevel@tonic-gate
1145661bb76SJohn LevonSMOFF += all_func_returns,index_overflow
1155661bb76SJohn Levon
1167c478bd9Sstevel@tonic-gate# Module type-specific compiler flags
117*d17be682SRichard Lowe$(MODOBJS) :=	CFLAGS += $(C_BIGPICFLAGS)
118*d17be682SRichard Lowe$(MODOBJS) :=	CFLAGS64 += $(C_BIGPICFLAGS)
11985f4cb87SRichard Lowe$(KMODOBJS) :=	CPPFLAGS += -D_KMDB
1207c478bd9Sstevel@tonic-gate$(KMODOBJS) :=	DTS_ERRNO =
1215a0af816SRobert Mustacchi$(KMODFILE) :=	STACKPROTECT = none
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate# Modules aren't allowed to export symbols
1247c478bd9Sstevel@tonic-gateMAPFILE		= $(SRC)/cmd/mdb/common/modules/conf/mapfile
1257c478bd9Sstevel@tonic-gate
12667e3a03eSrie# Modules typically make external references.  To provide for -zdefs use
12767e3a03eSrie# and clean ldd(1) processing, explicitly define all external references.
12867e3a03eSrieMAPFILE-EXT	= $(SRC)/cmd/mdb/common/modules/conf/mapfile-extern
12967e3a03eSrie
1307c478bd9Sstevel@tonic-gate#
1317c478bd9Sstevel@tonic-gate# kmdb is a kernel module, so we'll use the kernel's build flags.
1327c478bd9Sstevel@tonic-gate$(KMODOBJS) := CFLAGS64 += $(STAND_FLAGS_64)
1337c478bd9Sstevel@tonic-gate
1347c478bd9Sstevel@tonic-gate#
1357c478bd9Sstevel@tonic-gate# Override this to pull source files from another directory
1367c478bd9Sstevel@tonic-gate#
1377c478bd9Sstevel@tonic-gateMODSRCS_DIR = ../../../common/modules/genunix
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gateall: $$(TARGETS)
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gateinstall: all $$(ROOTTGTS)
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gatedmods: install
1447c478bd9Sstevel@tonic-gate
1457c478bd9Sstevel@tonic-gateclean:
1461a7c1b72Smws	$(RM) $(MODOBJS) $(KMODOBJS) $(CLEANFILES)
1477c478bd9Sstevel@tonic-gate
14885f4cb87SRichard Loweclobber: clean
1491a7c1b72Smws	$(RM) $(MODFILE) $(KMODFILE) $(CLOBBERFILES)
1507c478bd9Sstevel@tonic-gate
1517c478bd9Sstevel@tonic-gate.NO_PARALLEL:
1527c478bd9Sstevel@tonic-gate.PARALLEL: $(MODOBJS) $(KMODOBJS) mdb_tgt kmdb_tgt dmod kmod \
15385f4cb87SRichard Lowe	$(TARGETS)
1547c478bd9Sstevel@tonic-gate
15567e3a03eSrie$(MODFILE): dmod .WAIT $(MODOBJS) $$(MAPFILE-EXT)
15685f4cb87SRichard Lowe	$(LINK.c) $(ZDEFS) $(ZIGNORE) $(MAPFILE-EXT:%=-Wl,-M%) $(GSHARED) \
157542a7b7fSCarlos Neira	    $(MODOBJS) -o $@ $(LDLIBS) -lc -lproc
1587c478bd9Sstevel@tonic-gate	$(CTFMERGE) -L VERSION -o $@ $(MODOBJS)
1597c478bd9Sstevel@tonic-gate	$(POST_PROCESS_SO)
1607c478bd9Sstevel@tonic-gate
1617c478bd9Sstevel@tonic-gate#
1627c478bd9Sstevel@tonic-gate# kmdb dmods must *not* stray from the module API.  To ensure that they don't,
1637c478bd9Sstevel@tonic-gate# we try to link them, at build time, against an object that exports the symbols
1647c478bd9Sstevel@tonic-gate# that they can legally use.  The link test object is, however, only built when
1657c478bd9Sstevel@tonic-gate# kmdb itself is built.  Requiring module developers to build kmdb first would
1667c478bd9Sstevel@tonic-gate# be painful, so by default, module-level builds don't do the link test (the
1677c478bd9Sstevel@tonic-gate# $(POUND_SIGN) assignment below takes care of that).  Builds of the entire
1687c478bd9Sstevel@tonic-gate# tree can, however, guarantee the construction of kmdb first, and as such can
1697c478bd9Sstevel@tonic-gate# override the setting of $(KMDB_LINKTEST_ENABLE).  This override causes the
1707c478bd9Sstevel@tonic-gate# link test to be run.
1717c478bd9Sstevel@tonic-gate#
1727c478bd9Sstevel@tonic-gate# Developers wanting to force a link test for a single module can use the
1737c478bd9Sstevel@tonic-gate# `linktest' target from within a module directory.
1747c478bd9Sstevel@tonic-gate#
1757c478bd9Sstevel@tonic-gateLINKTESTOBJ = $(KMDBDIR)/kmdb_modlinktest.o
1767c478bd9Sstevel@tonic-gate
1777c478bd9Sstevel@tonic-gateKMDB_LINKTEST = \
17882d0151aSRichard Lowe	$(LD) $(ZDEFS) -ztype=kmod -o $@.linktest $(KMODOBJS) \
179dc0093f4Seschrock	$(STANDOBJS) $(LINKTESTOBJ) && \
1807c478bd9Sstevel@tonic-gate	$(RM) $@.linktest
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gateKMDB_LINKTEST_ENABLE=$(POUND_SIGN)
1837c478bd9Sstevel@tonic-gate$(KMDB_LINKTEST_ENABLE)KMDB_LINKTEST_CMD = $(KMDB_LINKTEST)
1847c478bd9Sstevel@tonic-gate
18582d0151aSRichard Lowe# Allow overriding this because mdb_ks is special case fake module,
18682d0151aSRichard Lowe# see Makefile.mdb_ks
18782d0151aSRichard LoweKMODFLAG = -ztype=kmod
18882d0151aSRichard Lowe
1897c478bd9Sstevel@tonic-gate$(KMODFILE): kmod .WAIT $(KMODOBJS) $(MAPFILE)
19082d0151aSRichard Lowe	$(LD) $(KMODFLAG) $(MAPFILE:%=-Wl,-M%) -Nmisc/kmdbmod -o $@ $(KMODOBJS) \
191dc0093f4Seschrock	$(STANDOBJS)
1927c478bd9Sstevel@tonic-gate	$(KMDB_LINKTEST_CMD)
19306abc743SJohn Levon	$(CTFMERGE) -l "$(UTS_LABEL)" -o $@ $(KMODOBJS)
1946ddb3373SRichard Lowe	$(POST_PROCESS)
1957c478bd9Sstevel@tonic-gate	$(SETDYNFLAG) -f DF_1_NOKSYMS $@
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gatelinktest: linktest_check .WAIT kmod .WAIT $(KMODOBJS)
1987c478bd9Sstevel@tonic-gate	$(KMDB_LINKTEST)
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gatelinktest_check:
201dc0093f4Seschrock	@if [ "$(MDBTGT)" != "kvm" ] ; then \
2027c478bd9Sstevel@tonic-gate		echo "ERROR: linktest is not supported non-kvm/disasm dmods" \
2037c478bd9Sstevel@tonic-gate		    >&2 ; \
2047c478bd9Sstevel@tonic-gate		exit 1 ; \
2057c478bd9Sstevel@tonic-gate	fi
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate#
2087c478bd9Sstevel@tonic-gate# Dynamic rules for object construction
2097c478bd9Sstevel@tonic-gate#
2107c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: %.c
2117c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
2127c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
2137c478bd9Sstevel@tonic-gate
2145d9d9091SRichard Lowedmod/%.o kmod%.o: %.S
215799823bbSRobert Mustacchi	$(COMPILE.s) -o $@ $<
216799823bbSRobert Mustacchi
2177c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: ../%.c
2187c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
2197c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
2207c478bd9Sstevel@tonic-gate
2215d9d9091SRichard Lowedmod/%.o kmod%.o: ../%.S
222799823bbSRobert Mustacchi	$(COMPILE.s) -o $@ $<
223799823bbSRobert Mustacchi
2247c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: ../../../common/modules/$(MODNAME)/%.c
2257c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
2267c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
2277c478bd9Sstevel@tonic-gate
2285d9d9091SRichard Lowedmod/%.o kmod%.o: ../../../common/modules/$(MODNAME)/%.S
229799823bbSRobert Mustacchi	$(COMPILE.s) -o $@ $<
230799823bbSRobert Mustacchi
2317c478bd9Sstevel@tonic-gatedmod/%.o kmod/%.o: $$(MODSRCS_DIR)/%.c
2327c478bd9Sstevel@tonic-gate	$(COMPILE.c) -o $@ $<
2337c478bd9Sstevel@tonic-gate	$(CTFCONVERT_O)
2347c478bd9Sstevel@tonic-gate
2355d9d9091SRichard Lowedmod/%.o kmod%.o: $$(MODSRCS_DIR)/%.S
236799823bbSRobert Mustacchi	$(COMPILE.s) -o $@ $<
237799823bbSRobert Mustacchi
2387c478bd9Sstevel@tonic-gate#
2397c478bd9Sstevel@tonic-gate# Installation targets
2407c478bd9Sstevel@tonic-gate#
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate$(ROOT)/usr/lib/mdb/$(MDBTGT): $(ROOT)/usr/lib/mdb
2437c478bd9Sstevel@tonic-gate	$(INS.dir)
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate$(ROOT)/usr/lib/mdb:
2467c478bd9Sstevel@tonic-gate	$(INS.dir)
2477c478bd9Sstevel@tonic-gate
2487c478bd9Sstevel@tonic-gate$(ROOT)/kernel/kmdb:
2497c478bd9Sstevel@tonic-gate	$(INS.dir)
2507c478bd9Sstevel@tonic-gate
2517c478bd9Sstevel@tonic-gate$(ROOTMOD)/$(MODULE): $(ROOTMOD)
2527c478bd9Sstevel@tonic-gate
2537c478bd9Sstevel@tonic-gate$(ROOTKMOD)/$(KMODULE): $(ROOTKMOD)
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gatekmod dmod:
2567c478bd9Sstevel@tonic-gate	-@mkdir -p $@
257