This repository has been archived by the owner on Apr 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
174 lines (143 loc) · 4.72 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
.PHONY: man clean deb gem default all go
ifeq ($V, 1)
VERBOSE =
else
VERBOSE = @
VQUIET = >/dev/null
VSILENCE = >/dev/null 2>&1
endif
VERSION ?= $(shell cat VERSION)
INFO := @printf "\x1b[36m%10s\x1b[1;35m → \x1b[0;36m%s\x1b[0m\n"
## Go #########################################################################
PACKAGE := github.com/Shopify/ecfg
GO_FILES := $(shell find . -type f -name '*.go')
## Manpages ###################################################################
RONN ?= bundle exec ronn
RONN_FLAGS := \
--organization Shopify \
--manual "Version $(VERSION)" \
--style toc \
--warnings \
--roff \
--html
RONN_FILES := $(shell find man -name '*.ronn') # man/ecfg.1.ronn
BUILD_ROFF_FILES := $(RONN_FILES:%.ronn=%) # man/ecfg.1
BUILD_HTML_FILES := $(RONN_FILES:%.ronn=%.html) # man/ecfg.1.html
# man/ecfg.1 -> man/man1/ecfg.1
ROFF_FILES := $(foreach v, $(BUILD_ROFF_FILES), \
$(patsubst man.%,man/man%, \
$(subst man/,man$(suffix $v)/,$v) \
) \
)
# man/ecfg.1.html -> man/html/ecfg.1.html
HTML_FILES := $(foreach v, $(BUILD_HTML_FILES), \
$(subst man/,man/html/,$v) \
)
## Debian/Ubuntu Package ######################################################
FPM ?= bundle exec fpm
DEB := target/ecfg_$(VERSION)_amd64.deb
DEB_MANIFEST := \
usr/local/bin/ecfg \
DEBIAN/control \
$(foreach v, $(ROFF_FILES), $(addprefix usr/local/share/,$v))
DEB_FILES := $(foreach v, $(DEB_MANIFEST), \
$(addprefix build/ecfg_$(VERSION)_amd64/,$v) \
)
## Rubygem ####################################################################
GEM := target/ecfg-$(VERSION).gem
GEM_MANIFEST := \
bin/ecfg \
build/darwin-amd64/ecfg \
build/linux-amd64/ecfg \
$(ROFF_FILES) \
ecfg.gemspec \
lib/ecfg/version.rb \
LICENSE
GEM_FILES := \
build/rubygem/MANIFEST \
$(foreach v, $(GEM_MANIFEST), $(addprefix build/rubygem/,$v))
## Table of Contents ##########################################################
default: all
all: deb man gem
man: $(BUILD_ROFF_FILES) $(BUILD_HTML_FILES) $(ROFF_FILES) $(HTML_FILES)
deb: $(DEB)
gem: $(GEM)
go: build/bin/linux-amd64 build/bin/darwin-amd64
## Manpages ###################################################################
man/man1/%: man/%
@mkdir -p "$(@D)"
@cp "$<" "$@"
man/man5/%: man/%
@mkdir -p "$(@D)"
@cp "$<" "$@"
man/html/%: man/%
@mkdir -p "$(@D)"
@cp "$<" "$@"
man/%: man/%.ronn VERSION
$(INFO) 'ronn' 'man/*'
$(VERBOSE) $(RONN) $(RONN_FLAGS) man/*.ronn $(VSILENCE)
man/%.html: man/%.ronn VERSION
$(INFO) 'ronn' 'man/*'
$(VERBOSE) $(RONN) $(RONN_FLAGS) man/*.ronn $(VQUIET)
## Debian/Ubuntu Package ######################################################
build/ecfg_$(VERSION)_amd64/usr/local/bin/ecfg: build/bin/linux-amd64
@mkdir -p $(@D)
@cp "$<" "$@"
build/ecfg_$(VERSION)_amd64/usr/local/share/man/man1/%: man/man1/%
@mkdir -p $(@D)
@cp "$<" "$@"
build/ecfg_$(VERSION)_amd64/usr/local/share/man/man5/%: man/man5/%
@mkdir -p $(@D)
@cp "$<" "$@"
build/ecfg_$(VERSION)_amd64/DEBIAN/control: dist/debian/control.tpl
@mkdir -p $(@D)
$(VERBOSE) sed 's/{{VERSION}}/$(VERSION)/g' < "$<" > "$@"
$(DEB): $(DEB_FILES)
$(INFO) 'dpkg-deb' '$@'
@mkdir -p "$(@D)"
$(VERBOSE) $(VQUIET) dpkg-deb --build "build/ecfg_$(VERSION)_amd64" "$@"
## Rubygem ####################################################################
$(GEM): $(GEM_FILES)
@mkdir -p $(@D)
$(INFO) 'gem' '$(GEM)'
$(VERBOSE) cd build/rubygem && $(VQUIET) gem build ecfg.gemspec
@mv build/rubygem/ecfg-$(VERSION).gem $(GEM)
build/rubygem/ecfg.gemspec: dist/rubygem/ecfg.gemspec
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/bin/ecfg: dist/rubygem/bin/ecfg
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/MANIFEST: Makefile
@mkdir -p $(@D)
@echo $(GEM_MANIFEST) | tr ' ' \\n > $@
build/rubygem/LICENSE: LICENSE
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/man/man1/%: man/man1/%
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/man/man5/%: man/man5/%
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/build/%-amd64/ecfg: build/bin/%-amd64
@mkdir -p $(@D)
@cp "$<" "$@"
build/rubygem/lib/ecfg/version.rb: VERSION
@mkdir -p $(@D)
@echo "module Ecfg\n VERSION = \"$(VERSION)\"\nend" > "$@"
## Go #########################################################################
build/bin/%-amd64: $(GO_FILES)
$(INFO) 'go build' '$@'
$(VERBOSE) $(VQUIET) \
env GOOS=$(subst -amd64,,$(@F)) GOARCH=amd64 \
go build -o "$@" \
-ldflags "-X main.version=$(VERSION)" \
"$(PACKAGE)/cmd/ecfg"
## Misc #######################################################################
publish-site: $(HTML_FILES)
$(INFO) 'html' '☁️'
$(VERBOSE) dist/site/publish
clean:
@rm -f $(BUILD_ROFF_FILES) $(BUILD_HTML_FILES)
@rm -rf target build