]> git.saurik.com Git - apple/xnu.git/blame - makedefs/MakeInc.rule
xnu-3248.60.10.tar.gz
[apple/xnu.git] / makedefs / MakeInc.rule
CommitLineData
39236c6e
A
1# -*- mode: makefile;-*-
2#
3# Copyright (C) 1999-2012 Apple Inc. All rights reserved.
4#
5# MakeInc.rule defines the targets and rules for
6# leaf directories once MakeInc.dir has recursed
7# into them. "do_XXX" may be double-colon rules
8# to allow the Makefile in the source directory
9# to augment the actions that will be performed.
10#
11
1c79356b
A
12#
13# Generic Install rules
14#
15
91447636
A
16ifndef INSTALL_KF_MI_LCL_LIST
17 INSTALL_KF_MI_LCL_LIST = $(EXPORT_MI_LIST)
18endif
1c79356b 19
91447636
A
20ifndef INSTALL_KF_MI_LCL_GEN_LIST
21 INSTALL_KF_MI_LCL_GEN_LIST = $(EXPORT_MI_GEN_LIST)
22endif
1c79356b 23
91447636
A
24ifndef INSTALL_KF_MD_LCL_LIST
25 INSTALL_KF_MD_LCL_LIST = $(EXPORT_MD_LIST)
26endif
1c79356b 27
91447636
A
28ifndef INSTALL_KF_MD_LCL_GEN_LIST
29 INSTALL_KF_MD_LCL_GEN_LIST = $(EXPORT_MD_GEN_LIST)
30endif
9bccf70c 31
91447636
A
32ifndef INSTALL_KF_MI_LIST
33 INSTALL_KF_MI_LIST = $(EXPORT_MI_LIST)
34endif
1c79356b 35
91447636
A
36ifndef INSTALL_KF_MI_GEN_LIST
37 INSTALL_KF_MI_GEN_LIST = $(EXPORT_MI_GEN_LIST)
38endif
9bccf70c 39
91447636
A
40ifndef INSTALL_KF_MD_LIST
41 INSTALL_KF_MD_LIST = $(EXPORT_MD_LIST)
42endif
9bccf70c 43
91447636
A
44ifndef INSTALL_KF_MD_GEN_LIST
45 INSTALL_KF_MD_GEN_LIST = $(EXPORT_MD_GEN_LIST)
46endif
47
39236c6e 48.PHONY: ALWAYS
2d21ac55 49
39236c6e 50ALWAYS:
91447636 51
39236c6e
A
52# $(1) is the list of install paths
53# $(2) is "1" if it's a "GEN"-style rule that looks locally, or else $(SOURCE)
54# $(3) is the local temp directory for processing
55# $(4) is the unifdef flags
56#
57# $$$$$$$$ is a double-escaped "$$" to represent the current pid
58# of the shell process for creating uniquely named temporary files
91447636 59
39236c6e 60define INSTALLHDRS_RULE_template
9bccf70c 61
39236c6e
A
62.PHONY: $(3)_MKDIR
63
64$(3)_MKDIR:
65 $$(_v)$$(MKDIR) ./$(3)
66 $$(_v)$$(MKDIR) $(dir $(firstword $(1)))
67
fe8ab488
A
68# Rebuild if unifdef flags change
69$(1): $(3)/.UNIFDEF_FLAGS
70$(3)/.UNIFDEF_FLAGS: ALWAYS | $(3)_MKDIR
71 $$(_v)$$(REPLACECONTENTS) $$@ $$(UNIFDEF) $(4)
72
39236c6e
A
73$(1): $(dir $(firstword $(1)))% : $(if $(2),%,$$(SOURCE)/%) | $(3)_MKDIR
74 @echo INSTALLHDR $$*
75 $$(_v)$$(UNIFDEF) $(4) $$< > ./$(3)/$$*.unifdef.$$$$$$$$; \
76 if [ $$$$? -eq 2 ]; then \
77 echo Parse failure for $$<; \
78 exit 1; \
91447636 79 fi; \
39236c6e
A
80 $$(DECOMMENT) ./$(3)/$$*.unifdef.$$$$$$$$ r > \
81 ./$(3)/$$*.strip.$$$$$$$$ || exit 1; \
82 if [ -s ./$(3)/$$*.strip.$$$$$$$$ ]; then \
83 $$(INSTALL) $$(INSTALL_FLAGS) ./$(3)/$$*.unifdef.$$$$$$$$ $$@ || exit 1; \
91447636 84 fi; \
39236c6e
A
85 $$(RM) ./$(3)/$$*.unifdef.$$$$$$$$ ./$(3)/$$*.strip.$$$$$$$$
86endef
87
88#
89# Machine-independent (public) files
90#
91
92INSTALL_MI_INC_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_LIST))
93INSTALL_MI_INC_GEN_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MI_DIR)/, $(INSTALL_MI_GEN_LIST))
94
95$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_INC_FILES),,incmidir,$(SINCFRAME_UNIFDEF)))
96$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_INC_GEN_FILES),1,incmigendir,$(SINCFRAME_UNIFDEF)))
1c79356b 97
39236c6e
A
98INSTALL_KF_MI_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LIST))
99INSTALL_KF_MI_GEN_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_GEN_LIST))
100
101$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_FILES),,kincmidir,$(KINCFRAME_UNIFDEF)))
102$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_GEN_FILES),1,kincmigendir,$(KINCFRAME_UNIFDEF)))
1c79356b
A
103
104#
39236c6e 105# Machine-independent local (private) files
1c79356b 106#
1c79356b 107
3e170ce0
A
108INSTALL_MI_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/, $(sort $(INSTALL_MI_LCL_LIST) $(INSTALL_MI_LIST)))
109INSTALL_MI_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MI_DIR)/, $(sort $(INSTALL_MI_LCL_GEN_LIST) $(INSTALL_MI_GEN_LIST)))
1c79356b 110
39236c6e
A
111$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_LCL_FILES),,pincmidir,$(SPINCFRAME_UNIFDEF)))
112$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MI_LCL_GEN_FILES),1,pincmigendir,$(SPINCFRAME_UNIFDEF)))
1c79356b 113
39236c6e
A
114INSTALL_KF_MI_LCL_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LCL_LIST))
115INSTALL_KF_MI_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MI_DIR)/, $(INSTALL_KF_MI_LCL_GEN_LIST))
1c79356b 116
39236c6e
A
117$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_LCL_FILES),,kpincmidir,$(KPINCFRAME_UNIFDEF)))
118$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MI_LCL_GEN_FILES),1,kpincmigendir,$(KPINCFRAME_UNIFDEF)))
1c79356b 119
39236c6e
A
120#
121# Machine-dependent (public) files
122#
1c79356b 123
39236c6e
A
124INSTALL_MD_INC_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_LIST))
125INSTALL_MD_INC_GEN_FILES = $(addprefix $(DSTROOT)/$(INCDIR)/$(INSTALL_MD_DIR)/, $(INSTALL_MD_GEN_LIST))
1c79356b 126
39236c6e
A
127$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_INC_FILES),,incdir,$(SINCFRAME_UNIFDEF)))
128$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_INC_GEN_FILES),1,incgendir,$(SINCFRAME_UNIFDEF)))
1c79356b 129
39236c6e
A
130INSTALL_KF_MD_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LIST))
131INSTALL_KF_MD_GEN_FILES = $(addprefix $(DSTROOT)/$(KINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_GEN_LIST))
1c79356b 132
39236c6e
A
133$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_FILES),,kincdir,$(KINCFRAME_UNIFDEF)))
134$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_GEN_FILES),1,kincgendir,$(KINCFRAME_UNIFDEF)))
1c79356b 135
39236c6e
A
136#
137# Machine-dependent local (private) files
138#
139
3e170ce0
A
140INSTALL_MD_LCL_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/, $(sort $(INSTALL_MD_LCL_LIST) $(INSTALL_MD_LIST)))
141INSTALL_MD_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(LCLDIR)/$(INSTALL_MD_DIR)/, $(sort $(INSTALL_MD_LCL_GEN_LIST) $(INSTALL_MD_GEN_LIST)))
39236c6e
A
142
143$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_LCL_FILES),,pincdir,$(SPINCFRAME_UNIFDEF)))
144$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_MD_LCL_GEN_FILES),1,pincgendir,$(SPINCFRAME_UNIFDEF)))
145
146INSTALL_KF_MD_LCL_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LCL_LIST))
147INSTALL_KF_MD_LCL_GEN_FILES = $(addprefix $(DSTROOT)/$(KPINCDIR)/$(EXPORT_MD_DIR)/, $(INSTALL_KF_MD_LCL_GEN_LIST))
148
149$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_LCL_FILES),,kpincdir,$(KPINCFRAME_UNIFDEF)))
150$(eval $(call INSTALLHDRS_RULE_template,$(INSTALL_KF_MD_LCL_GEN_FILES),1,kpincgendir,$(KPINCFRAME_UNIFDEF)))
1c79356b 151
39236c6e
A
152.PHONY: do_installhdrs_mi
153
154# Double-colon rule so that MakeInc.kernel can add custom behaviors
155do_installhdrs_mi:: $(INSTALL_MI_INC_FILES) $(INSTALL_MI_INC_GEN_FILES) $(INSTALL_KF_MI_FILES) $(INSTALL_KF_MI_GEN_FILES) \
156 $(INSTALL_MI_LCL_FILES) $(INSTALL_MI_LCL_GEN_FILES) $(INSTALL_KF_MI_LCL_FILES) $(INSTALL_KF_MI_LCL_GEN_FILES)
157 @:
158
159.PHONY: do_installhdrs_md
160
161do_installhdrs_md: $(INSTALL_MD_INC_FILES) $(INSTALL_MD_INC_GEN_FILES) $(INSTALL_KF_MD_FILES) $(INSTALL_KF_MD_GEN_FILES) \
162 $(INSTALL_MD_LCL_FILES) $(INSTALL_MD_LCL_GEN_FILES) $(INSTALL_KF_MD_LCL_FILES) $(INSTALL_KF_MD_LCL_GEN_FILES)
163 @:
164
165#
166# Generic Export rules
167#
168EXPORT_MI_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_LIST))
1c79356b
A
169EXPORT_MI_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/, $(EXPORT_MI_GEN_LIST))
170
39236c6e 171.PHONY: EXP_MI_INC_DIR
1c79356b 172
39236c6e
A
173EXP_MI_INC_DIR:
174 $(_v)$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)
1c79356b 175
39236c6e
A
176$(EXPORT_MI_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : % | EXP_MI_INC_DIR
177 $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
178
179$(EXPORT_MI_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MI_DIR)/% : $(SOURCE)/% | EXP_MI_INC_DIR
180 $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
181
182EXPORT_MD_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_LIST))
1c79356b
A
183EXPORT_MD_GEN_INC_FILES = $(addprefix $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/, $(EXPORT_MD_GEN_LIST))
184
39236c6e 185.PHONY: EXP_MD_INC_DIR
1c79356b 186
39236c6e
A
187EXP_MD_INC_DIR:
188 $(_v)$(MKDIR) $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)
189
190$(EXPORT_MD_GEN_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : % | EXP_MD_INC_DIR
191 $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
192
193$(EXPORT_MD_INC_FILES): $(OBJROOT)/$(EXPDIR)/$(EXPORT_MD_DIR)/% : $(SOURCE)/% | EXP_MD_INC_DIR
194 $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
195
196.PHONY: do_exporthdrs_mi
197
198do_exporthdrs_mi: $(EXPORT_MI_GEN_INC_FILES) $(EXPORT_MI_INC_FILES)
199 @:
200
201.PHONY: do_exporthdrs_md
202
203do_exporthdrs_md: $(EXPORT_MD_GEN_INC_FILES) $(EXPORT_MD_INC_FILES)
204 @:
1c79356b 205
1c79356b
A
206#
207# Generic Compilation rules
208#
209
210#
211# Compilation rules to generate .o from .s
212#
2d21ac55 213
39236c6e 214S_RULE_0=@echo AS $@
fe8ab488 215S_RULE_1A=$(_v)${S_KCC} -c ${SFLAGS} -MD -MF $(@:o=d) -MP ${$@_SFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
39236c6e
A
216S_RULE_1B=$(<F)
217S_RULE_2=
1c79356b
A
218
219#
220# Compilation rules to generate .o from .c for normal files
39236c6e
A
221#
222C_RULE_0=@echo CC $@
223C_RULE_1A=$(_v)${KCC} -c ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CWARNFLAGS}} -MD -MF $(@:o=d) -MP ${$@_CFLAGS_ADD} ${$@_CWARNFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
224C_RULE_1B=$(<F)
6d2010ae 225ifeq ($(BUILD_MACHO_OBJ),0)
39236c6e
A
226C_RULE_2=
227else ifeq ($(DO_CTFCONVERT),1)
228C_RULE_2=$(_v)if [ -z "${$@_SKIP_CTFCONVERT}" ]; then ${CTFCONVERT} -l xnu -v -o $@.ctf $@ > /dev/null || true; fi
2d21ac55 229else
39236c6e 230C_RULE_2=
316670eb 231endif
39236c6e 232ifeq ($(DO_CTFMACHO), 1)
fe8ab488 233C_CTFRULE_1A=$(_v)${KCC} -o $@.non_lto -c ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CWARNFLAGS}} ${$@_CFLAGS_ADD} ${$@_CWARNFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS} $(CFLAGS_NOLTO_FLAG)
39236c6e
A
234C_CTFRULE_1B=$(<F)
235C_CTFRULE_2=$(_v)if [ -z "${$@_SKIP_CTFCONVERT}" ]; then ${CTFCONVERT} -l xnu -v -o $@.non_lto.ctf $@.non_lto > /dev/null || true; fi
236else
237C_CTFRULE_1A=@true
238C_CTFRULE_1B=
239C_CTFRULE_2=@true
316670eb
A
240endif
241
1c79356b
A
242#
243# Compilation rules to generate .o from .c for driver files
244#
39236c6e 245C_RULE_0_D=${C_RULE_0}
1c79356b
A
246C_RULE_1A_D=${C_RULE_1A}
247C_RULE_1B_D=${C_RULE_1B}
248C_RULE_2_D=${C_RULE_2}
39236c6e
A
249C_CTFRULE_1A_D=${C_CTFRULE_1A}
250C_CTFRULE_1B_D=${C_CTFRULE_1B}
251C_CTFRULE_2_D=${C_CTFRULE_2}
1c79356b 252
1c79356b
A
253#
254# Compilation rules to generate .co from .cp or .cpo from .cpp
255# The config tool slickly changes the last source filename char to 'o'
256# for the object filename.
39236c6e
A
257P_RULE_0=@echo C++ $@
258P_RULE_1A=$(_v)${KC++} -o $@ -c ${CXXFLAGS} ${filter-out ${$@_CFLAGS_RM}, ${CFLAGS} ${CXXWARNFLAGS}} -MD -MF $(@:o=d) -MP ${$@_CFLAGS_ADD} ${$@_CXXWARNFLAGS_ADD} ${INCFLAGS} ${$@_INCFLAGS}
1c79356b 259P_RULE_1B=$(<F)
39236c6e
A
260P_RULE_2=
261P_CTFRULE_1A=@true
262P_CTFRULE_1B=
263P_CTFRULE_2=@true
1c79356b 264
1c79356b 265
3e170ce0
A
266#
267# This isn't the right place to put this, but we need to := override some settings
268# in Makefiles that include the generic helper fragments (like this file)
269#
270ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
271HIB_FILES :=
272LAST_FILES :=
273KLD_FILES :=
274endif
275
39236c6e 276.PHONY: do_build_all
1c79356b 277
39236c6e
A
278# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
279# in their local Makefiles. Those that do will use a "::" rule to augment this.
280do_build_all::
281 @:
1c79356b 282
39236c6e 283.PHONY: do_build_install_primary
2d21ac55 284
39236c6e
A
285# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
286# in their local Makefiles. Those that do will use a "::" rule to augment this.
287do_build_install_primary::
288 @:
2d21ac55 289
39236c6e 290.PHONY: do_build_install_non_primary
2d21ac55 291
39236c6e
A
292# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
293# in their local Makefiles. Those that do will use a "::" rule to augment this.
294do_build_install_non_primary::
295 @:
1c79356b 296
39236c6e 297INSTALL_MAN_FILES = $(addprefix $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/, $(INSTALL_MAN_LIST))
1c79356b 298
39236c6e 299.PHONY: INSTALL_MAN_DIR
1c79356b 300
39236c6e
A
301INSTALL_MAN_DIR:
302 $(_v)$(MKDIR) $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)
9bccf70c 303
39236c6e
A
304$(INSTALL_MAN_FILES): $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/% : % | INSTALL_MAN_DIR
305 @echo MAN $*
306 $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
307
308define MAN_LINKS_RULE_template
309$$(DSTROOT)/$$(MANDIR)/$$(INSTALL_MAN_DIR)/$(2): $$(DSTROOT)/$$(MANDIR)/$$(INSTALL_MAN_DIR)/$(1)
310 @echo MANLINK $(2)
311 $(_v)ln -f $$< $$@
312endef
313
314function_generate_man_links_rules = $(if $(word 1,$(1)),$(eval $(call MAN_LINKS_RULE_template,$(word 1,$(1)),$(word 2,$(1)))) $(DSTROOT)/$(MANDIR)/$(INSTALL_MAN_DIR)/$(word 2,$(1)) $(call function_generate_man_links_rules,$(wordlist 3,$(words $(1)),$(1))))
315
316INSTALL_MAN_FILES_LINKS = $(call function_generate_man_links_rules,$(INSTALL_MAN_LINKS))
317
318.PHONY: do_installman
319
320do_installman: $(INSTALL_MAN_FILES) $(INSTALL_MAN_FILES_LINKS)
321 @:
1c79356b 322
fe8ab488
A
323.PHONY: do_textfiles_install
324
325# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
326# in their local Makefiles. Those that do will use a "::" rule to augment this.
327do_textfiles_install:: do_installman
328 @:
329
39236c6e
A
330.PHONY: do_build_setup
331
332# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
333# in their local Makefiles. Those that do will use a "::" rule to augment this.
334do_build_setup::
335 @:
336
337.PHONY: do_config_all
338
339# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
340# in their local Makefiles. Those that do will use a "::" rule to augment this.
341do_config_all::
342 @:
343
fe8ab488
A
344.PHONY: do_config_install
345
346# Do-nothing rule, since not all levels of the recursive hierarchy might implement this
347# in their local Makefiles. Those that do will use a "::" rule to augment this.
348do_config_install::
349 @:
b0d623f7 350
2d21ac55 351# vim: set ft=make: