【Basic】 Makefile Basics

 

Example Makefile

.PHONY: generate update_submodule server rpc mock build run clean build_run

fetch:
	go get -u github.com/google/wire
	go get -u github.com/golang/mock/gomock
	go get -u github.com/smartystreets/goconvey/convey

generate: update_submodule server rpc mock

update_submodule:
ifeq ($(wildcard idl/.*),)
	git submodule init
endif
	git submodule update --remote

server:
	$(idlgen) -module $(prefix) -service $(psm) idl/video/kite_demo.thrift

rpc:
	$(idlgen) idl/content/arch/diting.thrift
	$(idlgen) idl/video/user_packer.thrift
	$(idlgen) idl/article/article_article.thrift
	$(idlgen) idl/video/favourite.thrift

mock:
	rm -rf mock/*
	mockgen -source=dal/db/channel.go -package=dbmock -destination=mock/db/channel.go
	mockgen -source=dal/db/union_category.go -package=dbmock -destination=mock/db/union_category.go
	mockgen -source=dal/kv/redis_channel.go -package=kvmock -destination=mock/kv/redis_channel.go
	mockgen -source=dal/tcc/demotion.go -package=tccmock -destination=mock/tcc/demotion.go
	mockgen -source=dal/tcc/conf.go -package=tccmock -destination=mock/tcc/conf.go
	mockgen -source=kitex_gen/content/arch/diting/ditingservice/client.go -package=ditingmock -destination=mock/rpc/diting/client.go
	mockgen -source=kitex_gen/video/user_packer/videouserpackerservice/client.go -package=userpackermock -destination=mock/rpc/user_packer/client.go
	mockgen -source=kitex_gen/article_article/articlearticleservice/client.go -package=articlemock -destination=mock/rpc/article/client.go

test:
	# 测试覆盖率和竞态检查
	go test -v -count=1 -race -cover -covermode=atomic -failfast $$(go list ./... | grep -v '/kitex_gen\|/faas\|/cronjob\|/mock\|/idl')

# make build_run
build_run: clean build run

build:
	./build.sh

run:
	./output/bootstrap.sh output

clean:
	rm -rf output

.PHONY at the beginning of file means that the command, for instance, .PHONY: install,

  • the word install doesn’t represent a file name in this Makefile
  • the Makefile has nothing to do with a file called install in the same directory.