golang项目中的Makefile给出错误“缺少分隔符。停止”。

时间:2019-12-22 20:06:20

标签: go makefile

我一直在我的Makefile上找几个小时,却找不到“ make build”在这里给我一个错误的原因:

GOBUILD=go build
GOX=gox
BINARY_NAME=tobw

VERSION=$(shell git describe --tags --always --dirty)
# linker flags for stripping debug info and injecting version info
LD_FLAGS="-s -w -X main.Version=$(VERSION)"
BIN_TARGETS="windows/386 windows/amd64 darwin/386 darwin/amd64 linux/386 linux/amd64 linux/arm linux/arm64 freebsd/386 freebsd/amd64 freebsd/arm openbsd/386 openbsd/amd64 openbsd/arm netbsd/386 netbsd/amd64 netbsd/arm"


# Used for help output
HELP_SPACING=15
HELP_COLOR=33
HELP_FORMATSTRING="\033[$(HELP_COLOR)m%-$(HELP_SPACING)s \033[00m%s.\n"

GO_FILES?=$$(find . -name '*.go' | grep -v vendor)
EXTERNAL_TOOLS=\
    golang.org/x/tools/cmd/goimports \
    github.com/golang/dep/cmd/dep \
    github.com/client9/misspell/cmd/misspell \
    github.com/mitchellh/gox

.PHONY: build local

build:
    @echo "*** Building binaries for supported architectures... ***"
    $(GOX) -osarch=$(BIN_TARGETS) -ldflags=$(LD_FLAGS) -output="bin/{{.Dir}}_{{.OS}}_{{.Arch}}"
    @echo "*** Done ***"

local:
    @echo "*** Building local binary... ***"
    $(GOBUILD) -o $(BINARY_NAME) ./
    @echo "*** Done ***"

.PHONY: clean fmt check_spelling fix_spelling vet dep

