Makefile 3.4 KB
Newer Older
W
wangzelin.wzl 已提交
1 2
include Makefile.common

O
ob-robot 已提交
3
.PHONY: pre-build build bindata mgragent monagent agentd agentctl mockgen rpm buildsucc
W
wangzelin.wzl 已提交
4

O
ob-robot 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
default: clean fmt pre-build build

pre-build: bindata

pre-test: mockgen

bindata: get
	go-bindata -o bindata/bindata.go -pkg bindata assets/...

mockgen:
	mockgen -source=lib/http/http.go -destination=tests/mock/lib_http_http_mock.go -package mock
	mockgen -source=lib/system/process.go -destination=tests/mock/lib_system_process_mock.go -package mock
	mockgen -source=lib/system/disk.go -destination=tests/mock/lib_system_disk_mock.go -package mock
	mockgen -source=lib/system/system.go -destination=tests/mock/lib_system_system_mock.go -package mock
	mockgen -source=lib/shell/shell.go -destination=tests/mock/lib_shell_shell_mock.go -package mock
	mockgen -source=lib/shell/command.go -destination=tests/mock/lib_shell_command_mock.go -package mock
	mockgen -source=lib/shellf/shellf.go -destination=tests/mock/lib_shellf_shellf_mock.go -package mock
	mockgen -source=lib/file/file.go -destination=tests/mock/lib_file_file_mock.go -package mock
	mockgen -source=lib/pkg/package.go -destination=tests/mock2/lib_pkg_package_mock.go -package mock2
W
wangzelin.wzl 已提交
24 25 26

build: build-debug

O
ob-robot 已提交
27 28 29
build-debug: set-debug-flags mgragent monagent agentd agentctl buildsucc

build-release: set-release-flags mgragent monagent agentd agentctl buildsucc
W
wangzelin.wzl 已提交
30

O
ob-robot 已提交
31 32
rpm:
	cd ./rpm && RELEASE=`date +%Y%m%d%H%M%S` rpmbuild -bb ./obagent.spec
W
wangzelin.wzl 已提交
33 34 35 36

set-debug-flags:
	@echo Build with debug flags
	$(eval LDFLAGS += $(LDFLAGS_DEBUG))
O
ob-robot 已提交
37
	$(eval BUILD_FLAG += $(GO_RACE_FLAG))	
W
wangzelin.wzl 已提交
38 39 40 41 42 43

set-release-flags:
	@echo Build with release flags
	$(eval LDFLAGS += $(LDFLAGS_RELEASE))

monagent:
O
ob-robot 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57
	$(GO) build $(BUILD_FLAG) -ldflags '$(MONAGENT_LDFLAGS)' -o bin/ob_monagent cmd/monagent/main.go

mgragent: 
	$(GO) build $(BUILD_FLAG) -ldflags '$(MGRAGENT_LDFLAGS)' -o bin/ob_mgragent cmd/mgragent/main.go

agentctl:
	$(GO) build $(BUILD_FLAG) -ldflags '$(AGENTCTL_LDFLAGS)' -o bin/ob_agentctl cmd/agentctl/main.go

agentd:
	$(GO) build $(BUILD_FLAG) -ldflags '$(AGENTD_LDFLAGS)' -o bin/ob_agentd cmd/agentd/main.go


buildsucc:
	@echo Build obagent successfully!
W
wangzelin.wzl 已提交
58

O
ob-robot 已提交
59 60 61 62 63 64 65
runmgragent:
	./bin/ob_mgragent --config tests/testdata/mgragent.yaml

runmonagent:
	./bin/ob_monagent --config tests/testdata/monagent.yaml

test: pre-build pre-test
W
wangzelin.wzl 已提交
66 67
	$(GOTEST) $(GOTEST_PACKAGES)

O
ob-robot 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
test-cover-html:
	go tool cover -html=$(GOCOVERAGE_FILE)

test-cover-html-out:
	mkdir -p $(GOCOVERAGE_REPORT)
	go tool cover -html=$(GOCOVERAGE_FILE) -o $(GOCOVERAGE_REPORT)/index.html

test-cover-profile:
	go tool cover -func=$(GOCOVERAGE_FILE)

test-cover-total:
	go tool cover -func=$(GOCOVERAGE_FILE) | tail -1 | awk '{print "total line coverage: " $$3}'

deploy:
	mkdir /home/admin/obagent
	cp -r bin /home/admin/obagent/bin
	cp -r etc /home/admin/obagent/conf
	mkdir -p /home/admin/obagent/{log,run,tmp,backup,pkg_store,task_store,position_store}

W
wangzelin.wzl 已提交
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fmt:
	@gofmt -s -w $(filter-out , $(GOFILES))

fmt-check:
	@if [ -z "$(UNFMT_FILES)" ]; then \
		echo "gofmt check passed"; \
		exit 0; \
    else \
    	echo "gofmt check failed, not formatted files:"; \
    	echo "$(UNFMT_FILES)" | tr -s " " "\n"; \
    	exit 1; \
    fi

tidy:
	$(GO) mod tidy

O
ob-robot 已提交
103 104 105 106
get:
	$(GO) install github.com/go-bindata/go-bindata/...@v3.1.2+incompatible
	$(GO) install github.com/golang/mock/mockgen@v1.6.0

W
wangzelin.wzl 已提交
107 108 109 110 111 112
vet:
	go vet $$(go list ./...)

clean:
	rm -rf $(GOCOVERAGE_FILE)
	rm -rf tests/mock/*
O
ob-robot 已提交
113
	rm -rf bin/ob_mgragent bin/ob_monagent bin/ob_agentctl bin/ob_agentd
W
wangzelin.wzl 已提交
114
	$(GO) clean -i ./...
O
ob-robot 已提交
115 116

init: pre-build pre-test tidy