shell - Boolean circuit using basic arithmetic? -


according how perform arithmetic in makefile?, can perform basic arithmetic through posix shell in gnumakefile (see dominic's answer).

i got excited because have suffered lack of logical operators in past. coded following test on os x:

gcc42_or_later = $(shell $(cxx) -v 2>&1 | $(egrep) -c "^gcc version (4.[2-9]|[5-9])") is_darwin = $(shell uname -s | $(egrep) -i -c "darwin") clang_compiler = $(shell $(cxx) --version 2>&1 | $(egrep) -i -c "clang")  # below, building boolean circuit says "darwin && (gcc 4.2 or above || clang)" supports_multiarch = $$($(is_darwin) * $$($(gcc42_or_later) + $(clang_compiler)))  ifneq ($(supports_multiarch),0) cxxflags += -arch x86_64 -arch i386 else cxxflags += -march=native endif 

a run on os x showed -arch x86_64 -arch i386, , expected.

i added is_darwin=0 before math, should have driven low. did not, , got -arch x86_64 -arch i386 again.

what doing wrong in above code?

as comment says, have $$(()) arithmetic work, need involve shell and shell needs bash. (edit: apparently doesn't, , posix shell work, minimal dash)

first off, add top of `makefile`: shell=/bin/bash

then, line playing should read:

# below, building boolean circuit says "darwin && (gcc 4.2 or above || clang)" supports_multiarch = $(shell echo $$(( $(is_darwin) * ( $(gcc42_or_later) + $(clang_compiler) ) )) ) 

i've added spaces in line show what's matching what. feel free delete them, though no harm.

inside double-paren-arithmetic group, don't need $$(( start arithmetic subgroup; use ordinary parentheses.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -