Convert hex to decimal in make script?
-
07-07-2019 - |
Question
A make script is attempting to set a variable as follows:
VER_DEC=$( perl -e "print hex(\"$(VER_HEX)\");" )
where VER_HEX
happens to have a value of 0a
.
Perl seems to think that VER_HEX is zero, implying that the variable isn't set (but it is, according to a debug echo in the makefile).
Does make have a simpler way to convert bases?
If so, what version of make is required?
UPDATE: This is a GNU Makefile. The invocation of perl is missing the word shell
inside the $( )
as well as potentially having escaping issues with the double-quotes.
Solution
VER_DEC=$(shell printf "%d" 0x$(VER_HEX))
if you're talking about Makefile
. Because your doesn't look like Makefile
to me, more like shell. (I think $(shell )
is GNU extension, but most of time you can safely replace it with backticks).
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow