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