I added the following to my Makevars file:
# Set the library flags based on the operating system
ifeq ($(findstring linux,$(OSTYPE)), linux)
PKG_LIBS = -L$(LIBDIR) -lharmonium -lasound
else
PKG_LIBS = -L$(LIBDIR) -lharmonium
endif
And devtools::check
is complaining:
❯ checking for GNU extensions in Makefiles ... WARNING
Found the following file(s) containing GNU extensions:
src/Makevars
Portable Makefiles do not use GNU extensions such as +=, :=, $(shell),
$(wildcard), ifeq ... endif, .NOTPARALLEL See section ‘Writing portable
packages’ in the ‘Writing R Extensions’ manual.
How to avoid this warning while keeping Makevars dependent on $OSTYPE
?
EDIT: this is the solution I got following Dirk's advice.
PKG_LIBS = `os=\`uname -s\`; if [ "$$os" = "Linux" ]; then echo "-L${LIBDIR} -lharmonium -lasound"; else echo ="-L${LIBDIR} -lharmonium"; fi`
You could call grep
directly and use the shell variable holding the value of the last command to access is. However, a more common approach is to query uname -s
and compare. I use both approaches here.
#!/bin/sh
echo $OSTYPE | grep -q linux
if [ $? -eq 0 ]; then
echo "We are on Linux (1 of 2)"
echo "PKG_LIBS = -L${LIBDIR} -lharmonium -lasound"
fi
os=`uname -s`
if [ "$os" = "Linux" ]; then
echo "We are on Linux (2 of 2)"
echo "PKG_LIBS = -L${LIBDIR} -lharmonium -lasound"
fi
While I see OSTYPE
under bash, it is empty for me in sh making only the second approach viable.
$ ./answer.sh
We are on Linux (2 of 2)
PKG_LIBS = -L -lharmonium -lasound
$
In your real use you want to of course assign to PKG_LIBS
rather than echo it.