程序在不同机器上运行的Makefile

发布于 2024-08-02 07:06:38 字数 818 浏览 7 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

草莓酥 2024-08-09 07:06:38

或者你可以使用

HOST := $(shell echo $(HOST) | cut -d . -f 1)

Alternatively you can use

HOST := $(shell echo $(HOST) | cut -d . -f 1)
彻夜缠绵 2024-08-09 07:06:38

尝试一下:

SHELL = /bin/bash
HOST := $(shell hostname)
HOST := $(shell host=$(HOST);echo ${host%%.*})

make 默认为 /bin/sh,它可能不支持 $(var%%string) 构造,具体取决于哪个版本你有。此外,混合 make 变量和 bash 变量有点具有挑战性。

Give this a try:

SHELL = /bin/bash
HOST := $(shell hostname)
HOST := $(shell host=$(HOST);echo ${host%%.*})

make defaults to /bin/sh which may not support the $(var%%string) construct depending on which version you have. Also, mixing make variables and bash variables is a bit challenging.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文