This repository was archived by the owner on Oct 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
306 lines (253 loc) · 11 KB
/
Makefile
File metadata and controls
306 lines (253 loc) · 11 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# Makefile for building binaries for different architectures and operating
# systems.
#
# Differences per target:
# * On Windows, -ldflags "-H windowsgui" is added to hide cmd.exe upon execution
# * On Windows, .syso file is generated to include icon in built binary
#
# See README.md for details on requirements.
#
# Set to true to have dev tools in build, set to false or disabled for
# prodution builds to omit devtools access
ENABLE_DEV_TOOLS := false
# Set to true to make app unpack assets to temp at lauch. Will cause assets to
# be always unpacked at start and deleted when app closes. If false, assets are
# unpacked under users HOME and vendored assets are re-used between launches.
USE_TEMP := false
# App version is the application version
APP_VERSION = v0.1
# Build string tells where and when the app was built
BUILD_STRING := $(shell git rev-parse --short HEAD)-$(shell git rev-parse --abbrev-ref HEAD)-$(shell hostname)
# Application namespace for temp files etc. generated content
APP_PREFIX := stopwatch
# Application name
APP_NAME := stopwatch ${APP_VERSION}
# App filename is the filename prefix for resulting binaries
APP_FILENAME := stopwatch
# root package is usually repo name, package name used in go imports
ROOT_PKG := github.com/msepp/stopwatch
# Electron and astilectron versions to use. These versions are passed via env
# and linker to Go, so you should not need to change them anywhere else.
ELECTRON_VERSION := v1.7.9
ASTILECTRON_VERSION := v0.14.0
# Resources dir name
RESOURCES_DIR := resources
# Where to download vendor materials
VENDOR_DIR := ${RESOURCES_DIR}/runtime
# Directory for built UI resources
UI_DIR := ${RESOURCES_DIR}/ui
# Icons directory
ICONS_DIR := ${RESOURCES_DIR}/icons
# Directory for UI sources
UI_SRC_DIR := app-ui
# Path to the final UI bundle
UI_BUNDLE := ${UI_SRC_DIR}/dist/app.asar
# Path to UI index file for setting project name
UI_SRC_INDEX := ${UI_SRC_DIR}/src/index.html
# App .ico path
APP_ICO := ${ICONS_DIR}/app.ico
# Icons used in the final build
ICONS := ${ICONS_DIR}/app.icns \
${ICONS_DIR}/app.png \
${APP_ICO}
# Paths for the downloaded vendored packages per GOOS and GOARCH.
# Note that astilectron is the same for all platforms.
VENDOR_ASTILECTRON := ${VENDOR_DIR}/astilectron-${ASTILECTRON_VERSION}.zip
VENDOR_LINUX_386 := ${VENDOR_DIR}/electron-${ELECTRON_VERSION}-linux-386.zip
VENDOR_LINUX_AMD64 := ${VENDOR_DIR}/electron-${ELECTRON_VERSION}-linux-amd64.zip
VENDOR_WINDOWS_386 := ${VENDOR_DIR}/electron-${ELECTRON_VERSION}-windows-386.zip
VENDOR_WINDOWS_AMD64 := ${VENDOR_DIR}/electron-${ELECTRON_VERSION}-windows-amd64.zip
# URLs for downloading vendored packages per GOOS and GOARCH.
# Here too we only need one URL for astilectron.
VENDOR_URL_ASTILECTRON := https://github.com/asticode/astilectron/archive/${ASTILECTRON_VERSION}.zip
VENDOR_URL_LINUX_386 := https://github.com/electron/electron/releases/download/${ELECTRON_VERSION}/electron-${ELECTRON_VERSION}-linux-ia32.zip
VENDOR_URL_LINUX_AMD64 := https://github.com/electron/electron/releases/download/${ELECTRON_VERSION}/electron-${ELECTRON_VERSION}-linux-x64.zip
VENDOR_URL_WINDOWS_386 := https://github.com/electron/electron/releases/download/${ELECTRON_VERSION}/electron-${ELECTRON_VERSION}-win32-ia32.zip
VENDOR_URL_WINDOWS_AMD64 := https://github.com/electron/electron/releases/download/${ELECTRON_VERSION}/electron-${ELECTRON_VERSION}-win32-x64.zip
# Bindata builder binary
BINDATA := go-bindata -pkg main -nomemcopy
# Common bindata resources. A list of things to pack into the binary.
# Electron is selected separately based on OS/Arch
# We try to omit all files we don't actually need.
BINDATA_COMMON := ${VENDOR_ASTILECTRON} \
${UI_DIR}/ui.asar \
${ICONS_DIR}/*
# Valid build targets, ie. supported GOOS + GOARCH combinations.
VALID_TARGETS := ${APP_FILENAME}-linux-386 \
${APP_FILENAME}-linux-amd64 \
${APP_FILENAME}-windows-386.exe \
${APP_FILENAME}-windows-amd64.exe
# Filenames for go:generate products per GOOS and GOARCH combo
RESOURCES_LINUX_386 := resources-linux-386.go.res
RESOURCES_LINUX_AMD64 := resources-linux-amd64.go.res
RESOURCES_WINDOWS_386 := resources-windows-386.go.res
RESOURCES_WINDOWS_AMD64 := resources-windows-amd64.go.res
# Common dependencies for go:generate, files that aren't platform dependent but
# are included in the generated .go file.
RESOURCES_DEPS_COMMON := ${UI_DIR}/ui.asar \
${ICONS}
# Common dependencies for the final build product, these are the same for all
# GOOS and GOARCH variants
COMMON_DEPS := Makefile \
*.go \
stopwatchdb/*.go \
stopwatchmodel/*.go \
stopwatchapp/*.go
# Linker flags for setting version info for config during build.
LDFLAGS := -X '${ROOT_PKG}/stopwatchapp.electronVersion=${ELECTRON_VERSION}' \
-X '${ROOT_PKG}/stopwatchapp.astilectronVersion=${ASTILECTRON_VERSION}' \
-X '${ROOT_PKG}/stopwatchapp.appVersion=${APP_VERSION}' \
-X '${ROOT_PKG}/stopwatchapp.resourcesDir=${RESOURCES_DIR}' \
-X '${ROOT_PKG}/stopwatchapp.devTools=${ENABLE_DEV_TOOLS}' \
-X '${ROOT_PKG}/stopwatchapp.useTemp=${USE_TEMP}' \
-X '${ROOT_PKG}/stopwatchapp.build=""${BUILD_STRING}""' \
-X '${ROOT_PKG}/stopwatchapp.guiName=""${UI_SRC_PROJECT}""' \
-X '${ROOT_PKG}/stopwatchapp.name=""${APP_NAME}""' \
-X '${ROOT_PKG}/stopwatchapp.prefix=""${APP_PREFIX}""'
DEFAULT_TARGET := ${APP_FILENAME}
ifeq ($(OS),Windows_NT)
DEFAULT_TARGET := ${DEFAULT_TARGET}-windows
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
DEFAULT_TARGET := ${DEFAULT_TARGET}-amd64.exe
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
DEFAULT_TARGET := ${DEFAULT_TARGET}-amd64.exe
else
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
DEFAULT_TARGET := ${DEFAULT_TARGET}-386.exe
else
DEFAULT_TARGET := unknown
endif
endif
endif
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
DEFAULT_TARGET := ${DEFAULT_TARGET}-linux
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
DEFAULT_TARGET := ${DEFAULT_TARGET}-amd64
else
ifneq ($(filter %86,$(UNAME_P)),)
DEFAULT_TARGET := ${DEFAULT_TARGET}-386
else
DEFAULT_TARGET := unknown
endif
endif
else
DEFAULT_TARGET := unknown
endif
endif
# Template resources file. Just a dummy to get builds working but empty to keep
# build times sensible.
RESTMPL := restmpl.go
# Build instructions with resource file shuffling to use the actual compiled
# resources file instead of placeholder.
BUILD_BIN=@echo "Building $@..." && \
if [ -f $< ]; then mv $< $(patsubst %.res,%,$<); fi && \
if [ -f $(RESTMPL) ]; then mv $(RESTMPL) $(RESTMPL).res; fi && \
GOARCH=$(GOARCH) GOOS=$(GOOS) go build -ldflags "$(LDFLAGS)" -o $@ && \
if [ -f $(patsubst %.res,%,$<) ]; then mv $(patsubst %.res,%,$<) $<; fi && \
if [ -f $(RESTMPL).res ]; then mv $(RESTMPL).res $(RESTMPL); fi
# All just outputs list of the real targets.
all: ${DEFAULT_TARGET}
@echo "Built ${DEFAULT_TARGET}"
unknown:
@echo "Valid targets: ${VALID_TARGETS}"
# Builds binary for 32bit Linux
${APP_FILENAME}-linux-386: GOARCH=386
${APP_FILENAME}-linux-386: GOOS=linux
${APP_FILENAME}-linux-386: ${RESOURCES_LINUX_386} ${COMMON_DEPS}
@$(RM) rsrc.syso
$(BUILD_BIN)
# Builds binary for 64bit Linux
${APP_FILENAME}-linux-amd64: GOARCH=amd64
${APP_FILENAME}-linux-amd64: GOOS=linux
${APP_FILENAME}-linux-amd64: ${RESOURCES_LINUX_AMD64} ${COMMON_DEPS}
@$(RM) rsrc.syso
$(BUILD_BIN)
# Builds binary for 32bit Windows.
${APP_FILENAME}-windows-386.exe: LDFLAGS += -H windowsgui
${APP_FILENAME}-windows-386.exe: GOARCH=386
${APP_FILENAME}-windows-386.exe: GOOS=windows
${APP_FILENAME}-windows-386.exe: ${RESOURCES_WINDOWS_386} ${COMMON_DEPS} rsrc.syso
$(BUILD_BIN)
# Builds binary for 64bit Windows
${APP_FILENAME}-windows-amd64.exe: LDFLAGS += -H windowsgui
${APP_FILENAME}-windows-amd64.exe: GOARCH=amd64
${APP_FILENAME}-windows-amd64.exe: GOOS=windows
${APP_FILENAME}-windows-amd64.exe: ${RESOURCES_WINDOWS_AMD64} ${COMMON_DEPS} rsrc.syso
$(BUILD_BIN)
# Generate .syso file to have an icon for the executable (Windows only).
# This file must be deleted when building for Linux.
rsrc.syso: ${APP_ICO}
@echo "Generating app icon for Windows target..."
@rsrc -ico ${APP_ICO}
# Generates resources file for 32bit Linux
${RESOURCES_LINUX_386}: ${VENDOR_LINUX_386} ${BINDATA_COMMON}
@echo "Creating bindata for Linux 32bit binary. This'll take a while..."
@$(RM) resources-window-*.go resources-*-amd64.go
@${BINDATA} -o $@ $^
# Generates resources file for 64bit Linux
${RESOURCES_LINUX_AMD64}: ${VENDOR_LINUX_AMD64} ${BINDATA_COMMON}
@echo "Creating bindata for Linux 64bit binary. This'll take a while..."
@$(RM) resources-window-*.go resources-*-386.go
@${BINDATA} -o $@ $^
# Generates resources file for 32bit Windows
${RESOURCES_WINDOWS_386}: ${VENDOR_WINDOWS_386} ${BINDATA_COMMON}
@echo "Creating bindata for Windows 32bit binary. This'll take a while..."
@$(RM) resources-linux-*.go resources-*-amd64.go
@${BINDATA} -o $@ $^
# Generates resources file for 64bit Windows
${RESOURCES_WINDOWS_AMD64}: ${VENDOR_WINDOWS_AMD64} ${BINDATA_COMMON}
@echo "Creating bindata for Windows 64bit binary. This'll take a while..."
@$(RM) resources-linux-*.go resources-*-386.go
@${BINDATA} -o $@ $^
# Copies bundled UI to the correct place under resources
${UI_DIR}/ui.asar: ${UI_BUNDLE}
@echo "Copying UI resources..."
@mkdir -p ${UI_DIR}
@cp ${UI_BUNDLE} $@
${UI_BUNDLE}: ${UI_BUNDLE}.stamp
@$(RM) $<
${UI_BUNDLE}.stamp:
@echo "Updating UI resources..."
@grep -q '${APP_NAME}' ${UI_SRC_INDEX} || sed -i -e 's/<title>.*<\/title>/<title>${APP_NAME}<\/title>/' ${UI_SRC_INDEX}
@$(MAKE) -C ${UI_SRC_DIR} ${UI_SRC_PROJECT}
# Downloads astilectron bundle
${VENDOR_ASTILECTRON}:
@echo "Retrieving astilectron..."
@mkdir -p ${VENDOR_DIR}
@wget ${VENDOR_URL_ASTILECTRON} -O $@
# Downloads Electron bundle for 32bit Linux
${VENDOR_LINUX_386}:
@echo "Retrieving Electron Linux 32bit. This'll take a while..."
@mkdir -p ${VENDOR_DIR}
@wget ${VENDOR_URL_LINUX_386} -O $@
# Downloads Electron bundle for 64bit Linux
${VENDOR_LINUX_AMD64}:
@echo "Retrieving Electron Linux 64bit. This'll take a while..."
@mkdir -p ${VENDOR_DIR}
@wget ${VENDOR_URL_LINUX_AMD64} -O $@
# Downloads Electron bundle for 32bit Windows
${VENDOR_WINDOWS_386}:
@echo "Retrieving Electron Windows 32bit. This'll take a while..."
@mkdir -p ${VENDOR_DIR}
@wget ${VENDOR_URL_WINDOWS_386} -O $@
# Downloads Electron bundle for 64bit Windows
${VENDOR_WINDOWS_AMD64}:
@echo "Retrieving Electron Windows 64bit. This'll take a while..."
@mkdir -p ${VENDOR_DIR}
@wget ${VENDOR_URL_WINDOWS_AMD64} -O $@
# Clean removes generated files
clean:
$(RM) -r ${UI_DIR}
$(RM) ${VALID_TARGETS}
$(RM) resources-*.go
$(RM) resources-*.go.res
$(RM) rsrc.syso
# Cleans vendored files
clean-vendor:
$(RM) -r ${VENDOR_DIR}
clean-all: clean-vendor clean
.PHONY:clean clean-vendor