From: Michal Sojka Date: Mon, 25 Nov 2013 16:31:19 +0000 (+0100) Subject: Add forgotten cmetric.omk X-Git-Url: https://rtime.felk.cvut.cz/gitweb/omk.git/commitdiff_plain/58a2faef6b8c006e83b22739fef5e4a7dde29039 Add forgotten cmetric.omk --- diff --git a/snippets/cmetric.omk b/snippets/cmetric.omk new file mode 100644 index 0000000..f44cd02 --- /dev/null +++ b/snippets/cmetric.omk @@ -0,0 +1,42 @@ +# cmetric_include_HEADERS .. generate header file with offsets and sizes of structure fields +# xxx_CMETRIC_SOURCES .. the source cmetric generation + +NM ?= nm + +# Syntax: $(call CMETRIC_o_h_template,,) +define CMETRIC_o_h_template +$(2): $(1) + @$(QUIET_CMD_ECHO) " CMETRIC $$@" + $(Q)if [ -n `dirname $$@` ] ; then \ + if [ ! -e `dirname $$@` ] ; then \ + mkdir -p `dirname $$@` ; fi ; fi + $(Q)echo >$$@.tmp '/* Automatically generated from $$< */' + $(Q)echo >>$$@.tmp '/* Conditionals to control compilation */' +# Bellow, the tricks with redirection are for shells without set -o pipefail +# (see http://www.mail-archive.com/dash@vger.kernel.org/msg00149.html) + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2cond_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in hexadecimal format */' + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0[0-9A-Fa-f]*\) *A *_cmetric2def_\([A-Za-z_0-9]*\) */#define \2 0x\1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)echo >>$$@.tmp '/* Defines from the values defined to symbols in decimal format */' + $(Q)exec 3>&1; status=`exec 4>&1 >&3; { $(NM) -td $$<; echo $$$$? >&4; }\ + | $(SED4OMK) -n 's/^ *0*\(0\|[1-9][0-9]*\) *A *_cmetric2defdec_\([A-Za-z_0-9]*\) */#define \2 \1/p' \ + | sort >>$$@.tmp` && exit $$$$status + $(Q)mv $$@.tmp $$@ +endef + +library-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(cmetric_include_HEADERS)) + +# Special rules for CMETRIC generated headers + +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call COMPILE_c_o_template,\ + $(SOURCES_DIR)/$($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES),\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),))) +$(foreach cmetrh,$(cmetric_include_HEADERS),$(eval $(call CMETRIC_o_h_template,\ + $($(basename $(notdir $(cmetrh)))_CMETRIC_SOURCES:%.c=%.o),\ + $(addprefix $(USER_INCLUDE_DIR)/,$(cmetrh))))) + +GEN_HEADERS+=$(cmetric_include_HEADERS:%=$(USER_INCLUDE_DIR)/%)