简体   繁体   English

Makefile 命令替换不接受参数

[英]Makefile command substitution does not accept parameters

I am trying to create a simple Makefile for my go project.我正在尝试为我的go项目创建一个简单的Makefile

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 ?替换go build -ldflags "-s -w" -a -installsuffix cgo的语法正确方法是什么?

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:否则,shell( make )会看到以下命令行:

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

It correctly treats the whole string go build... as argv[0] and tries to find it as an executable.它正确地将整个字符串go build...视为argv[0]并尝试将其作为可执行文件查找。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM