0

We caught a bug report for the following in our GNUmakefile. I'm still not quite clear on the reason for the bug (the report lacks some detail), but I want to ensure the substituion and assignment is valid for GNU Make.

SUNCC_VERSION := $(subst `,',$(shell $(CXX) -V 2>&1))

I seem to recall it is needed when using SunCC (C++) compiler and the default Solaris shell. Without the substituion the makefile produces errors when run. The error is seen when grepping SUNCC_VERSION for version numbers.

Here is the make manual on the subject: 8.2 Functions for String Substitution and Analysis. The section does not discuss reserved characters or similar topics (other than blackslash and percent).

My question is, is the substitution valid or does it need to be fixed?

jww
  • 97,681
  • 90
  • 411
  • 885

1 Answers1

1

There's no way to know, because you didn't specify what "errors when run" means. What command gives the error? What is the error message? What is the value generated by the $(CC) -V command, before make performs this replacement?

There's nothing special to make about quotes of any type: single, double, or backquotes. Make treats them just like any other character. So, this substitution is not being done for make's benefit.

Very likely the result of the $(CC) -V shell command prints some string inside quotes using the old-school GNU (and other) format which used a backquote as the opening single quote and a single quote as the closing single quote, so something like:

foo `version' bar

Then this variable SUNCC_VERSION was used in a location where the backquote was not allowed. Maybe as part of a shell script, and lacking proper quoting, like this:

all:
        @echo Version is $(SUNCC_VERSION)

If you don't replace the backquote this expands to:

echo Version is foo `version' bar

which is not a valid shell script.

However since there's no details about any of this in the question I'm just guessing.

MadScientist
  • 92,819
  • 9
  • 109
  • 136
  • Thanks. The question was, *"is the substitution valid'*. I believe this is the answer: *"There's nothing special to make about quotes of any type: single, double, or backquotes"*. That is, it is a valid GNU make statement. The bug report is at [Compile-Error under MacOS](https://github.com/weidai11/cryptopp/issues/592). – jww Feb 27 '18 at 07:41
  • 1
    @jww yep, you understood MadScientist right. GNUmake doesn't care for quotes in makefiles. In a `$subst()` or any other function call, the interpreted characters are `,` (comma - separates function parameters) and `()` (opening/closing parentheses - are required to match, but only `()` and not `[]` or `{}`) and `$` if it is in a place where the following string could be a make-variable or function name (which is evaluated and replaced then). – Vroomfondel Feb 27 '18 at 09:45