]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/prepare
Formating changes, added Emacs modelines
[omk.git] / snippets / prepare
1
2 ################ -*- makefile-gmake -*-
3 # Prepare pass #
4 ################
5
6 $(eval $(call omk_pass_template,prepare-pass))
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 to preserve \ in echo argument
22 # >'< substitution is for echo to work,
23 # >$< substitution to preserve $ when reloading .omk.inc file
24 subst-cmd = $(subst $$,$$$$,$(call escsq,$(subst \,\\,$(1))))
25
26 ###
27 # prepare_rule is used to generate .omk.inc files during prepare-pass.
28 # All paths in this file should be relative to $(OUTPUT_DIR)
29 # Usage: $(eval $(call prepare_rule,<targets>,<deps>,<msg>,<cmd>))
30 define prepare_rule
31 prepare-pass::
32 #TODO remove echos from the next commands
33         @set -e;\
34             echo 'prepared_rules += $(omk_inc_rule)' > $(omk_inc_file).tmp; \
35             echo '$(omk_inc_rule)_targets = $$(call strip_out,$(1))' >> $(omk_inc_file).tmp; \
36             echo '$(omk_inc_rule)_deps += $$(call strip_out,$(2))' >> $(omk_inc_file).tmp; \
37             echo '$(omk_inc_rule)_msg = $(3)' >> $(omk_inc_file).tmp; \
38             echo '$(omk_inc_rule)_cmd = $(call subst-cmd,$(4))' >> $(omk_inc_file).tmp; \
39         if cmp -s $(omk_inc_file).tmp $(omk_inc_file); then rm $(omk_inc_file).tmp; echo "  CHK     "$$(call strip_out,$(omk_inc_file)); else mv $(omk_inc_file).tmp $(omk_inc_file); echo "  UPD     "$$(call strip_out,$(omk_inc_file)); fi
40 endef
41
42 ###
43 # prepare_rule_goal - same as prepare rules but the target is put
44 # as dependency to the default goal, which causes it to be built
45 # upon calling make
46 define prepare_rule_goal
47 $(call prepare_rule,$(1),$(2),$(3),$(4))
48 prepared_goals += $(call strip_out,$(1))
49 endef
50
51 _goals := $(OMK_WORK_DIR)/__goals.omk.inc
52
53 prepare-pass::
54         @echo 'omk_goals += $(prepared_goals)' > $(_goals).tmp; \
55             if cmp -s $(_goals).tmp $(_goals); \
56                 then rm $(_goals).tmp; \
57                 else mv $(_goals).tmp $(_goals); fi
58
59