gnu make - info guarded by conditional in recipe? -
we have library project , transitioning unaligned data access common in old i386/i686/x86_64 aligned data access. impetus gcc , vectorization, causing crashes @ -o3
(gcc vectorizing string compares sse4 primitives).
if runs make , particular define not present, want print info
message warning them. i'm having trouble crafting recipe.
the following recipe produces error when run (it uses tab, , not spaces):
.phony check_defines check_defines: config_aligned := $(shell $(egrep) -i -c "[[:space:]]*#[[:space:]]*define[[:space:]]*no_unaligned_data_access" config.h) cxx_aligned := $(shell echo $(value cxxflags) | $(egrep) -i -c "-dno_unaligned_data_access") ifeq ($(config_aligned)$(cxx_aligned),00) $(info warning: no_unaligned_data_access not defined) endif
the error is:
$ make check_defines gnumakefile:383: *** missing separator. stop.
line 383 config_aligned := ...
. manual on 5.1 recipe syntax not helpful me.
how craft rule perform test within recipe?
makefiles not parsed script , executed imperatively. recipe not sub-routine.
the page linked explicitly tells body of recipe treated shell commands, not make declarations/expressions:
- a variable definition in “rule context” indented tab first character on line, considered part of recipe, not make variable definition, , passed shell.
- a conditional expression (ifdef, ifeq, etc. see syntax of conditionals) in “rule context” indented tab first character on line, considered part of recipe , passed shell.
so can't declare make variables or use make conditionals. can use shell commands.
try like:
config_aligned := $(shell $(egrep) -i -c "[[:space:]]*#[[:space:]]*define[[:space:]]*no_unaligned_data_access" config.h) cxx_aligned := $(shell echo $(value cxxflags) | $(egrep) -i -c "-dno_unaligned_data_access") ifeq ($(config_aligned)$(cxx_aligned),00) check_failed := 1 endif .phony check_defines check_defines: if [ $(check_failed) = 1 ]; echo warning: no_unaligned_data_access not defined; exit 1; fi
or check condition using shell:
config_aligned := $(shell $(egrep) -i -c "[[:space:]]*#[[:space:]]*define[[:space:]]*no_unaligned_data_access" config.h) cxx_aligned := $(shell echo $(value cxxflags) | $(egrep) -i -c "-dno_unaligned_data_access") .phony check_defines check_defines: if [ $(config_aligned)$(cxx_aligned) = 00 ]; echo warning: no_unaligned_data_access not defined; exit 1; fi
or shell, declaring shell variables instead of make variables:
.phony check_defines check_defines: config_aligned=`$(egrep) -i -c "[[:space:]]*#[[:space:]]*define[[:space:]]*no_unaligned_data_access" config.h` cxx_aligned=`echo $(value cxxflags) | $(egrep) -i -c "-dno_unaligned_data_access")` if [ $${config_aligned}$${cxx_aligned} = 00 ]; echo warning: no_unaligned_data_access not defined; exit 1; fi
(this version might not work if cxxflags contains shell-outs such `pkg-config --cflags foo`
confuse shell)
Comments
Post a Comment