clean:
    @echo "*** Cleaning up object files... ***"
    rm -r -f bin/*
    rm -f tobw
    rm -f tobw.exe
    go clean
    @echo "*** Done ***"

fmt:
    @echo "*** Applying gofmt on all .go files (excluding vendor)... ***"
    @goimports -w $(GO_FILES)
    @echo "*** Done ***"

check_spelling:
    @echo "*** Check for common spelling mistakes in .go files... ***"
    @misspell -error $(GO_FILES)
    @echo "*** Done ***"

fix_spelling:
    @echo "*** Fix any encountered spelling mistakes in .go files... ***"
    @misspell -w $(GO_FILES)
    @echo "*** Done ***"

vet:
    @echo "*** Running vet on package directories... ***"
    @go list ./... | grep -v /vendor/ | xargs go vet
    @echo "*** Done ***"

dep:
    @echo "*** Installing all dependencies... ***"
    @dep ensure
    @echo "*** Done ***"

bootstrap:
    @echo "*** Installing required tools for building... ***"
    @for tool in  $(EXTERNAL_TOOLS) ; do \
        echo "Installing/Updating $$tool" ; \
        GO111MODULE=off go get -u $$tool; \
    done
    @echo "*** Done ***"

help:
    @printf "\n*** Available make targets ***\n\n"
    @printf $(HELP_FORMATSTRING) "help" "This message"
    @printf $(HELP_FORMATSTRING) "bootstrap" "Install tools needed for build"
    @printf $(HELP_FORMATSTRING) "dep" "Install libraries needed for compilation"
    @printf $(HELP_FORMATSTRING) "build" "Compile for all targets"
    @printf $(HELP_FORMATSTRING) "vet" "Checks code for common mistakes"
    @printf $(HELP_FORMATSTRING) "fmt" "Fix formatting on .go files"
    @printf $(HELP_FORMATSTRING) "check_spelling" "Show potential spelling mistakes"
    @printf $(HELP_FORMATSTRING) "fix_spelling" "Correct detected spelling mistakes"
    @printf $(HELP_FORMATSTRING) "local" "Build executable for your OS, for testing purposes"
    @printf $(HELP_FORMATSTRING) "clean" "Clean your working directory"
    @printf "\n*** End ***\n\n"

结果:

make build                                                                                                                                     
Makefile:26: *** missing separator.  Stop.

首先,我认为这是空格与制表符的问题,但我不再认为是这种情况:

> $ cat -e -t -v Makefile                                                                                                                          [±develop ●]
GOBUILD=go build$
GOX=gox$
BINARY_NAME=tobw$
$
VERSION=$(shell git describe --tags --always --dirty)$
# linker flags for stripping debug info and injecting version info$
LD_FLAGS="-s -w -X main.Version=$(VERSION)"$
BIN_TARGETS="windows/386 windows/amd64 darwin/386 darwin/amd64 linux/386 linux/amd64 linux/arm linux/arm64 freebsd/386 freebsd/amd64 freebsd/arm openbsd/386 openbsd/amd64 openbsd/arm netbsd/386 netbsd/amd64 netbsd/arm"$
$
$
# Used for help output$
HELP_SPACING=15$
HELP_COLOR=33$
HELP_FORMATSTRING="\033[$(HELP_COLOR)m%-$(HELP_SPACING)s \033[00m%s.\n"$
$
GO_FILES?=$$(find . -name '*.go' | grep -v vendor)$
EXTERNAL_TOOLS=\$
^Igolang.org/x/tools/cmd/goimports \$
^Igithub.com/golang/dep/cmd/dep \$
^Igithub.com/client9/misspell/cmd/misspell \$
^Igithub.com/mitchellh/gox$
$
.PHONY: build local$
$
build:$
    @echo "*** Building binaries for supported architectures... ***"$
    $(GOX) -osarch=$(BIN_TARGETS) -ldflags=$(LD_FLAGS) -output="bin/{{.Dir}}_{{.OS}}_{{.Arch}}"$
    @echo "*** Done ***"$
$
local:$
^I@echo "*** Building local binary... ***"$
^I$(GOBUILD) -o $(BINARY_NAME) ./$
^I@echo "*** Done ***"$
$
.PHONY: clean fmt check_spelling fix_spelling vet dep$
$
clean:$
^I@echo "*** Cleaning up object files... ***"$
^Irm -r -f bin/*$
^Irm -f tobw$
^Irm -f tobw.exe$
^Igo clean$
^I@echo "*** Done ***"$
$
fmt:$
^I@echo "*** Applying gofmt on all .go files (excluding vendor)... ***"$
^I@goimports -w $(GO_FILES)$
^I@echo "*** Done ***"$
$
check_spelling:$
^I@echo "*** Check for common spelling mistakes in .go files... ***"$
^I@misspell -error $(GO_FILES)$
^I@echo "*** Done ***"$
$
fix_spelling:$
^I@echo "*** Fix any encountered spelling mistakes in .go files... ***"$
^I@misspell -w $(GO_FILES)$
^I@echo "*** Done ***"$
$
vet:$
^I@echo "*** Running vet on package directories... ***"$
^I@go list ./... | grep -v /vendor/ | xargs go vet$
^I@echo "*** Done ***"$
$
dep:$
^I@echo "*** Installing all dependencies... ***"$
^I@dep ensure$
^I@echo "*** Done ***"$
$
bootstrap:$
^I@echo "*** Installing required tools for building... ***"$
^I@for tool in  $(EXTERNAL_TOOLS) ; do \$
^I^Iecho "Installing/Updating $$tool" ; \$
^I^IGO111MODULE=off go get -u $$tool; \$
^Idone$
^I@echo "*** Done ***"$
$
help:$
^I@printf "\n*** Available make targets ***\n\n"$
^I@printf $(HELP_FORMATSTRING) "help" "This message"$
^I@printf $(HELP_FORMATSTRING) "bootstrap" "Install tools needed for build"$
^I@printf $(HELP_FORMATSTRING) "dep" "Install libraries needed for compilation"$
^I@printf $(HELP_FORMATSTRING) "build" "Compile for all targets"$
^I@printf $(HELP_FORMATSTRING) "vet" "Checks code for common mistakes"$
^I@printf $(HELP_FORMATSTRING) "fmt" "Fix formatting on .go files"$
^I@printf $(HELP_FORMATSTRING) "check_spelling" "Show potential spelling mistakes"$
^I@printf $(HELP_FORMATSTRING) "fix_spelling" "Correct detected spelling mistakes"$
^I@printf $(HELP_FORMATSTRING) "local" "Build executable for your OS, for testing purposes"$
^I@printf $(HELP_FORMATSTRING) "clean" "Clean your working directory"$
^I@printf "\n*** End ***\n\n"$

我能理解为什么人们一旦不得不处理Makefile,就不能继续从事软件开发事业...

0 个答案:

没有答案