-
Notifications
You must be signed in to change notification settings - Fork 78
/
Makefile
143 lines (116 loc) · 4.2 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# GNU-standard vars (cf. http://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html)
SHELL = /bin/sh
# Paths may be loaded from mk/config.mk, whcih is made by configure
-include mk/config.mk
prefix ?= /usr/local
bindir ?= ${prefix}/bin
libexecdir ?= ${prefix}/libexec
sysconfdir ?= /etc
localstatedir ?= ${prefix}/var
srcdir = .
INSTALL = install
INSTALL_PROGRAM = ${INSTALL}
JOBBER_VERSION := $(shell cat ${srcdir}/version)
SRC_TARBALL = jobber-${JOBBER_VERSION}.tgz
SRC_TARBALL_DIR = jobber-${JOBBER_VERSION}
OUTPUT_DIR = bin
GO = go
GO_VERSION = 1.11
# NOTE: '-mod=vendor' prevents go from downloading dependencies
GO_BUILD_BASE_FLAGS := -mod=vendor
COMPILETIME_VARS := \
-X 'github.com/dshearer/jobber/common.jobberVersion=${JOBBER_VERSION}' \
-X 'github.com/dshearer/jobber/common.etcDirPath=${sysconfdir}'
GO_BUILD := ${GO} build ${GO_BUILD_BASE_FLAGS} -ldflags "${COMPILETIME_VARS}"
GO_VET = ${GO} vet -mod=vendor
GO_TEST = ${GO} test -mod=vendor
GO_GEN = ${GO_WITH_TOOLS} generate -mod=vendor
GO_CLEAN = ${GO} clean -mod=vendor
PACKAGES = \
github.com/dshearer/jobber/common \
github.com/dshearer/jobber/ipc \
github.com/dshearer/jobber/jobber \
github.com/dshearer/jobber/jobbermaster \
github.com/dshearer/jobber/jobberrunner \
github.com/dshearer/jobber/jobfile
include mk/def-sources.mk
.PHONY : default
default : build
include mk/buildtools.mk # defines 'GO_WITH_TOOLS' and 'GOYACC'
################################################################################
# BUILD
################################################################################
.PHONY : build
build : check ${OUTPUT_DIR}/jobber ${OUTPUT_DIR}/jobbermaster \
${OUTPUT_DIR}/jobberrunner ${OUTPUT_DIR}/jobber.conf
@echo
@echo "Built with these paths:"
@echo "localstatedir: ${localstatedir}"
@echo "libexecdir: ${libexecdir}"
@echo "sysconfdir: ${sysconfdir}"
.PHONY : check
check : ${TEST_SOURCES} jobfile/parse_time_spec.go
@go version
@echo GO TEST
@${GO_TEST} ${PACKAGES}
${OUTPUT_DIR}/% : ${MAIN_SOURCES} jobfile/parse_time_spec.go
@$(call checkGoVersion)
@echo GO VET
@${GO_VET} ${PACKAGES}
@echo BUILD $*
@${GO_BUILD} -o "$@" "github.com/dshearer/jobber/$*"
${OUTPUT_DIR}/jobber.conf : ${OUTPUT_DIR}/jobbermaster
@echo BUILD $@
@${OUTPUT_DIR}/jobbermaster defprefs --var "${localstatedir}" --libexec "${libexecdir}" > "$@"
jobfile/parse_time_spec.go : ${GOYACC} ${JOBFILE_SOURCES}
@echo GEN SRC
@${GO_GEN} -mod=vendor github.com/dshearer/jobber/jobfile
################################################################################
# INSTALL
################################################################################
install : \
${DESTDIR}${libexecdir}/jobbermaster \
${DESTDIR}${libexecdir}/jobberrunner \
${DESTDIR}${bindir}/jobber \
${DESTDIR}${sysconfdir}/jobber.conf
${DESTDIR}${libexecdir}/% : ${OUTPUT_DIR}/%
@echo INSTALL $@
@mkdir -p "${dir $@}"
@${INSTALL_PROGRAM} "$<" "$@"
${DESTDIR}${bindir}/% : ${OUTPUT_DIR}/%
@echo INSTALL $@
@mkdir -p "${dir $@}"
@${INSTALL_PROGRAM} "$<" "$@"
${DESTDIR}${sysconfdir}/jobber.conf : ${OUTPUT_DIR}/jobber.conf
@echo INSTALL $@
@mkdir -p "${dir $@}"
@cp "$<" "$@"
.PHONY : uninstall
uninstall :
-rm "${DESTDIR}${libexecdir}/jobbermaster"
-rm "${DESTDIR}${libexecdir}/jobberrunner"
-rm "${DESTDIR}${bindir}/jobber"
-rm "${DESTDIR}${sysconfdir}/jobber.conf"
.PHONY : dist
dist :
mkdir -p "${DESTDIR}dist-tmp"
"${srcdir}/buildtools/srcsync" ${ALL_SOURCES} \
"${DESTDIR}dist-tmp/${SRC_TARBALL_DIR}"
tar -C "${DESTDIR}dist-tmp" -czf "${DESTDIR}${SRC_TARBALL}" \
"${SRC_TARBALL_DIR}"
rm -rf "${DESTDIR}dist-tmp"
################################################################################
# CLEAN
################################################################################
.PHONY : clean
clean : clean-buildtools
@echo CLEAN
@-${GO_CLEAN} -i ${PACKAGES}
@rm -rf "${DESTDIR}${SRC_TARBALL}.tgz" jobfile/parse_time_spec.go \
jobfile/y.output "${OUTPUT_DIR}"
################################################################################
# MISC
################################################################################
define checkGoVersion
${srcdir}/buildtools/versionge "$$(go version | egrep -o '[[:digit:].]+' | head -n 1)" "${GO_VERSION}"
endef