Skip to content

Instantly share code, notes, and snippets.

@halink0803
Created January 5, 2018 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halink0803/0f117ccde15ba3b747e985a4258526f2 to your computer and use it in GitHub Desktop.
Save halink0803/0f117ccde15ba3b747e985a4258526f2 to your computer and use it in GitHub Desktop.

Save from post Makefile cho Go

SRC = $(wildcard *.go)
OUT = <tên-file-binary-muốn-build>

CC = go
go = $(shell which go 2> /dev/null)

ifeq (, $(go))
    @printf "\e[91mGo not found!"
endif

$(OUT): clean $(SRC)
    @printf "\e[33mBuilding\e[90m %s\e[0m\n" $@
    @$(CC) build -o $@ $(SRC)
    @printf "\e[34mDone!\e[0m\n"

test: clean
    @printf "\e[33mTesting...\e[0m\n"
    go test ./...
    @printf "\e[34mDone!\e[0m\n"

clean:
    @rm -f $(OUT)
    @printf "\e[34mAll clear!\e[0m\n"

install: $(OUT)
    @printf "\e[33mInstalling\e[90m %s\e[0m\n" $(OUT)
    sudo rm -f /usr/local/bin/$(OUT)
    sudo ln -s $(PWD)/$(OUT) /usr/local/bin/$(OUT)
    @printf "\e[34mDone!\e[0m\n"

uninstall:
    @printf "\e[33mRemoving\e[90m %s\e[0m\n" $(OUT)
    sudo rm -f /usr/local/bin/$(OUT)
    @printf "\e[34mDone!\e[0m\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment