]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/prepare
ed7fdedbfd5e7066cddde7826e570fb2cb292529
[omk.git] / snippets / prepare
1
2 ################
3 # Prepare pass #
4 ################
5
6 $(eval $(call omk_pass_template,prepare-pass,$(USER_OBJS_DIR),,always))
7
8 ###
9 # Name of the prepared rule.  This name is used as prefix of variable
10 # names in .omk.inc and is based on the first target
11 omk_inc_rule = $(firstword $(1:$(OUTPUT_DIR)/%=%))
12
13 # The name of .omk.inc file is derived from $(omk_inc_rule) and
14 # depends whether the target is under _build or elsewhere.
15 omk_inc_file = $(if $(filter $(BUILD_DIR_NAME)%,$(omk_inc_rule)),\
16                     $(OMK_WORK_DIR)/$(notdir $(omk_inc_rule)).omk.inc,\
17                     $(OMK_WORK_DIR)/$(subst /,_,$(omk_inc_rule)).omk.inc)
18
19 target_omk_file = $(OMK_WORK_DIR)/$(notdir $(1)).target.omk
20
21 # >'< substitution is for echo to work,
22 # >$< substitution to preserve $ when reloading .omk.inc file
23 subst-cmd = $(subst \#,\\\#,$(subst $$,$$$$,$(call escsq,$(1))))
24
25 ###
26 # prepare_rule is used to generate .omk.inc files during prepare-pass.
27 # All paths in this file should be relative to $(OUTPUT_DIR)
28 # Usage: $(eval $(call prepare_rule,<targets>,<deps>,<msg>,<cmd>))
29 define prepare_rule
30 prepare-pass-local: $(omk_inc_file)
31
32 $(omk_inc_file): FORCE
33 #TODO remove the next line
34         @echo "  PREP    "$$(call strip_out,$$@); \
35             echo 'prepared_rules += $(omk_inc_rule)' > $$@.tmp; \
36             echo '$(omk_inc_rule)_targets = $$(call strip_out,$(1))' >> $$@.tmp; \
37             echo '$(omk_inc_rule)_deps += $$(call strip_out,$(2))' >> $$@.tmp; \
38             echo '$(omk_inc_rule)_msg = $(3)' >> $$@.tmp; \
39             echo '$(omk_inc_rule)_cmd = $(call subst-cmd,$(4))' >> $$@.tmp; \
40         if cmp -s $$@.tmp $$@; then rm $$@.tmp; else mv $$@.tmp $$@; fi
41 endef
42
43 ###
44 # prepare_rule_goal - same as prepare rules but the target is put
45 # as dependency to the default goal, which causes it to be built
46 # upon calling make
47 define prepare_rule_goal
48 $(call prepare_rule,$(1),$(2),$(3),$(4))
49 prepared_goals += $(call strip_out,$(1))
50 endef
51
52 prepare-pass-local: $(OMK_WORK_DIR)/__goals.omk.inc
53 $(OMK_WORK_DIR)/__goals.omk.inc: FORCE
54         $(Q)echo 'omk_goals += $(prepared_goals)' > $@.tmp; \
55             if cmp -s $@.tmp $@; then rm $@.tmp; else mv $@.tmp $@; fi
56
57