-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
114 lines (97 loc) · 5.17 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
################################################################################
# SlackOverflow make
################################################################################
SLACKOVERFLOW = slackoverflow
SLACKOVERFLOW_PATH = $(PWD)
SLACKOVERFLOW_BUILD_DIR = ${SLACKOVERFLOW_PATH}/build
SLACKOVERFLOW_BINARY = ${SLACKOVERFLOW_BUILD_DIR}/${SLACKOVERFLOW}
SLACKOVERFLOW_CONTRIBUTORS = ${SLACKOVERFLOW_PATH}/slackoverflow/contributors.go
SLACKOVERFLOW_BUILD_DATE = $(shell if hash gdate 2>/dev/null; then gdate --rfc-3339=seconds | sed 's/ /T/'; else date --rfc-3339=seconds | sed 's/ /T/'; fi)
################################################################################
# Go LDFLAGS
define SLACKOVERFLOW_LDFLAGS
-X main.buildDate=${SLACKOVERFLOW_BUILD_DATE}
endef
export SLACKOVERFLOW_LDFLAGS
################################################################################
# Makefile Functions
define log_info
@printf "\033[94m%s\033[0m \033[1m%s\033[0m\n" "[${SLACKOVERFLOW} make]:" "$(1)"
endef
define log_error
@printf "\033[33m%s\031[0m \033[1m%s\033[0m\n" "[${SLACKOVERFLOW} make]:" "$(1)"
endef
define log_warn
@printf "\033[33m%s\033[0m \033[1m%s\033[0m\n" "[${SLACKOVERFLOW} make]:" "$(1)"
endef
define log_ok
@printf "\033[32m%s\033[0m \033[1m%s\033[0m\n" "[${SLACKOVERFLOW} make]:" "$(1)"
endef
################################################################################
# Default goals
.DEFAULT_GOAL := slackoverflow
################################################################################
# Help
help: ## Show this help menu
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[33m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
################################################################################
# Build
slackoverflow: ## Build new SlackOverflow binary
$(call log_info, build new SlackOverflow binary)
go build -a -ldflags "${SLACKOVERFLOW_LDFLAGS}" -o ${SLACKOVERFLOW_BINARY}
$(call log_ok, new binary ready)
################################################################################
# Install
install: ## Execute Go install
$(call log_info, Execute Go install)
go install -ldflags "${SLACKOVERFLOW_LDFLAGS}" .
################################################################################
# Info
info: ## Show makefile variables
$(call log_info, SLACKOVERFLOW ${SLACKOVERFLOW}.)
$(call log_info, SLACKOVERFLOW_PATH ${SLACKOVERFLOW_PATH}.)
$(call log_info, SLACKOVERFLOW_BUILD_DIR ${SLACKOVERFLOW_BUILD_DIR}.)
$(call log_info, SLACKOVERFLOW_BINARY ${SLACKOVERFLOW_BINARY}.)
$(call log_info, SLACKOVERFLOW_CONTRIBUTORS ${SLACKOVERFLOW_CONTRIBUTORS}.)
$(call log_info, SLACKOVERFLOW_BUILD_DATE ${SLACKOVERFLOW_BUILD_DATE}.)
$(call log_info, SLACKOVERFLOW_LDFLAGS ${SLACKOVERFLOW_LDFLAGS}.)
################################################################################
# Dependencies
dependencies: ## Install SlackOverflow build dependencies
$(call log_info, The Vendor Tool for Go.)
@go get -u github.com/kardianos/govendor
$(call log_ok, github.com/kardianos/govendor)
$(call log_info, sqlite3 driver conforming to the built-in database/sql interface.)
@go get -u github.com/mattn/go-sqlite3
$(call log_ok, github.com/mattn/go-sqlite3)
$(call log_info, Install Aurora - ultimate ANSI colors for Golang. The package supports Printf/Sprintf etc.)
@govendor fetch github.com/logrusorgru/aurora@962a6974312dde57d1f6f5738b4f83e1af9f38a4
$(call log_ok, github.com/logrusorgru/aurora@962a6974312dde57d1f6f5738b4f83e1af9f38a4)
$(call log_info, Install yaml.v2 - package that implements YAML support for the Go language.)
@govendor fetch github.com/go-yaml/yaml@=v2
$(call log_ok, github.com/go-yaml/yaml@=v2)
$(call log_info, Install go-flags - a go library for parsing command line arguments.)
@govendor fetch github.com/jessevdk/go-flags@=v1.1.0
$(call log_ok, github.com/jessevdk/go-flags@=v1.1.0)
$(call log_info, Install cron - a cron library for go .)
@govendor fetch github.com/robfig/cron@=v2
$(call log_ok, github.com/robfig/cron@=v2)
$(call log_info, Install daemon - A daemon package for use with Go golang services with no dependencies .)
@govendor fetch github.com/takama/daemon
$(call log_ok, github.com/takama/daemon)
################################################################################
# Contributors
contributors: ## Update contributors list
$(call log_info, Regenerating ${SLACKOVERFLOW_CONTRIBUTORS}.)
$(shell echo -e "// Package slackoverflow - This is autogenerated file. To Regenerate contributors list run (make contributors)" > ${SLACKOVERFLOW_CONTRIBUTORS})
$(shell echo -e "package slackoverflow\n" >> ${SLACKOVERFLOW_CONTRIBUTORS})
$(shell echo -e "var contributors = []string{" >> ${SLACKOVERFLOW_CONTRIBUTORS})
$(shell git log --format=' "%aN %aE",' | sort -u >> ${SLACKOVERFLOW_CONTRIBUTORS})
$(shell echo -e "}" >> ${SLACKOVERFLOW_CONTRIBUTORS})
$(call log_ok, Updated contributors list)
################################################################################
# Clean
clean: ## Remove existing binary if exists
if [ -f ${SLACKOVERFLOW_BINARY} ]; then rm ${SLACKOVERFLOW_BINARY}; fi
$(call log_ok, SlackOverflow old binary removed)
.PHONY: clean slackoverflow