程序在不同机器上运行的Makefile
我有一个 C++ 程序,它将在多台使用网络文件系统的计算机上运行。对于我的程序使用的每个 C++ 库,我在 ~/program_files/machinename/libraryname 下为每台计算机安装了一个版本。
“machinename”是通过bash命令“hostname”获得的。在我使用的计算机上,“主机名”输出类似“io21.aaa.bbb.edu”的内容,并且我仅将“io21”作为库路径的“计算机名”。在 bash 中,我了解到
$ HOST=
主机名
# 现在HOST的值为“io21.aaa.bbb.edu”$ HOST=${HOST%%.*} # 从“io21.aaa.bbb.edu”中提取“io21”
$回显${HOST}
io21
在我的程序的 Makefile 中,我想根据当前机器调用这些 bash 命令来指定库的路径:
HOST := $(shell 主机名)
HOST := $(shell ${HOST%%.*})
LDFLAGS=-L${HOME}/program_files/${HOST}/libraryname/lib
CXXFLAGS=-Wall -I${HOME}/program_files/${HOST}/libraryname/include
第一行工作正常,即主机是“io21.aaa.bbb.edu”,但提取“io21”的第二行不起作用,主机仍然是“io21” .aaa.bbb.edu”。
我想知道我应该如何解决这个问题?
感谢致敬!
I have a C++ program that will run on several machines that use a Network File System. For each of the C++ libraries that my program uses, I installed a version for each machine, under ~/program_files/machinename/libraryname.
"machinename" is obtained via bash command "hostname". On the machines I am using, "hostname" outputs something like "io21.aaa.bbb.edu" and I take only "io21" as "machinename" for the path to the libraries. In bash, I learned that
$ HOST=
hostname
# now the value of HOST is "io21.aaa.bbb.edu"$ HOST=${HOST%%.*} # extract "io21" from "io21.aaa.bbb.edu"
$ echo ${HOST}
io21
In the Makefile of my program, I want to call these bash commands to specify the path to the library according to the current machine:
HOST := $(shell hostname)
HOST := $(shell ${HOST%%.*})
LDFLAGS=-L${HOME}/program_files/${HOST}/libraryname/lib
CXXFLAGS=-Wall -I${HOME}/program_files/${HOST}/libraryname/include
The first line is working i.e. HOST is "io21.aaa.bbb.edu", but the second line which extracts "io21" doesn't work and HOST is still "io21.aaa.bbb.edu".
I am wondering how I should solve this problem?
Thanks and regards!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
或者你可以使用
Alternatively you can use
尝试一下:
make
默认为/bin/sh
,它可能不支持$(var%%string)
构造,具体取决于哪个版本你有。此外,混合make
变量和bash
变量有点具有挑战性。Give this a try:
make
defaults to/bin/sh
which may not support the$(var%%string)
construct depending on which version you have. Also, mixingmake
variables andbash
variables is a bit challenging.