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