Skip to main content

[Note] Makefile 使用

go-makefile-example @ github

在專/案中新增檔名為 Makefile 的檔案,在檔案中可以寫入對應的 Terminal 指令:

# Makefilehello:    echo "Hello"
build:    go build -o bin/main main.go
run:    go run main.go
compile:    # 32-Bit Systems    # FreeBDS    GOOS=freebsd GOARCH=386 go build -o bin/main-freebsd-386 main.go    # MacOS    GOOS=darwin GOARCH=386 go build -o bin/main-darwin-386 main.go    # Linux    GOOS=linux GOARCH=386 go build -o bin/main-linux-386 main.go    # Windows    GOOS=windows GOARCH=386 go build -o bin/main-windows-386 main.go        # 64-Bit    # FreeBDS    GOOS=freebsd GOARCH=amd64 go build -o bin/main-freebsd-amd64 main.go    # MacOS    GOOS=darwin GOARCH=amd64 go build -o bin/main-darwin-amd64 main.go    # Linux    GOOS=linux GOARCH=amd64 go build -o bin/main-linux-amd64 main.go    # Windows    GOOS=windows GOARCH=amd64 go build -o bin/main-windows-amd64 main.go
all: hello build

在專案中只需要使用 make ooo 就可以執行對應的指令:

$ make hello   # "Hello"
$ make all     # 會同時執行 hello 和 build 對應的指令

參考#