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