英文:
checking for GNU extensions in Makefiles ... WARNING
问题
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`
英文:
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`
答案1
得分: 2
以下是翻译好的部分:
你可以直接调用 grep
并使用存储最后命令值的 shell 变量来访问它。然而,更常见的方法是查询 uname -s
并进行比较。我在这里同时使用了这两种方法。
代码
#!/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
输出
虽然我在 bash 下看到了 OSTYPE
,但在 sh 中为空,因此只有第二种方法可行。
$ ./answer.sh
We are on Linux (2 of 2)
PKG_LIBS = -L -lharmonium -lasound
$
在实际用途中,你当然希望将值分配给 PKG_LIBS
而不是将其输出。
英文:
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.
Code
#!/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
Output
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论