xref: /illumos-gate/usr/src/uts/Makefile.targ (revision d4039345c8fe6e54a31d17d91e86e393fdcf401b)
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) -ztype=kmod $(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$(ROOT_OVERLAY_DIR)/%:	$(OBJS_DIR)/% $(ROOT_MOD_DIR) $(ROOT_OVERLAY_DIR) FRC
181	$(INS.file)
182
183$(USR_DRV_DIR)/%:	$(OBJS_DIR)/% $(USR_DRV_DIR) FRC
184	$(INS.file)
185
186$(USR_EXEC_DIR)/%:	$(OBJS_DIR)/% $(USR_EXEC_DIR) FRC
187	$(INS.file)
188
189$(USR_FS_DIR)/%:	$(OBJS_DIR)/% $(USR_FS_DIR) FRC
190	$(INS.file)
191
192$(USR_SCHED_DIR)/%:	$(OBJS_DIR)/% $(USR_SCHED_DIR) FRC
193	$(INS.file)
194
195$(USR_SOCK_DIR)/%:	$(OBJS_DIR)/% $(USR_SOCK_DIR) FRC
196	$(INS.file)
197
198$(USR_STRMOD_DIR)/%:	$(OBJS_DIR)/% $(USR_STRMOD_DIR) FRC
199	$(INS.file)
200
201$(USR_SYS_DIR)/%:	$(OBJS_DIR)/% $(USR_SYS_DIR) FRC
202	$(INS.file)
203
204$(USR_MISC_DIR)/%:	$(OBJS_DIR)/% $(USR_MISC_DIR) FRC
205	$(INS.file)
206
207$(USR_DACF_DIR)/%:	$(OBJS_DIR)/% $(USR_DACF_DIR) FRC
208	$(INS.file)
209
210$(USR_PCBE_DIR)/%:	$(OBJS_DIR)/% $(USR_PCBE_DIR) FRC
211	$(INS.file)
212
213$(USR_DTRACE_DIR)/%:	$(OBJS_DIR)/% $(USR_DTRACE_DIR) FRC
214	$(INS.file)
215
216$(USR_BRAND_DIR)/%:	$(OBJS_DIR)/% $(USR_BRAND_DIR) FRC
217	$(INS.file)
218
219$(ROOT_KICONV_DIR)/%:	$(OBJS_DIR)/% $(ROOT_KICONV_DIR) FRC
220	$(INS.file)
221
222$(ROOT_FIRMWARE_DIR)/$(MODULE):
223	$(INS.dir)
224
225$(ROOT_FIRMWARE_DIR)/$(MODULE)/%:= FILEMODE = $(CFILEMODE)
226
227$(ROOT_FIRMWARE_DIR)/$(MODULE)/%: $(ROOT_FIRMWARE_DIR)/$(MODULE) $(FWDIR)/%
228	$(INS.file)
229
230include $(SRC)/Makefile.psm.targ
231
232#
233#	Target for 64b modules
234#
235$(ROOT_KERN_DIR_64):
236	-$(INS.dir)
237
238$(ROOT_KERN_DIR_64)/%:	$(OBJS_DIR)/% $(ROOT_KERN_DIR_64) FRC
239	$(INS.file)
240
241%/$(SUBDIR64):		%
242	-$(INS.dir)
243
244#
245#	Targets for '.conf' file installation.
246#
247$(ROOT_CONFFILE):	$(SRC_CONFFILE)	$(ROOT_CONFFILE:%/$(CONFFILE)=%)
248	$(INS.conffile)
249
250#
251#	Targets for creating links between common platforms. ROOT_PLAT_LINKS
252#	are are the /platform level while ROOT_PLAT_LINKS_2 are one level
253#	down (/platform/`uname -i`/{lib|sbin|kernel}.
254#
255$(ROOT_PLAT_LINKS):
256	$(INS.slink1)
257
258$(ROOT_PLAT_LINKS_2):
259	$(INS.slink2)
260
261$(USR_PLAT_LINKS):
262	$(INS.slink1)
263
264$(USR_PLAT_LINKS_2):
265	$(INS.slink2)
266
267#
268# multiple builds support
269#
270def $(DEF_DEPS)			:= TARGET = def
271all $(ALL_DEPS)			:= TARGET = all
272clean $(CLEAN_DEPS)		:= TARGET = clean
273clobber $(CLOBBER_DEPS)		:= TARGET = clobber
274modlist	$(MODLIST_DEPS)		:= TARGET = modlist
275modlist	$(MODLIST_DEPS)		:= NO_STATE= -K $$MODSTATE$$$$
276install $(INSTALL_DEPS)		:= TARGET = install
277symcheck $(SYM_DEPS)		:= TARGET = symcheck
278
279ALL_TARGS	= def all clean clobber install symcheck
280
281ALL_OBJ32	= $(ALL_TARGS:%=%.obj32)
282
283$(ALL_OBJ32):	FRC
284	@BUILD_TYPE=OBJ32 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
285
286ALL_DEBUG32	= $(ALL_TARGS:%=%.debug32)
287
288$(ALL_DEBUG32):	FRC
289	@BUILD_TYPE=DBG32 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
290
291ALL_OBJ64	= $(ALL_TARGS:%=%.obj64)
292
293$(ALL_OBJ64):	FRC
294	@BUILD_TYPE=OBJ64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
295
296ALL_DEBUG64	= $(ALL_TARGS:%=%.debug64)
297
298$(ALL_DEBUG64):	FRC
299	@BUILD_TYPE=DBG64 VERSION='$(VERSION)' $(MAKE) $(NO_STATE) $(TARGET).targ
300
301#
302#	Currently only the IP module needs symbol checking on obj64.
303#	Other modules have the same global-objs nm output for debug64 and obj64.
304#
305$(SISCHECK_DEPS):	$(DEF_DEPS)
306	@TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
307	MODSYMS=$(MODULE).symbols.$$TARG; \
308	if [ -f "$(MODULE).global-objs.$$TARG" ]; then \
309		$(GREP) -v '#' $(MODULE).global-objs.$$TARG |$(GREP) . | \
310		    $(SORT) -u > $$MODSYMS.tmp; \
311		$(NM) $$TARG/$(MODULE) |$(GREP) OBJT |$(GREP) -v UNDEF | \
312		    $(CUT) -d'|' -f8 |$(GREP) -v '^___const_' | \
313		    $(GREP) -v '\.[0-9]*$$' |$(SORT) -u \
314		    > $$MODSYMS.tmp.new; \
315		$(DIFF) $$MODSYMS.tmp $$MODSYMS.tmp.new > $$MODSYMS.diff || \
316		    ($(ECHO) "warning: $(MODULE) symbol checking:" \
317		    "global variable(s) introduced and/or removed."; \
318		    $(CAT) $$MODSYMS.diff; exit 1) \
319	fi
320
321$(SISCLEAN_DEPS):
322	-TARG=`$(ECHO) $@ | $(CUT) -d'.' -f2`; \
323	MODSYMS=$(MODULE).symbols.$$TARG; \
324	$(RM) $$MODSYMS.tmp $$MODSYMS.tmp.new $$MODSYMS.diff Nothing_to_remove
325
326
327$(OBJS_DIR):
328	-@mkdir -p $@ 2> /dev/null
329
330def.targ:		$(OBJS_DIR) $(ALL_TARGET)
331
332all.targ:		$(OBJS_DIR) $(ALL_TARGET)
333
334install.targ:		$(OBJS_DIR) $(INSTALL_TARGET)
335
336#
337# Support for Install.sh.
338#
339
340modlist:	$(MODLIST_DEPS)
341
342# paths relative to $(ROOT).
343RELMODULE = $(ROOTMODULE:$(ROOT)/%=%)
344RELCONF = $(ROOT_CONFFILE:$(ROOT)/%=%)
345RELLINK = $(ROOTLINK:$(ROOT)/%=%)
346RELUNIX = $(UNIX32_LINK:$(ROOT)/%=%)
347RELSOFTLINKS = $(ROOTSOFTLINKS:$(ROOT)/%=%)
348
349MODSRC:sh=		pwd
350
351#
352# Generate module information for Install.sh, i.e., specify what files
353# Install.sh should include.  Each line looks like
354#   <tag> <srcdir> <arg1> <arg2> ...
355# where <tag> specifies the type of file, <srcdir> gives the source
356# path (useful if there is an error), and <argN> is one or more
357# additional bits of information that Install.sh needs (e.g., source
358# directory, install directory, filtering tags).  See Install.sh for
359# details on the arguments for each tag type, especially the functions
360# copymod, filtmod, and filtimpl.
361#
362# Changes to this target may require corresponding changes to
363# Install.sh.
364#
365# Don't issue a MOD entry if it's not in the install list.
366#
367
368$(MODLIST_DEPS): FRC
369	@case $@ in \
370	*32) \
371		class=32; \
372		[ -n "$(RELMODULE)" ] && relmodule=`dirname $(RELMODULE)`;; \
373	*64) \
374		class=64; \
375		[ -n "$(RELMODULE)" ] && \
376		    relmodule=`dirname $(RELMODULE)`/$(SUBDIR64);; \
377	esac; \
378	if [ -z "$(THISIMPL)" ]; then \
379		impl=all; \
380	else \
381		impl=$(THISIMPL); \
382	fi; \
383	if [ -n "$(ROOTMODULE)" -a -n "$(INSTALL_TARGET)" ]; then \
384		if [ -z "$(MODULE)" ]; then \
385			module=`basename $(ROOTMODULE)`; \
386		else \
387			module=$(MODULE); \
388		fi; \
389		tinstall="$(INSTALL_TARGET)"; \
390		for t in $$tinstall; do \
391			if [ "$(ROOTMODULE)" = $$t ]; then \
392				echo MOD $(MODSRC) $$module $$relmodule \
393				    $$class $$impl; \
394				break; \
395			fi \
396		done \
397	fi; \
398	if [ -n "$(CONF_SRCDIR)" ]; then \
399		tinstall="$(INSTALL_TARGET)"; \
400		for t in $$tinstall; do \
401			if [ $(ROOT_CONFFILE) = $$t ]; then \
402				echo CONF $(MODSRC) $(RELCONF) \
403				    $(MODSRC)/$(CONF_SRCDIR) $$impl $$module; \
404				break; \
405			fi \
406		done \
407	fi; \
408	if [ -n "$(ROOTLINK)" ]; then \
409		rellinks="$(RELLINK)"; \
410		for r in $$rellinks; do \
411			if [ $$class = 32 ]; then \
412				linkdir=`dirname $$r`; \
413			else \
414				linkdir=`dirname $$r`/$(SUBDIR64); \
415			fi; \
416			echo LINK $(MODSRC) $$relmodule $$module \
417				$$linkdir `basename $$r` $$impl; \
418		done \
419	fi; \
420	if [ -n "$(UNIX32_LINK)" ]; then \
421		echo SYMLINK $(MODSRC) $(SUBDIR64)/$(UNIX) \
422		    `dirname $(RELUNIX)` unix $$impl $$module; \
423	fi; \
424	trelsoftlinks="$(RELSOFTLINKS)"; \
425	for t in $$trelsoftlinks; do \
426		if [ $$class = 32 ]; then \
427			linkdir=`dirname $$t`; \
428		else \
429			linkdir=`dirname $$t`/$(SUBDIR64); \
430		fi; \
431		linkname=`basename $$t`; \
432		echo SYMLINK $(MODSRC) $(MODULE) $$linkdir $$linkname \
433		    $$impl $$module; \
434	done
435
436#
437#	Cleanliness is next to ...
438#
439clean.targ:
440	-$(RM) $(CLEANFILES) Nothing_to_remove
441
442clobber.targ:
443	-$(RM) $(CLOBBERFILES) Nothing_to_remove
444
445FRC:
446