Make autogen.sh portable on Linux and Mac OS
the package I am trying to install has the following autogen.sh (only the first lines are showed):
开发者_开发知识库#! /bin/sh
libtoolize --automake
However, on Mac, once GNU libtool has been installed (via MacPorts for instance), libtoolize is renamed as glibtoolize. Following this answer, I hence want to modify the autogen.sh above into:
#! /bin/sh
if [ $(hash libtoolize 2>&-) -eq 0 ]
then
libtoolize --automake
else
glibtoolize --automake
fi
But it returns ./autogen.sh: line 6: [: -eq: unary operator expected
. What am I doing wrong here?
I cannot comment (not enough rep yet), but I'd like to point out that these days, it might actually be best if you replaced the autogen.sh script by a simple call to the autoreconf tool, which was specifically created to replace all those autogen.sh, bootstrap.sh etc. scripts out there. It is part of any autoconf (not sure since when, but definitely was part of autoconf 2.63 (current is 2.68).
The problem you have is $(hash libtoolize 2>&-)
has no output, and so that line is interpreted as simply:if [ -eq 0 ]
The return code of the command is accessible via $?
, so you could do:
hash libtoolize 2>&-
if [ $? -eq 0]; then
#....
However, you could just as well do this:
if hash libtoolize 2>&-
then
libtoolize --automake
else
glibtoolize --automake
fi
精彩评论