Home > database >  Makefile command substitution does not accept parameters
Makefile command substitution does not accept parameters

Time:08-06

I am trying to create a simple Makefile for my go project.

The following command substitution

GO_BUILD     := 'go build -ldflags "-s -w" -a -installsuffix cgo'


.PHONY: backup
build-cli:
    @$(GO_BUILD) -o cli ./cli 

seems to create the following problem

▶ make build-cli
make: go build -ldflags "-s -w" -a -installsuffix cgo: No such file or directory
make: *** [build-cli] Error 1

What is the syntactically correct way of substituting go build -ldflags "-s -w" -a -installsuffix cgo ?

CodePudding user response:

Removing the superfluous quotes from the variable should do it:

GO_BUILD     := go build -ldflags "-s -w" -a -installsuffix cgo

Otherwise, the shell (that make spawns) sees this command line:

'go build ...' -o cli ./cli 

It correctly treats the whole string go build ... as argv[0] and tries to find it as an executable.

  • Related