xref: /illumos-gate/usr/src/uts/Makefile.targ (revision 0aaef2f5)
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 (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23# Copyright 2014 Garrett D'Amore <garrett@damore.org>
24# Copyright 2016 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
25# Copyright (c) 2017 by Delphix. All rights reserved.
26# Copyright 2019 Joyent, Inc.
27#
28#	This Makefiles contains the common targets and definitions for
29#	all kernels. It is to be included in the Makefiles for specific
30#	implementation architectures and processor architecture dependent
31#	modules: i.e.: all driving kernel Makefiles.
32#
33
34#
35#	All C objects depend on inline files. However, cc(1) doesn't generate
36#	the correct dependency info. Also, these Makefiles don't contain a
37#	separate list of C-derived object files (but it is light weight to
38#	let the assembler files think they depend upon this when they don't).
39#	Fortunately, the inline files won't change very often. So, for now,
40#	all objects depend on the inline files. Remove this when the inliner
41#	is fixed to drop correct dependency information.
42#
43$(OBJECTS): $(INLINES)
44
45#
46#	Partially link .o files to generate the kmod. The fake dependency
47#	on modstubs simplifies things...
48#
49$(BINARY):		$(OBJECTS) $(DTRACE_MAPFILE) $(MAPFILE)
50	$(LD) -r $(LDFLAGS) -o $@ $(OBJECTS)
51	$(CTFMERGE_UNIQUIFY_AGAINST_GENUNIX)
52	$(POST_PROCESS)
53
54#
55#	This target checks each kmod for undefined entry points. It does not
56#	modify the kmod in any way.
57#
58$(MODULE).check:	FRC
59	@BUILD_TYPE=DBG32 $(MAKE) $(MODULE).check.targ
60
61$(MODULE).check.targ:	$(BINARY) $(OBJECTS) $(EXTRA_CHECK_OBJS) $(UNIX_O) $(MODSTUBS_O) $(GENLIB)
62	$(LD) -o /dev/null $(OBJECTS) $(EXTRA_CHECK_OBJS) $(UNIX_O) $(MODSTUBS_O) $(GENLIB)
63
64#
65# Since assym.h is a derived file, the dependency must be explicit for all
66# files including this file.  The actual lists are defined in
67# */Makefile.files.
68#
69$(ASSYM_DEPS:%=$(OBJS_DIR)/%):	$(DSF_DIR)/$(OBJS_DIR)/assym.h
70
71#
72#	Everybody need to know how to create a modstubs.o built with the
73#	appropriate flags and located in the appropriate location.
74#
75$(MODSTUBS_O):	$(MODSTUBS)
76	$(COMPILE.s) -o $@ $(MODSTUBS)
77
78#
79# Build the source file which contains the kernel's utsname,
80# with release, version and machine set as follows:
81#
82#	release: contents of $(RELEASE) (Spaces replaced by '_')
83#	version: contents of $(PATCHID) (Spaces replaced by '_')
84#	machine: contents of $(UNAME_M)
85#
86# Build environment information is only contained in the comment section.
87#
88
89$(OBJS_DIR)/vers.o: $(OBJECTS)
90	$(COMPILE.c) -DUTS_RELEASE=\"`$(ECHO) $(RELEASE) | sed -e 's/ /_/g'`\" \
91	    -DUTS_VERSION=\"`$(ECHO) $(PATCHID) | sed -e 's/ /_/g'`\" \
92	    -DUTS_PLATFORM=\"$(UNAME_M)\" -o $@ $(SRC)/uts/common/os/vers.c
93	$(CTFCONVERT_O)
94	$(POST_PROCESS_O)
95
96#
97#	Installation targets and rules:
98#
99$(ROOT_MOD_DIR) $(USR_MOD_DIR):
100	-$(INS.dir)
101
102$(ROOT_MOD_DIRS_32):	$(ROOT_MOD_DIR)
103	-$(INS.dir)
104
105$(USR_MOD_DIRS_32):	$(USR_MOD_DIR)
106	-$(INS.dir)
107
108$(ROOT_MOD_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MOD_DIR) FRC
109	$(INS.file)
110
111$(ROOT_CPU_DIR)/%:	$(OBJS_DIR)/% $(ROOT_CPU_DIR) FRC
112	$(INS.file)
113
114$(ROOT_DRV_DIR)/%:	$(OBJS_DIR)/% $(ROOT_DRV_DIR) FRC
115	$(INS.file)
116
117$(ROOT_DTRACE_DIR)/%:	$(OBJS_DIR)/% $(ROOT_DTRACE_DIR) FRC
118	$(INS.file)
119
120$(ROOT_EXEC_DIR)/%:	$(OBJS_DIR)/% $(ROOT_EXEC_DIR) FRC
121	$(INS.file)
122
123$(ROOT_FS_DIR)/%:	$(OBJS_DIR)/% $(ROOT_FS_DIR) FRC
124	$(INS.file)
125
126$(ROOT_SCHED_DIR)/%:	$(OBJS_DIR)/% $(ROOT_SCHED_DIR) FRC
127	$(INS.file)
128
129$(ROOT_SOCK_DIR)/%:	$(OBJS_DIR)/% $(ROOT_SOCK_DIR) FRC
130	$(INS.file)
131
132$(ROOT_STRMOD_DIR)/%:	$(OBJS_DIR)/% $(ROOT_STRMOD_DIR) FRC
133	$(INS.file)
134
135$(ROOT_IPP_DIR)/%:	$(OBJS_DIR)/% $(ROOT_IPP_DIR) FRC
136	$(INS.file)
137
138$(ROOT_SYS_DIR)/%:	$(OBJS_DIR)/% $(ROOT_SYS_DIR) FRC
139	$(INS.file)
140
141$(ROOT_MISC_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MISC_DIR) FRC
142	$(INS.file)
143
144$(ROOT_DACF_DIR)/%:	$(OBJS_DIR)/% $(ROOT_DACF_DIR) FRC
145	$(INS.file)
146
147$(ROOT_BRAND_DIR)/%:	$(OBJS_DIR)/% $(ROOT_BRAND_DIR) FRC
148	$(INS.file)
149
150$(ROOT_CC_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_CC_DIR) FRC
151	$(INS.file)
152
153$(ROOT_CRYPTO_DIR)/%:	$(OBJS_DIR)/% $(ROOT_CRYPTO_DIR) FRC
154	$(INS.file)
155
156$(ROOT_KGSS_DIR)/%:	$(OBJS_DIR)/% $(ROOT_KGSS_DIR) FRC
157	$(INS.file)
158
159$(ROOT_SCSI_VHCI_DIR)/%: $(OBJS_DIR)/% $(ROOT_SCSI_VHCI_DIR) FRC
160	$(INS.file)
161
162$(ROOT_PMCS_FW_DIR)/%:	$(OBJS_DIR)/% $(ROOT_PMCS_FW_DIR) FRC
163	$(INS.file)
164
165$(ROOT_QLC_FW_DIR)/%:	$(OBJS_DIR)/% $(ROOT_QLC_FW_DIR) FRC
166	$(INS.file)
167
168$(ROOT_EMLXS_FW_DIR)/%:	$(OBJS_DIR)/% $(ROOT_EMLXS_FW_DIR) FRC
169	$(INS.file)
170
171$(ROOT_MACH_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MACH_DIR) FRC
172	$(INS.file)
173
174$(ROOT_FONT_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_FONT_DIR) FRC
175	$(INS.file)
176
177$(ROOT_MAC_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_MAC_DIR) FRC
178	$(INS.file)
179
180$(USR_DRV_DIR)/%:	$(OBJS_DIR)/% $(USR_DRV_DIR) FRC
181	$(INS.file)
182
183$(USR_EXEC_DIR)/%:	$(OBJS_DIR)/% $(USR_EXEC_DIR) FRC
184	$(INS.file)
185
186$(USR_FS_DIR)/%:	$(OBJS_DIR)/% $(USR_FS_DIR) FRC
187	$(INS.file)
188
189$(USR_SCHED_DIR)/%:	$(OBJS_DIR)/% $(USR_SCHED_DIR) FRC
190	$(INS.file)
191
192$(USR_SOCK_DIR)/%:	$(OBJS_DIR)/% $(USR_SOCK_DIR) FRC
193	$(INS.file)
194
195$(USR_STRMOD_DIR)/%:	$(OBJS_DIR)/% $(USR_STRMOD_DIR) FRC
196	$(INS.file)
197
198$(USR_SYS_DIR)/%:	$(OBJS_DIR)/% $(USR_SYS_DIR) FRC
199	$(INS.file)
200
201$(USR_MISC_DIR)/%:	$(OBJS_DIR)/% $(USR_MISC_DIR) FRC
202	$(INS.file)
203
204$(USR_DACF_DIR)/%:	$(OBJS_DIR)/% $(USR_DACF_DIR) FRC
205	$(INS.file)
206
207$(USR_PCBE_DIR)/%:	$(OBJS_DIR)/% $(USR_PCBE_DIR) FRC
208	$(INS.file)
209
210$(USR_DTRACE_DIR)/%:	$(OBJS_DIR)/% $(USR_DTRACE_DIR) FRC
211	$(INS.file)
212
213$(USR_BRAND_DIR)/%:	$(OBJS_DIR)/% $(USR_BRAND_DIR) FRC
214	$(INS.file)
215
216$(ROOT_KICONV_DIR)/%:	$(OBJS_DIR)/% $(ROOT_KICONV_DIR) FRC
217	$(INS.file)
218
219$(ROOT_FIRMWARE_DIR)/$(MODULE):
220	$(INS.dir)
221
222$(ROOT_FIRMWARE_DIR)/$(MODULE)/%:= FILEMODE = $(CFILEMODE)
223
224$(ROOT_FIRMWARE_DIR)/$(MODULE)/%: $(ROOT_FIRMWARE_DIR)/$(MODULE) $(FWDIR)/%
225	$(INS.file)
226
227include $(SRC)/Makefile.psm.targ
228
229#
230#	Target for 64b modules
231#
232$(ROOT_KERN_DIR_64):
233	-$(INS.dir)
234
235$(ROOT_KERN_DIR_64)/%:	$(OBJS_DIR)/% $(ROOT_KERN_DIR_64) FRC
236	$(INS.file)
237
238%/$(SUBDIR64):		%
239	-$(INS.dir)
240
241#
242#	Targets for '.conf' file installation.
243#
244$(ROOT_CONFFILE):	$(SRC_CONFFILE)	$(ROOT_CONFFILE:%/$(CONFFILE)=%)
245	$(INS.conffile)
246
247#
248#	Targets for creating links between common platforms. ROOT_PLAT_LINKS
249#	are are the /platform level while ROOT_PLAT_LINKS_2 are one level
250#	down (/platform/`uname -i`/{lib|sbin|kernel}.
251#
252$(ROOT_PLAT_LINKS):
253	$(INS.slink1)
254
255$(ROOT_PLAT_LINKS_2):
256	$(INS.slink2)
257
258$(USR_PLAT_LINKS):
259	$(INS.slink1)
260
261$(USR_PLAT_LINKS_2):
262	$(INS.slink2)
263
264#
265# multiple builds support
266#
267def $(DEF_DEPS)			:= TARGET = def
268all $(ALL_DEPS)			:= TARGET = all
269clean $(CLEAN_DEPS)		:= TARGET = clean
270clobber $(CLOBBER_DEPS)		:= TARGET = clobber
271modlist	$(MODLIST_DEPS)		:= TARGET = modlist
272modlist	$(MODLIST_DEPS)		:= NO_STATE= -K $$MODSTATE$$$$
273install $(INSTALL_DEPS)		:= TARGET = install
274symcheck $(SYM_DEPS)		:= TARGET = symcheck
275
276ALL_TARGS	= def all clean clobber install symcheck
277
278ALL_OBJ32	= $(ALL_TARGS:%=%.obj32)
279
280$(ALL_OBJ32):	FRC
281	@BUILD_TYPE=OBJ32 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
282
283ALL_DEBUG32	= $(ALL_TARGS:%=%.debug32)
284
285$(ALL_DEBUG32):	FRC
286	@BUILD_TYPE=DBG32 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
287
288ALL_OBJ64	= $(ALL_TARGS:%=%.obj64)
289
290$(ALL_OBJ64):	FRC
291	@BUILD_TYPE=OBJ64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
292
293ALL_DEBUG64	= $(ALL_TARGS:%=%.debug64)
294
295$(ALL_DEBUG64):	FRC
296	@BUILD_TYPE=DBG64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
297
298#
299#	Currently only the IP module needs symbol checking on obj64.
300#	Other modules have the same global-objs nm output for debug64 and obj64.
301#
302$(SISCHECK_DEPS):	$(DEF_DEPS)
303	@TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
304	MODSYMS=$(MODULE).symbols.$$TARG; \
305	if [ -f "$(MODULE).global-objs.$$TARG" ]; then \
306		$(GREP) -v '#' $(MODULE).global-objs.$$TARG |$(GREP) . | \
307		    $(SORT) -u > $$MODSYMS.tmp; \
308		$(NM) $$TARG/$(MODULE) |$(GREP) OBJT |$(GREP) -v UNDEF | \
309		    $(CUT) -d'|' -f8 |$(GREP) -v '^___const_' | \
310		    $(GREP) -v '\.[0-9]*$$' |$(SORT) -u \
311		    > $$MODSYMS.tmp.new; \
312		$(DIFF) $$MODSYMS.tmp $$MODSYMS.tmp.new > $$MODSYMS.diff || \
313		    ($(ECHO) "warning: $(MODULE) symbol checking:" \
314		    "global variable(s) introduced and/or removed."; \
315		    $(CAT) $$MODSYMS.diff; exit 1) \
316	fi
317
318$(SISCLEAN_DEPS):
319	-TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
320	MODSYMS=$(MODULE).symbols.$$TARG; \
321	$(RM) $$MODSYMS.tmp $$MODSYMS.tmp.new $$MODSYMS.diff Nothing_to_remove
322
323
324$(OBJS_DIR):
325	-@mkdir -p $@ 2> /dev/null
326
327def.targ:		$(OBJS_DIR) $(ALL_TARGET)
328
329all.targ:		$(OBJS_DIR) $(ALL_TARGET)
330
331install.targ:		$(OBJS_DIR) $(INSTALL_TARGET)
332
333#
334# Support for Install.sh.
335#
336
337modlist:	$(MODLIST_DEPS)
338
339# paths relative to $(ROOT).
340RELMODULE = $(ROOTMODULE:$(ROOT)/%=%)
341RELCONF = $(ROOT_CONFFILE:$(ROOT)/%=%)
342RELLINK = $(ROOTLINK:$(ROOT)/%=%)
343RELUNIX = $(UNIX32_LINK:$(ROOT)/%=%)
344RELSOFTLINKS = $(ROOTSOFTLINKS:$(ROOT)/%=%)
345
346MODSRC:sh=		pwd
347
348#
349# Generate module information for Install.sh, i.e., specify what files
350# Install.sh should include.  Each line looks like
351#   <tag> <srcdir> <arg1> <arg2> ...
352# where <tag> specifies the type of file, <srcdir> gives the source
353# path (useful if there is an error), and <argN> is one or more
354# additional bits of information that Install.sh needs (e.g., source
355# directory, install directory, filtering tags).  See Install.sh for
356# details on the arguments for each tag type, especially the functions
357# copymod, filtmod, and filtimpl.
358#
359# Changes to this target may require corresponding changes to
360# Install.sh.
361#
362# Don't issue a MOD entry if it's not in the install list.
363#
364
365$(MODLIST_DEPS): FRC
366	@case $@ in \
367	*32) \
368		class=32; \
369		[ -n "$(RELMODULE)" ] && relmodule=`dirname $(RELMODULE)`;; \
370	*64) \
371		class=64; \
372		[ -n "$(RELMODULE)" ] && \
373		    relmodule=`dirname $(RELMODULE)`/$(SUBDIR64);; \
374	esac; \
375	if [ -z "$(THISIMPL)" ]; then \
376		impl=all; \
377	else \
378		impl=$(THISIMPL); \
379	fi; \
380	if [ -n "$(ROOTMODULE)" -a -n "$(INSTALL_TARGET)" ]; then \
381		if [ -z "$(MODULE)" ]; then \
382			module=`basename $(ROOTMODULE)`; \
383		else \
384			module=$(MODULE); \
385		fi; \
386		tinstall="$(INSTALL_TARGET)"; \
387		for t in $$tinstall; do \
388			if [ "$(ROOTMODULE)" = $$t ]; then \
389				echo MOD $(MODSRC) $$module $$relmodule \
390				    $$class $$impl; \
391				break; \
392			fi \
393		done \
394	fi; \
395	if [ -n "$(CONF_SRCDIR)" ]; then \
396		tinstall="$(INSTALL_TARGET)"; \
397		for t in $$tinstall; do \
398			if [ $(ROOT_CONFFILE) = $$t ]; then \
399				echo CONF $(MODSRC) $(RELCONF) \
400				    $(MODSRC)/$(CONF_SRCDIR) $$impl $$module; \
401				break; \
402			fi \
403		done \
404	fi; \
405	if [ -n "$(ROOTLINK)" ]; then \
406		rellinks="$(RELLINK)"; \
407		for r in $$rellinks; do \
408			if [ $$class = 32 ]; then \
409				linkdir=`dirname $$r`; \
410			else \
411				linkdir=`dirname $$r`/$(SUBDIR64); \
412			fi; \
413			echo LINK $(MODSRC) $$relmodule $$module \
414				$$linkdir `basename $$r` $$impl; \
415		done \
416	fi; \
417	if [ -n "$(UNIX32_LINK)" ]; then \
418		echo SYMLINK $(MODSRC) $(SUBDIR64)/$(UNIX) \
419		    `dirname $(RELUNIX)` unix $$impl $$module; \
420	fi; \
421	trelsoftlinks="$(RELSOFTLINKS)"; \
422	for t in $$trelsoftlinks; do \
423		if [ $$class = 32 ]; then \
424			linkdir=`dirname $$t`; \
425		else \
426			linkdir=`dirname $$t`/$(SUBDIR64); \
427		fi; \
428		linkname=`basename $$t`; \
429		echo SYMLINK $(MODSRC) $(MODULE) $$linkdir $$linkname \
430		    $$impl $$module; \
431	done
432
433#
434#	Cleanliness is next to ...
435#
436clean.targ:
437	-$(RM) $(CLEANFILES) Nothing_to_remove
438
439clobber.targ:
440	-$(RM) $(CLOBBERFILES) Nothing_to_remove
441
442FRC:
443