Use of expr in Makefile

Hello everyone,

I'm trying to make a patch for an outdated ported. Unfortunately, I need to do a string comparison in the Makefile like so:
Makefile:
STRING1=12
STRING2=34

.if `${EXPR} "${STRING1} < ${STRING2}"`

.endif
I've tried all these variations:
Code:
(${EXPR} "${STRING1} < ${STRING2}")
${EXPR} ${STRING1} < ${STRING2}
$((${EXPR} "${STRING1} < ${STRING2}"))

# This works in the shell
expr "${STRING1} < ${STRING2}"
# Would produce: 12 < 34
All forms I've tried I've ended getting malformed condition. Has anyone used the expr command in the Makefile?

Thanks,
Tommy
 
You can use
Makefile:
res!= expr 1 + 2
all:
    echo ${res}
as well as
Makefile:
res!= test "${STRING1}" \< "${STRING2}" && echo 1 || echo 0
all:
    echo ${res}
to run a (shell) command in in POSIX makefiles.

Why would you need string comparison?
 
Hi Bobi,

Thanks for the feedback. I'll try your suggestions. I was using:
Makefile:
.if ${STRING1} < ${STRING2}

.endif

And the port works as expected. But when testing for compatibility with other ports, poudriere distclean -a
broke and complained about malformed conditional even though poudriere bulk ... works fine. But after some research, I think it may a bug in poudriere since another experiencing similar error for configuring a port PR 226695
 
Back
Top