forked from aequitas/macos-menubar-wireguard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
220 lines (181 loc) · 7.56 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
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
SHELL=/bin/bash
tmp=${TMPDIR:/=}
brew_bin:=$(shell brew --prefix || echo /usr/local)/bin
convert=${brew_bin}/convert
xcpretty=${HOME}/.gem/ruby/2.3.0/bin/xcpretty
swiftlint=${brew_bin}/swiftlint
tailor=${brew_bin}/tailor
git_sha=$(shell git rev-parse --short HEAD)
swift_sources=$(shell find * -name "*.swift"|grep -vE 'SKQueue|INIParse')
other_sources=$(shell find * -name "*.plist") WireGuardStatusbar.xcodeproj/project.pbxproj
sources=${swift_sources} ${other_sources}
# without argument make will run all tests and checks, build a distributable image
.PHONY: all
all: test dist
## Testing & Code quality
# run tests
test: .test-unit .test-integration
.test-unit: ${sources} .check | icons ${xcpretty}
set -o pipefail; xcodebuild -scheme WireGuardStatusbar test | ${xcpretty}
@touch $@
# verify code quality
check: .check
.check: ${swift_sources} .fix .check.tailor | ${swiftlint}
swiftlint --strict
@touch $@
# only run tailor on changed files as it is slow
.check.tailor: ${swift_sources} | .fix ${tailor}
tailor $?
@touch $@
# automatically fix all trivial code quality issues
fix: .fix
.fix: ${swift_sources} | ${swiftformat}
swiftformat $?
@touch $@
# setup requirements and run integration tests
test-integration: .test-integration
.test-integration: ${sources} /etc/wireguard/test-localhost.conf | icons
# application running in Xcode will hang the test
-osascript -e 'tell application "Xcode" to set actionResult to stop workspace document 1'
set -o pipefail; xcodebuild -scheme IntegrationTests test | ${xcpretty}
@touch $@
prep-integration: /etc/wireguard/test-localhost.conf
/etc/wireguard/test-localhost.conf: IntegrationTests/test-localhost.conf
sudo chmod 0755 ${@D}
sudo cp $< $@
## Building and distribution
# Location where xcodebuild puts .app when archiving
archive=${tmp}/WireGuardStatusbar.xcarchive
build_dest=${archive}/Products/Applications
dist=${tmp}/WireGuardStatusbar
# Create just the .app in the current working directory
app: WireGuardStatusbar.app
WireGuardStatusbar.app: ${build_dest}/WireGuardStatusbar.app
rm -rf "$@" && cp -r "${<}" "$@"
# Create distributable .dmg in current working directory
dist: WireGuardStatusbar.dmg
WireGuardStatusbar.dmg: ${dist}/WireGuardStatusbar.app
hdiutil create "$@" -srcfolder "${<D}" -ov
# Zipped distributable with current git commit sha
zip: WireGuardStatusbar-${git_sha}.zip
WireGuardStatusbar-${git_sha}.zip: ${tmp}/WireGuardStatusbar-${git_sha}.app
cd ${<D}; zip -r ${PWD}/$@ ${<F}
${tmp}/WireGuardStatusbar-${git_sha}.app: ${build_dest}/WireGuardStatusbar.app
rm -rf "$@" && cp -r "${<}" "$@"
# Generate contents for distributable .dmg
${dist}/WireGuardStatusbar.app: ${build_dest}/WireGuardStatusbar.app Misc/Uninstall.sh
rm -rf "${@D}/"; mkdir -p "${@D}/"
ln -sf /Applications "${@D}/Applications"
cp Misc/Uninstall.sh "${@D}/Uninstall"
cp Misc/Mullvad-Setup.sh "${@D}/Mullvad-Setup"
cp Misc/Setup "${@D}/Setup"
rm -rf "$@" && cp -r "$<" "$@"
# Generate archive build (this excludes debug symbols (dSYM) which are in a release build)
${build_dest}/WireGuardStatusbar.app: ${sources} | icons ${xcpretty}
xcodebuild -scheme WireGuardStatusbar -archivePath "${archive}" archive | ${xcpretty}
# install and run the App /Application using the distributable .dmg
install: /Applications/WireGuardStatusbar.app
/Applications/WireGuardStatusbar.app: ${build_dest}/WireGuardStatusbar.app | WireGuardStatusbar.dmg
-osascript -e 'tell application "WireGuardStatusbar" to quit'
-diskutil umount /Volumes/WireGuardStatusbar
hdiutil attach -quiet WireGuardStatusbar.dmg
cp -r /Volumes/WireGuardStatusbar/WireGuardStatusbar.app /Volumes/WireGuardStatusbar/Applications/
hdiutil detach -quiet /Volumes/WireGuardStatusbar/
open "$@"
uninstall:
Misc/Uninstall.sh
screenshot: Misc/demo.png
Misc/demo.png: ${all_sources} WireGuardStatusbar.app
Misc/screenshot.sh $@
## Icon/image generation
assets=WireGuardStatusbar/Assets.xcassets
.PHONY: icons appicon imagesets
icons: appicon imagesets
# The icon used by the application
appicon: \
${assets}/AppIcon.appiconset/16.png \
${assets}/AppIcon.appiconset/32.png \
${assets}/AppIcon.appiconset/64.png \
${assets}/AppIcon.appiconset/128.png \
${assets}/AppIcon.appiconset/256.png \
${assets}/AppIcon.appiconset/512.png \
${assets}/AppIcon.appiconset/1024.png
# Provide different sizes of appicon
${assets}/AppIcon.appiconset/%.png: Misc/logo.png
${convert} $< -strip -scale $*x$* $@
# Icons used for the menubar
imagesets: \
${assets}/silhouette.imageset/Contents.json \
${assets}/silhouette.imageset/18.png \
${assets}/silhouette.imageset/36.png \
${assets}/silhouette-dim.imageset/Contents.json \
${assets}/silhouette-dim.imageset/18.png \
${assets}/silhouette-dim.imageset/36.png \
${assets}/dragon.imageset/Contents.json \
${assets}/dragon.imageset/18.png \
${assets}/dragon.imageset/36.png \
${assets}/dragon-dim.imageset/Contents.json \
${assets}/dragon-dim.imageset/18.png \
${assets}/dragon-dim.imageset/36.png
# Provide 2 required sizes for any imageset variant
${assets}/%.imageset/18.png: Misc/%.png
${convert} $< -strip -scale 18x18 $@
${assets}/%.imageset/36.png: Misc/%.png
${convert} $< -strip -scale 36x36 $@
# Provide standard imageset definition
${assets}/%.imageset/Contents.json: Misc/imageset.Contents.json
mkdir -p ${@D}
cp $< $@
# Create a dimmed version of a image
%-dim.png: %.png | ${convert}
${convert} $< -strip -channel A -evaluate Multiply 0.50 +channel $@
# Extract the logo part from the banner, color it black and white
Misc/logo.png: Misc/wireguard.png | ${convert}
${convert} --version | grep 7.0.8-9 || exit 1 # versions 7.0.8-{15,16} have a bug breaking floodfill
${convert} $< -strip -crop 1251x1251+0+0 -colorspace gray +dither -colors 2 \
-floodfill +600+200 white -floodfill +600+400 white -floodfill +350+900 white \
-floodfill +400+200 black -floodfill +777+117 black\
$@
# Extract the logo part from the banner, invert to keep only the dragon
Misc/dragon.png: Misc/wireguard.png | ${convert}
${convert} --version | grep 7.0.8-9 || exit 1 # versions 7.0.8-{15,16} have a bug breaking floodfill
${convert} $< -strip -colorspace gray +dither -colors 2 -crop 1251x1251+0+0\
-floodfill +600+200 black -floodfill +600+400 black -floodfill +350+900 black\
-floodfill +400+200 transparent -floodfill +777+117 transparent \
$@
# Extract the logo part from the banner, but keep the dragon transparent
Misc/silhouette.png: Misc/wireguard.png | ${convert}
${convert} --version | grep 7.0.8-9 || exit 1 # versions 7.0.8-{15,16} have a bug breaking floodfill
${convert} $< -strip -colorspace gray +dither -colors 2 -crop 1251x1251+0+0 \
-floodfill +400+200 black -floodfill +777+117 black\
$@
# Convert SVG wireguard banner to png
Misc/%.png: Misc/%.svg | ${convert}
${convert} -strip -background transparent -density 400 $< $@
# Download the official logo
Misc/wireguard.svg:
curl -s https://www.wireguard.com/img/wireguard.svg > $@
## Setup and maintenance
${convert} ${swiftlint} ${tailor} ${swiftformat}:
brew bundle install --verbose --no-upgrade
# Used to generate less verbose xcodebuild output
${xcpretty}:
gem install --user xcpretty
.PHONY: clean mrproper
# cleanup build artifacts
clean:
rm -rf \
.{fix,check,test}* \
${archive} \
${dist} \
WireGuardStatusbar.{dmg,app} \
WireGuardStatusbar-*.zip \
${tmp}/WireGuardStatusbar-*.app \
DerivedData/
# cleanup most artifacts that could be generated by the Makefile
mrproper: clean
rm -rf \
Misc/{logo,dragon,wireguard,silhouette}.png \
${tmp}/wireguard.png WireGuardStatusbar/Assets.xcassets/*.imageset/ \
WireGuardStatusbar/Assets.xcassets/*/*.png
sudo rm -rf /etc/wireguard/test-localhost.conf