使用shell变量传递选项时,autotools配置错误

问题描述 投票:1回答:1

我希望从bash脚本中调用configure命令(来编译nginx),如下所示:

CONF_OPTS=' --with-cc-opt="-O2 -g"'
./configure ${CONF_OPTS}

但我收到以下错误:

./configure: error: invalid option "-g"

当我通过以下选项时:

./configure --with-cc-opt="-O2 -g"

我没有错。

重现:

curl -O  http://nginx.org/download/nginx-1.14.2.tar.gz
tar xfz nginx-1.14.2.tar.gz
cd nginx-1.14.2

OPTS='--with-cc-opt="-O2 -g"'
./configure ${OPTS}

结果

./configure: error: invalid option "-g""

但:

./configure --with-cc-opt="-O2 -g"

没关系

我认为这与nginx无关,但我认为是bash引用替换问题。

bash nginx autotools configure
1个回答
0
投票

它会像这样工作:

$ CC_OPTS=--with-cc-opt='-O2 -g'
$ ./configure "$CC_OPTS"

所以$CC_OPTS的扩张作为一个论点传递给./configure

但如果你也想通过,也许:

--with-ld-opt='-Wl,-gc-sections -Wl,-Map=mapfile'

通过变量,您需要:

$ CC_OPTS=--with-cc-opt='-O2 -g'
$ LD_OPTS=--with-ld-opt='-Wl,-gc-sections -Wl,-Map=mapfile'
$ ./configure "$CC_OPTS" "$LD_OPTS"

因为你需要将两个参数传递给./configure,并且:

./configure "$CC_OPTS $LD_OPTS"

只通过一个,并将失败。

© www.soinside.com 2019 - 2024. All rights reserved.