Makefile for a program running on different machines

I have a C ++ program that will run on multiple computers using the network filesystem. For each of the C ++ libraries my program uses, I have set a per machine version to ~ / program_files / machinename / libraryname.

The "machine name" is obtained with the bash "hostname" command. On the machines I am using, "hostname" outputs something like "io21.aaa.bbb.edu" and I only take "io21" as the "machine name" for the library path. In bash, I found out that

$ HOST = hostname

# HOST is now "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 invoke these bash commands to specify the library path according to the current machine:

HOST: = $ (shell hostname)

HOST: = $ (shell $ {HOST %%. *})

LDFLAGS = -L $ {HOME} / program_files / $ {HOST} / LibraryName / Library

CXXFLAGS = -Wall -I $ {HOME} / program_files / $ {HOST} / libraryname / include

The first line works, i.e. HOST is "io21.aaa.bbb.edu", but the second line that retrieves "io21" doesn't work, and HOST is still "io21.aaa.bbb.edu".

I am wondering how should I solve this problem?

Thank you and welcome!

+2


source to share


2 answers


Alternatively, you can use



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

      

+3


source


Try:

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

      



make

the default is used /bin/sh

, which may not support construction $(var%%string)

depending on which version you have. Also, mixing variables make

and variables bash

is a bit tricky.

+3


source







All Articles