-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
435 lines (365 loc) · 13.3 KB
/
Copy pathMakefile
File metadata and controls
435 lines (365 loc) · 13.3 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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
#
# supports architectures arm64, x86_64 and bitcode
#
# make - build a fat archive framework using $ARCHS, if $ARCHS is empty all architectures are built (device and simulator)
# \
# make ARCHS=x86_64 |
# > build a thin archive framework with named architecture
# |
# make ARCHS=arm64 /
# make ARCHS='x86_64' - bulid a fat archive framework with only the named architectures
#
# From xcode build script:
# make ARCHS=${ARCHS} - build all active architectures
#
# Xcode bitcode support:
# make ARCHS="arm64" ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=bitcode - create bitcode
# make ARCHS="arm64" ENABLE_BITCODE=YES BITCODE_GENERATION_MODE=marker - add bitcode marker (but no real bitcode)
#
# The ENABLE_BITCODE and BITCODE_GENERATION_MODE flags are set in the Xcode project settings
#
SHELL = /bin/bash
V ?= 0
at = @
ifeq ($(V),1)
at =
endif
MACOS_MIN_VERSION = 10.13
IOS_MIN_VERSION = 11.0
#
# Repository info
#
GITBRANCH ?= $(shell which git > /dev/null && git rev-parse --abbrev-ref --verify -q HEAD || echo "unknown")
GITCOMMIT ?= $(shell which git > /dev/null && git rev-parse --verify -q HEAD || echo "unknown")
#
# library distribution to be built
DIST_NAME = libarchive
DIST_VERSION = 3.8.0
#
# Release version on GitHub - bump last digit to make new
# GitHub release with same distribution version.
NAME = archive
VERSION = 3.8.0-2
#
# Download location URL
#
TARBALL = $(DIST_NAME)-$(DIST_VERSION).tar.gz
DOWNLOAD_URL = http://www.libarchive.org/downloads/$(TARBALL)
#
# Files used to trigger builds for each architecture
# TARGET_BUILD_LIB file under install prefix that can be built directly
# TARGET_NOBUILD_ARTIFACT file under install prefix that is built indirectly
#
INSTALLED_LIB = /lib/libarchive.a
INSTALLED_HEADER_DIR = /include
#
# Output framework name
#
FRAMEWORK_NAME = $(NAME)
#
# The supported Xcode SDKs
#
MACOSX_SDK = macosx
IPHONEOS_SDK = iphoneos
IPHONESIMULATOR_SDK = iphonesimulator
#
# The supported build target os
#
MACOSX_TARGET = apple-darwin
IPHONEOS_TARGET = apple-ios
IPHONESIMULATOR_TARGET = apple-iossim
#
# The supported build target architecture
#
ARM64_TARGET = aarch64
X86_64_TARGET = x86_64
#
# The supported Xcode build architectures
#
ARM_64_ARCH = arm64
X86_64_ARCH = x86_64
#
# SDK platform version
#
IPHONESIMULATOR_SDK_PLATFORM_VERSION = $(shell xcrun --sdk $(IPHONESIMULATOR_SDK) --show-sdk-platform-version)
#
# set or unset warning flags
#
WFLAGS = -Wno-tautological-pointer-compare -Wno-deprecated-declarations
# -g retains DWARF in the static archive members so consumers get full,
# symbolicated stack traces (file/line) and a non-empty dSYM when archiving
# an app that links libarchive. Nothing strips (make install, not
# install-strip; assembly is lipo only), so -g alone is sufficient — the
# autotools equivalent of boost's debug-symbols=on (FleetSafer AB#25 sibling).
EXTRA_CFLAGS = -g
EXTRA_CXXFLAGS = -stdlib=libc++ -std=c++17
EXTRA_CPPFLAGS =
EXTRA_LDFLAGS = -Z -L/usr/lib
EXTRA_CONFIGURE_ARGS = --without-lzma
#
# enable bitcode support
#
ifeq "$(ENABLE_BITCODE)" "YES"
ifeq "$(BITCODE_GENERATION_MODE)" "marker"
XCODE_BITCODE_FLAG = -fembed-bitcode-marker
endif
ifeq "$(BITCODE_GENERATION_MODE)" "bitcode"
XCODE_BITCODE_FLAG = -fembed-bitcode
endif
endif
#
# SDK_NAME, ARCHS and BUILT_PRODUCTS_DIR are set by xcode
# only set them if make is invoked directly
#
# build for device or simulator
ifneq ($(findstring $(IPHONEOS_SDK), $(SDK_NAME)),)
SDK = $(IPHONEOS_SDK)
else ifneq ($(findstring $(IPHONESIMULATOR_SDK), $(SDK_NAME)),)
SDK = $(IPHONESIMULATOR_SDK)
else ifneq ($(findstring $(MACOSX_SDK), $(SDK_NAME)),)
SDK = $(MACOSX_SDK)
else ifneq ($(SDK_NAME),)
SDK = $(SDK_NAME)
else
SDK = $(IPHONEOS_SDK)
endif
# build for device or simulator
ifeq ($(SDK),$(IPHONEOS_SDK))
ARCHS ?= $(ARM_64_ARCH)
#
# set minimum iOS version supported
#
ifneq "$(IPHONEOS_DEPLOYMENT_TARGET)" ""
MIN_OS_VER = $(IPHONEOS_DEPLOYMENT_TARGET)
else
MIN_OS_VER = $(IOS_MIN_VERSION)
endif
else ifeq ($(SDK),$(IPHONESIMULATOR_SDK))
# MacOSX Tahoe removed support for all but one Intel Mac.
# Tahoe shipped with SDK26.1, x86_64 simulator can still be built
# but is no longer supported (discouraged) by Apple. Older SDK's
# will still build it.
ifeq ($(shell expr $(IPHONESIMULATOR_SDK_PLATFORM_VERSION) \>= 26),1)
ARCHS ?= $(ARM_64_ARCH)
else
ARCHS ?= $(ARM_64_ARCH) $(X86_64_ARCH)
endif
#
# set minimum iOS version supported
#
ifneq "$(IPHONEOS_DEPLOYMENT_TARGET)" ""
MIN_OS_VER = $(IPHONEOS_DEPLOYMENT_TARGET)
else
MIN_OS_VER = $(IOS_MIN_VERSION)
endif
else ifeq ($(SDK),$(MACOSX_SDK))
#
# set minimum MacOSX version supported
#
ifneq "$(MACOXS_DEPLOYMENT_TARGET)" ""
MIN_OS_VER = $(MACOSX_DEPLOYMENT_TARGET)
else
MIN_OS_VER = $(MACOS_MIN_VERSION)
endif
ARCHS ?= $(ARM_64_ARCH) $(X86_64_ARCH)
else
$(error unsupported sdk: $(SDK))
endif
BUILT_PRODUCTS_DIR ?= $(CURDIR)/build
MAKER_DIR = $(BUILT_PRODUCTS_DIR)/Maker
MAKER_ARCHIVES_DIR = $(MAKER_DIR)/Archives
MAKER_SOURCES_DIR = $(MAKER_DIR)/Sources
MAKER_BUILD_DIR = $(MAKER_DIR)/Build
MAKER_BUILDROOT_DIR = $(MAKER_DIR)/Buildroot
MAKER_INTERMEDIATE_DIR = $(MAKER_DIR)/Intermediate
PKGSRCDIR = $(MAKER_SOURCES_DIR)/$(DIST_NAME)-$(DIST_VERSION)
FRAMEWORKBUNDLE = $(FRAMEWORK_NAME).framework
XCFRAMEWORKBUNDLE = $(FRAMEWORK_NAME).xcframework
empty:=
space:= $(empty) $(empty)
comma:= ,
.PHONY : \
all \
build \
install \
carthage \
clean \
build-commence \
build-complete \
install-commence i\
nstall-complete \
dirs \
tarball \
configure \
makefiles \
$(addprefix Makefile_$(SDK)_, $(ARCHS)) \
builds \
$(addprefix Build_$(SDK)_, $(ARCHS))
all : build
build : build-commence dirs tarball configure makefiles builds bundle build-complete
install : install-commence dirs tarball configure makefiles builds bundle install-complete
carthage:
carthage build --no-skip-current
carthage archive
clean :
$(RM) -r $(BUILT_PRODUCTS_DIR)
$(RM) -r DerivedData
$(RM) -r Carthage
$(RM) *.xcframework.tar.gz
$(RM) *.xcframework.tar.bz2
$(RM) *.xcframework.tar.zip
$(RM) Info.plist
build-commence :
@echo "Commencing debug build for SDK:$(SDK) ARCHS:\"$(ARCHS)\" framework: $(FRAMEWORK_NAME)"
build-complete :
@echo "Completed debug build for SDK:$(SDK) ARCHS:\"$(ARCHS)\" framework: $(FRAMEWORK_NAME)"
install-commence :
@echo "Commencing release build for SDK:$(SDK) ARCHS:\"$(ARCHS)\" framework: $(FRAMEWORK_NAME)"
install-complete :
@echo "Completed release build for SDK:$(SDK) ARCHS:\"$(ARCHS)\" framework: $(FRAMEWORK_NAME)"
dirs : $(MAKER_ARCHIVES_DIR) $(MAKER_SOURCES_DIR) $(MAKER_BUILD_DIR) $(MAKER_BUILDROOT_DIR) $(MAKER_INTERMEDIATE_DIR)
$(MAKER_ARCHIVES_DIR) $(MAKER_SOURCES_DIR) $(MAKER_BUILD_DIR) $(MAKER_BUILDROOT_DIR) $(MAKER_INTERMEDIATE_DIR) :
@mkdir -p $@
tarball : dirs $(MAKER_ARCHIVES_DIR)/$(TARBALL)
$(MAKER_ARCHIVES_DIR)/$(TARBALL) :
@echo "downloading $(DOWNLOAD_URL)"
$(at)curl -L --retry 10 --retry-delay 12 -s -o $@ $(DOWNLOAD_URL) || { \
$(RM) $@ ; \
exit 1 ; \
}
configure : dirs tarball $(PKGSRCDIR)/configure
$(PKGSRCDIR)/configure :
tar -C $(MAKER_SOURCES_DIR) -xf $(MAKER_ARCHIVES_DIR)/$(TARBALL)
if [ -d patches/$(VERSION) ] ; then \
for p in patches/$(VERSION)/*.patch ; do \
if [ -f $$p ] ; then \
patch -d $(PKGSRCDIR) -p1 < $$p ; \
fi ; \
done ; \
fi
makefiles : dirs tarball configure $(addprefix Makefile_$(SDK)_, $(ARCHS))
builds : dirs tarball configure makefiles $(addprefix Build_$(SDK)_, $(ARCHS))
#
# $1 - sdk (iphoneos or iphonesimulator)
# $2 - xcode architecture (arm64, x86_64)
# $3 - target toolchain os name
# $4 - target toolchain architecture name
#
define configure_template
Makefile_$(1)_$(2) : $(MAKER_BUILD_DIR)/$(1)/$(2) $(MAKER_BUILD_DIR)/$(1)/$(2)/Makefile
$(MAKER_BUILD_DIR)/$(1)/$(2) :
$(at)mkdir -p $$@
$(MAKER_BUILD_DIR)/$(1)/$2/Makefile :
$(at)builddir="$(MAKER_BUILD_DIR)/$(1)/$(2)" ; \
installdir="$(MAKER_BUILDROOT_DIR)/$(1)/$(2)/$(FRAMEWORKBUNDLE)" ; \
cd $$$$builddir && \
$(PKGSRCDIR)/configure \
--prefix=/$$(FRAMEWORKBUNDLE) \
--host=$(4)-$(3) \
--disable-shared \
--disable-bsdcpio \
--disable-bsdtar \
--without-bz2lib \
--without-xml2 \
--without-iconv \
$$(EXTRA_CONFIGURE_ARGS) \
CC='xcrun --sdk $(1) clang -arch $(2)' \
CFLAGS='$(EXTRA_CFLAGS) $(EXTRA_CPPFLAGS) -m$(1)-version-min=$$(MIN_OS_VER) $$(XCODE_BITCODE_FLAG) $$(WFLAGS)' \
CXXFLAGS='$(EXTRA_CXXFLAGS) $(EXTRA_CPPFLAGS) -m$(1)-version-min=$$(MIN_OS_VER) $$(XCODE_BITCODE_FLAG) $$(WFLAGS)' \
LDFLAGS='$(EXTRA_LDFLAGS)' \
CPP='xcrun --sdk $(1) clang -arch $(2) -E' \
AR='xcrun --sdk $(1) ar' \
LD='xcrun --sdk $(1) ld' \
LIPO='xcrun --sdk $(1) lipo' \
OTOOL='xcrun --sdk $(1) otool' \
STRIP='xcrun --sdk $(1) strip' \
NM='xcrun --sdk $(1) nm' \
LIBTOOL='xcrun --sdk $(1) libtool'
Build_$(1)_$(2) : $(MAKER_BUILDROOT_DIR)/$(1)/$(2)/$(FRAMEWORKBUNDLE)$(INSTALLED_LIB)
$(MAKER_BUILDROOT_DIR)/$(1)/$(2)/$(FRAMEWORKBUNDLE)$(INSTALLED_LIB) :
$(at)$(MAKE) -C $(MAKER_BUILD_DIR)/$(1)/$(2) DESTDIR=$(MAKER_BUILDROOT_DIR)/$(1)/$(2) LIBTOOLFLAGS=--no-warn install
endef
$(eval $(call configure_template,$(MACOSX_SDK),$(ARM_64_ARCH),$(MACOSX_TARGET),$(ARM64_TARGET)))
$(eval $(call configure_template,$(MACOSX_SDK),$(X86_64_ARCH),$(MACOSX_TARGET),$(X86_64_TARGET)))
$(eval $(call configure_template,$(IPHONEOS_SDK),$(ARM_64_ARCH),$(IPHONEOS_TARGET),$(ARM64_TARGET)))
$(eval $(call configure_template,$(IPHONESIMULATOR_SDK),$(ARM_64_ARCH),$(IPHONESIMULATOR_TARGET),$(ARM64_TARGET)))
$(eval $(call configure_template,$(IPHONESIMULATOR_SDK),$(X86_64_ARCH),$(IPHONESIMULATOR_TARGET),$(X86_64_TARGET)))
FIRST_ARCH = $(firstword $(ARCHS))
.PHONY : bundle-dirs bundle-headers bundle-rm-fat-library bundle-info
SDK_DIR = $(MAKER_INTERMEDIATE_DIR)/$(SDK)
SDK_FRAMEWORK_DIR = $(SDK_DIR)/$(FRAMEWORKBUNDLE)
bundle : \
bundle-dirs \
bundle-headers \
bundle-rm-fat-library \
$(SDK_FRAMEWORK_DIR)/$(FRAMEWORK_NAME) \
bundle-info \
$(SDK_DIR)/$(FRAMEWORKBUNDLE).zip
FRAMEWORK_DIRS = \
$(SDK_FRAMEWORK_DIR) \
$(SDK_FRAMEWORK_DIR)/Resources \
$(SDK_FRAMEWORK_DIR)/Headers \
$(SDK_FRAMEWORK_DIR)/Documentation \
$(SDK_FRAMEWORK_DIR)/Modules
bundle-dirs : $(FRAMEWORK_DIRS)
$(FRAMEWORK_DIRS) :
@mkdir -p $@
bundle-headers : bundle-dirs
$(at)rsync -r -u $(MAKER_BUILDROOT_DIR)/$(SDK)/$(FIRST_ARCH)/$(FRAMEWORKBUNDLE)$(INSTALLED_HEADER_DIR)/* $(SDK_FRAMEWORK_DIR)/Headers
$(SDK_FRAMEWORK_DIR)/Info.plist :
$(at)cp $(FRAMEWORK_NAME)/Info.plist $@
$(at)/usr/libexec/plistbuddy -c "Set:CFBundleDevelopmentRegion English" $@
$(at)/usr/libexec/plistbuddy -c "Set:CFBundleExecutable $(NAME)" $@
$(at)/usr/libexec/plistbuddy -c "Set:CFBundleName $(FRAMEWORK_NAME)" $@
$(at)/usr/libexec/plistbuddy -c "Set:CFBundleIdentifier com.cogosense.$(NAME)" $@
bundle-info : $(SDK_FRAMEWORK_DIR)/Info.plist
$(at)verCode=$$(git tag -l '[0-9]*\.[0-9]*\.[0-9]' | wc -l) ; \
verStr=$$(git describe --match '[0-9]*\.[0-9]*\.[0-9]' --always) ; \
/usr/libexec/plistbuddy -c "Set:CFBundleShortVersionString $${verStr}" $< ; \
/usr/libexec/plistbuddy -c "Set:CFBundleVersion $${verCode}" $<
$(at)plutil -convert binary1 $<
bundle-rm-fat-library :
$(at)$(RM) $(SDK_FRAMEWORK_DIR)/$(FRAMEWORK_NAME)
$(SDK_FRAMEWORK_DIR)/$(FRAMEWORK_NAME) : $(addprefix $(MAKER_BUILDROOT_DIR)/$(SDK)/, $(addsuffix /$(FRAMEWORKBUNDLE)$(INSTALLED_LIB),$(ARCHS)))
$(at)mkdir -p $(@D)
$(at)xcrun -sdk $(SDK) lipo -create $^ -o $@
$(SDK_DIR)/$(FRAMEWORKBUNDLE).zip : $(SDK_DIR)/$(FRAMEWORKBUNDLE)
@echo "creating $@"
$(at)(cd $(SDK_DIR) && zip -qr $(FRAMEWORKBUNDLE).zip $(FRAMEWORKBUNDLE)) || exit $?
@echo "$(FRAMEWORKBUNDLE) for $(SDK) saved to archive $@"
.PHONY : xcframework
xcframework : $(BUILT_PRODUCTS_DIR)/$(XCFRAMEWORKBUNDLE) $(XCFRAMEWORKBUNDLE).tar.gz $(XCFRAMEWORKBUNDLE).tar.bz2 $(XCFRAMEWORKBUNDLE).zip
$(BUILT_PRODUCTS_DIR)/$(XCFRAMEWORKBUNDLE) : $(wildcard $(MAKER_INTERMEDIATE_DIR)/*/$(FRAMEWORKBUNDLE))
$(at)$(RM) -r $@
$(at)xcodebuild -create-xcframework -output $@ $(addprefix -framework , $^)
$(XCFRAMEWORKBUNDLE).tar.gz : $(BUILT_PRODUCTS_DIR)/$(XCFRAMEWORKBUNDLE)
@echo "creating $@"
$(at)tar -C $(BUILT_PRODUCTS_DIR) -czf $(XCFRAMEWORKBUNDLE).tar.gz $(XCFRAMEWORKBUNDLE)
@echo "$(XCFRAMEWORKBUNDLE) saved to archive $@"
$(XCFRAMEWORKBUNDLE).tar.bz2 : $(BUILT_PRODUCTS_DIR)/$(XCFRAMEWORKBUNDLE)
@echo "creating $@"
$(at)tar -C $(BUILT_PRODUCTS_DIR) -cjf $(XCFRAMEWORKBUNDLE).tar.bz2 $(XCFRAMEWORKBUNDLE)
@echo "$(XCFRAMEWORKBUNDLE) saved to archive $@"
$(XCFRAMEWORKBUNDLE).zip : $(BUILT_PRODUCTS_DIR)/$(XCFRAMEWORKBUNDLE)
@echo "creating $@"
$(at)(cd $(BUILT_PRODUCTS_DIR) && zip -qr ../$(XCFRAMEWORKBUNDLE).zip $(XCFRAMEWORKBUNDLE)) || exit $?
@echo "$(XCFRAMEWORKBUNDLE) saved to archive $@"
.PHONY : release
version :
@echo $(VERSION)
release : notes/RELNOTES-$(VERSION) $(XCFRAMEWORKBUNDLE).tar.gz $(XCFRAMEWORKBUNDLE).tar.bz2 $(XCFRAMEWORKBUNDLE).zip
$(at)if [ $(GITBRANCH) == 'master' ] ; then \
if ! gh release view $(VERSION) > /dev/null 2>&1 ; then \
echo "creating release $(VERSION)" ; \
git tag -am "Release $(NAME) for iOS/MacOS $(VERSION)" $(VERSION) ; \
git push origin HEAD:master --follow-tags ; \
gh release create "$(VERSION)" \
--verify-tag \
--generate-notes \
-F notes/RELNOTES-$(VERSION) \
$(XCFRAMEWORKBUNDLE).tar.gz $(XCFRAMEWORKBUNDLE).tar.bz2 $(XCFRAMEWORKBUNDLE).zip \
$(MAKER_INTERMEDIATE_DIR)/$(IPHONEOS_SDK)/$(FRAMEWORKBUNDLE).zip ; \
else \
echo "warning: $(NAME) $(VERSION) has already been created: skipping release" ; \
fi ; \
fi