]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/cmetric.omk
Ensure that OBJ_EXT, LIB_EXT, LIB_PREF and ASM_EXT is defined for all targets.
[omk.git] / snippets / cmetric.omk
1 # cmetric_include_HEADERS    .. generate header file with offsets and sizes of structure fields
2 # xxx_CMETRIC_SOURCES        .. the source cmetric generation
3
4 NM ?= nm
5
6 # Syntax: $(call CMETRIC_o_h_template,<object_file>,<target_header>)
7 define CMETRIC_o_h_template
8 $(2): $(1)
9         @$(QUIET_CMD_ECHO) "  CMETRIC $$@"
10         $(Q)if [ -n `dirname $$@` ] ; then \
11               if [ ! -e `dirname $$@` ] ; then \
12                 mkdir -p `dirname $$@` ; fi ; fi
13         $(Q)echo >$$@.tmp '/* Automatically generated from $$< */'
14         $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */'
15 # Bellow, the tricks with redirection are for shells without set -o pipefail
16 # (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html)
17         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
18                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
19                 | sort >>$$@.tmp` && exit $$$$status
20         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */'
21         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\
22                 | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \
23                 | sort >>$$@.tmp` && exit $$$$status
24         $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */'
25         $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\
26                 | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \
27                 | sort >>$$@.tmp` && exit $$$$status
28         $(Q)mv $$@.tmp $$@
29 endef
30
31 library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS))
32
33 # Special rules for CMETRIC generated headers
34
35 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\
36                 $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\
37                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%$(OBJ_EXT)),)))
38 $(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\
39                 $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%$(OBJ_EXT)),\
40                 $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh)))))
41
42 GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)