-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
276 lines (214 loc) · 8.1 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
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
APP_SIGNING_ID ?= Developer ID Application: Donald McCaughey
INSTALLER_SIGNING_ID ?= Developer ID Installer: Donald McCaughey
NOTARIZATION_KEYCHAIN_PROFILE ?= Donald McCaughey
TMP ?= $(abspath tmp)
version := 5.4.5
revision := 1
archs := arm64 x86_64
rev := $(if $(patsubst 1,,$(revision)),-r$(revision),)
ver := $(version)$(rev)
.SECONDEXPANSION :
.PHONY : signed-package
signed-package : $(TMP)/xz-$(ver)-unnotarized.pkg
.PHONY : notarize
notarize : xz-$(ver).pkg
.PHONY : clean
clean :
-rm -f xz-*.pkg
-rm -rf $(TMP)
.PHONY : check
check :
test "$(shell lipo -archs $(TMP)/install/usr/local/bin/lzmadec)" = "x86_64 arm64"
test "$(shell lipo -archs $(TMP)/install/usr/local/bin/lzmainfo)" = "x86_64 arm64"
test "$(shell lipo -archs $(TMP)/install/usr/local/bin/xz)" = "x86_64 arm64"
test "$(shell lipo -archs $(TMP)/install/usr/local/bin/xzdec)" = "x86_64 arm64"
test "$(shell lipo -archs $(TMP)/install/usr/local/lib/liblzma.a)" = "x86_64 arm64"
test "$(shell lipo -archs $(TMP)/install/usr/local/lib/liblzma.5.dylib)" = "x86_64 arm64"
test "$(shell ./tools/dylibs --no-sys-libs --count $(TMP)/install/usr/local/bin/lzmadec) dylibs" = "0 dylibs"
test "$(shell ./tools/dylibs --no-sys-libs --count $(TMP)/install/usr/local/bin/lzmainfo) dylibs" = "0 dylibs"
test "$(shell ./tools/dylibs --no-sys-libs --count $(TMP)/install/usr/local/bin/xz) dylibs" = "0 dylibs"
test "$(shell ./tools/dylibs --no-sys-libs --count $(TMP)/install/usr/local/bin/xzdec) dylibs" = "0 dylibs"
codesign --verify --strict $(TMP)/install/usr/local/bin/lzmadec
codesign --verify --strict $(TMP)/install/usr/local/bin/lzmainfo
codesign --verify --strict $(TMP)/install/usr/local/bin/xz
codesign --verify --strict $(TMP)/install/usr/local/bin/xzdec
codesign --verify --strict $(TMP)/install/usr/local/lib/liblzma.a
codesign --verify --strict $(TMP)/install/usr/local/lib/liblzma.5.dylib
pkgutil --check-signature xz-$(ver).pkg
spctl --assess --type install xz-$(ver).pkg
xcrun stapler validate xz-$(ver).pkg
##### compilation flags ##########
arch_flags = $(patsubst %,-arch %,$(archs))
CFLAGS += $(arch_flags)
##### dist ##########
dist_sources := $(shell find dist -type f \! -name .DS_Store)
##### build xz and lzmainfo, statically linked ##########
xz_options := --disable-shared
$(TMP)/build_xz/src/xz/xz : $(TMP)/build_xz/config.status $(dist_sources)
cd $(TMP)/build_xz && $(MAKE)
$(TMP)/build_xz/config.status : dist/configure | $(TMP)/build_xz
cd $(TMP)/build_xz && sh $(abspath $<) $(xz_options) CFLAGS='$(CFLAGS)'
$(TMP)/build_xz :
mkdir -p $@
##### build xzdec and lzmadec, optimized for size ##########
dec_options := \
--disable-encoders \
--disable-nls \
--disable-shared \
--disable-threads \
--enable-small
dec_CFLAGS := $(CFLAGS) -Os
$(TMP)/build_decs/src/xzdec/xzdec : $(TMP)/build_decs/config.status $(dist_sources)
cd $(TMP)/build_decs && $(MAKE)
$(TMP)/build_decs/config.status : dist/configure | $(TMP)/build_decs
cd $(TMP)/build_decs && sh $(abspath $<) $(dec_options) CFLAGS='$(dec_CFLAGS)'
$(TMP)/build_decs :
mkdir -p $@
##### build liblzma, static and dynamic ##########
lib_options :=
$(TMP)/build_libs/src/liblzma/.libs/liblzma.a : $(TMP)/build_libs/config.status $(dist_sources)
cd $(TMP)/build_libs && $(MAKE)
$(TMP)/build_libs/config.status : dist/configure | $(TMP)/build_libs
cd $(TMP)/build_libs && sh $(abspath $<) $(lib_options) CFLAGS='$(CFLAGS)'
$(TMP)/build_libs :
mkdir -p $@
##### assemble installed distribution and sign binaries ##########
$(TMP)/installed-and-signed.stamp.txt : \
$(TMP)/build_xz/src/xz/xz \
$(TMP)/build_decs/src/xzdec/xzdec \
$(TMP)/build_libs/src/liblzma/.libs/liblzma.a \
| $(TMP)/install
cd $(TMP)/build_xz && $(MAKE) DESTDIR=$(TMP)/install install
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/bin/xz
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/bin/lzmainfo
cd $(TMP)/build_decs/src/xzdec && $(MAKE) DESTDIR=$(TMP)/install install
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/bin/xzdec
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/bin/lzmadec
cd $(TMP)/build_libs/src/liblzma && $(MAKE) DESTDIR=$(TMP)/install install
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/lib/liblzma.a
xcrun codesign \
--sign "$(APP_SIGNING_ID)" \
--options runtime \
$(TMP)/install/usr/local/lib/liblzma.5.dylib
date > $@
$(TMP)/install :
mkdir -p $@
##### pkg ##########
$(TMP)/xz.pkg : \
$(TMP)/install/usr/local/bin/uninstall-xz
pkgbuild \
--root $(TMP)/install \
--identifier cc.donm.pkg.xz \
--ownership recommended \
--version $(version) \
$@
$(TMP)/install/etc/paths.d/xz.path : \
xz.path \
$(TMP)/installed-and-signed.stamp.txt \
| $$(dir $$@)
cp $< $@
$(TMP)/install/usr/local/bin/uninstall-xz : \
uninstall-xz \
$(TMP)/install/etc/paths.d/xz.path \
| $$(dir $$@)
cp $< $@
cd $(TMP)/install && find . -type f \! -name .DS_STORE | sort >> $@
sed -e 's/^\./rm -f /g' -i '' $@
chmod a+x $@
$(TMP)/install/etc/paths.d \
$(TMP)/install/usr/local/bin :
mkdir -p $@
##### product ##########
arch_list := $(shell printf '%s' "$(archs)" | sed "s/ / and /g")
date := $(shell date '+%Y-%m-%d')
macos:=$(shell \
system_profiler -detailLevel mini SPSoftwareDataType \
| grep 'System Version:' \
| awk -F ' ' '{print $$4}' \
)
xcode:=$(shell \
system_profiler -detailLevel mini SPDeveloperToolsDataType \
| grep 'Version:' \
| awk -F ' ' '{print $$2}' \
)
$(TMP)/xz-$(ver)-unnotarized.pkg : \
$(TMP)/xz.pkg \
$(TMP)/build-report.txt \
$(TMP)/distribution.xml \
$(TMP)/resources/background.png \
$(TMP)/resources/background-darkAqua.png \
$(TMP)/resources/license.html \
$(TMP)/resources/welcome.html
productbuild \
--distribution $(TMP)/distribution.xml \
--resources $(TMP)/resources \
--package-path $(TMP) \
--version v$(version)-r$(revision) \
--sign '$(INSTALLER_SIGNING_ID)' \
$@
$(TMP)/build-report.txt : | $$(dir $$@)
printf 'Build Date: %s\n' "$(date)" > $@
printf 'Software Version: %s\n' "$(version)" >> $@
printf 'Installer Revision: %s\n' "$(revision)" >> $@
printf 'Architectures: %s\n' "$(arch_list)" >> $@
printf 'macOS Version: %s\n' "$(macos)" >> $@
printf 'Xcode Version: %s\n' "$(xcode)" >> $@
printf 'APP_SIGNING_ID: %s\n' "$(APP_SIGNING_ID)" >> $@
printf 'INSTALLER_SIGNING_ID: %s\n' "$(INSTALLER_SIGNING_ID)" >> $@
printf 'NOTARIZATION_KEYCHAIN_PROFILE: %s\n' "$(NOTARIZATION_KEYCHAIN_PROFILE)" >> $@
printf 'TMP directory: %s\n' "$(TMP)" >> $@
printf 'CFLAGS: %s\n' "$(CFLAGS)" >> $@
printf 'Tag: v%s-r%s\n' "$(version)" "$(revision)" >> $@
printf 'Tag Title: XZ Utils %s for macOS rev %s\n' "$(version)" "$(revision)" >> $@
printf 'Tag Message: A signed and notarized universal installer package for XZ Utils %s.\n' "$(version)" >> $@
$(TMP)/distribution.xml \
$(TMP)/resources/welcome.html : $(TMP)/% : % | $$(dir $$@)
sed \
-e 's/{{arch_list}}/$(arch_list)/g' \
-e 's/{{date}}/$(date)/g' \
-e 's/{{macos}}/$(macos)/g' \
-e 's/{{revision}}/$(revision)/g' \
-e 's/{{version}}/$(version)/g' \
-e 's/{{xcode}}/$(xcode)/g' \
$< > $@
$(TMP)/resources/background.png \
$(TMP)/resources/background-darkAqua.png \
$(TMP)/resources/license.html : $(TMP)/% : % | $(TMP)/resources
cp $< $@
$(TMP) \
$(TMP)/resources :
mkdir -p $@
##### notarization ##########
$(TMP)/submit-log.json : $(TMP)/xz-$(ver)-unnotarized.pkg | $$(dir $$@)
xcrun notarytool submit $< \
--keychain-profile "$(NOTARIZATION_KEYCHAIN_PROFILE)" \
--output-format json \
--wait \
> $@
$(TMP)/submission-id.txt : $(TMP)/submit-log.json | $$(dir $$@)
jq --raw-output '.id' < $< > $@
$(TMP)/notarization-log.json : $(TMP)/submission-id.txt | $$(dir $$@)
xcrun notarytool log "$$(<$<)" \
--keychain-profile "$(NOTARIZATION_KEYCHAIN_PROFILE)" \
$@
$(TMP)/notarized.stamp.txt : $(TMP)/notarization-log.json | $$(dir $$@)
test "$$(jq --raw-output '.status' < $<)" = "Accepted"
date > $@
xz-$(ver).pkg : $(TMP)/xz-$(ver)-unnotarized.pkg $(TMP)/notarized.stamp.txt
cp $< $@
xcrun stapler staple $@