Skip to content

Commit 4c1b9ab

Browse files
committed
Migrated OpenSSL to use XCFramework; added log storage, and more structural cleanup.
1 parent b311960 commit 4c1b9ab

File tree

1 file changed

+81
-52
lines changed

1 file changed

+81
-52
lines changed

Makefile

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,26 @@
55
# - iOS - build everything for iOS
66
# - tvOS - build everything for tvOS
77
# - watchOS - build everything for watchOS
8+
# - OpenSSL - build OpenSSL for all platforms
89
# - OpenSSL-macOS - build OpenSSL for macOS
910
# - OpenSSL-iOS - build OpenSSL for iOS
1011
# - OpenSSL-tvOS - build OpenSSL for tvOS
1112
# - OpenSSL-watchOS - build OpenSSL for watchOS
13+
# - BZip2 - build Bzip2 for all platforms
1214
# - BZip2-macOS - build BZip2 for macOS
1315
# - BZip2-iOS - build BZip2 for iOS
1416
# - BZip2-tvOS - build BZip2 for tvOS
1517
# - BZip2-watchOS - build BZip2 for watchOS
18+
# - XZ - build XZ for all platforms
1619
# - XZ-macOS - build XZ for macOS
1720
# - XZ-iOS - build XZ for iOS
1821
# - XZ-tvOS - build XZ for tvOS
1922
# - XZ-watchOS - build XZ for watchOS
23+
# - libFFI - build libFFI for all platforms (except macOS)
2024
# - libFFI-iOS - build libFFI for iOS
2125
# - libFFI-tvOS - build libFFI for tvOS
2226
# - libFFI-watchOS - build libFFI for watchOS
27+
# - Python - build Python for all platforms
2328
# - Python-macOS - build Python for macOS
2429
# - Python-iOS - build Python for iOS
2530
# - Python-tvOS - build Python for tvOS
@@ -113,8 +118,8 @@ clean-OpenSSL:
113118
@echo ">>> Clean OpenSSL build products"
114119
rm -rf build/*/openssl-$(OPENSSL_VERSION)-* \
115120
build/*/openssl \
116-
build/*/libssl.a build/*/libcrypto.a \
117-
build/*/Support/OpenSSL
121+
build/*/openssl-*.log \
122+
build/*/Support/OpenSSL.xcframework
118123

119124
# Download original OpenSSL source code archive.
120125
downloads/openssl-$(OPENSSL_VERSION).tgz:
@@ -132,6 +137,7 @@ clean-BZip2:
132137
@echo ">>> Clean BZip2 build products"
133138
rm -rf build/*/bzip2-$(BZIP2_VERSION)-* \
134139
build/*/bzip2 \
140+
build/*/bzip2-*.log \
135141
build/*/Support/BZip2.xcframework
136142

137143
# Download original BZip2 source code archive.
@@ -149,6 +155,7 @@ clean-XZ:
149155
@echo ">>> Clean XZ build products"
150156
rm -rf build/*/xz-$(XZ_VERSION)-* \
151157
build/*/xz \
158+
build/*/xz-*.log \
152159
build/*/Support/XZ.xcframework
153160

154161
# Download original XZ source code archive.
@@ -238,15 +245,19 @@ LDFLAGS-$(target)=-arch $$(ARCH-$(target)) -isysroot=$$(SDK_ROOT-$(target))
238245
###########################################################################
239246

240247
OPENSSL_DIR-$(target)=build/$(os)/openssl-$(OPENSSL_VERSION)-$(target)
248+
OPENSSL_SSL_LIB-$(target)=$$(OPENSSL_DIR-$(target))/_install/lib/libssl.a
249+
OPENSSL_CRYPTO_LIB-$(target)=$$(OPENSSL_DIR-$(target))/_install/lib/libcrypto.a
241250

242251
$$(OPENSSL_DIR-$(target))/Makefile: downloads/openssl-$(OPENSSL_VERSION).tgz
243252
@echo ">>> Unpack and configure OpenSSL sources for $(target)"
244253
mkdir -p $$(OPENSSL_DIR-$(target))
245254
tar zxf downloads/openssl-$(OPENSSL_VERSION).tgz --strip-components 1 -C $$(OPENSSL_DIR-$(target))
255+
246256
ifeq ($$(findstring simulator,$$(SDK-$(target))),)
247257
# Tweak ui_openssl.c
248258
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" $$(OPENSSL_DIR-$(target))/crypto/ui/ui_openssl.c
249259
endif
260+
250261
ifeq ($$(findstring iphone,$$(SDK-$(target))),)
251262
# Patch apps/speed.c and apps/ocsp.c to not use fork() since it's not available on tvOS
252263
sed -ie 's/define HAVE_FORK 1/define HAVE_FORK 0/' $$(OPENSSL_DIR-$(target))/apps/speed.c
@@ -258,31 +269,40 @@ endif
258269
# Configure the OpenSSL build
259270
ifeq ($(os),macOS)
260271
cd $$(OPENSSL_DIR-$(target)) && \
261-
CC="$$(CC-$(target))" MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
262-
./Configure darwin64-$$(ARCH-$(target))-cc no-tests --prefix=$(PROJECT_DIR)/build/$(os)/openssl --openssldir=/etc/ssl
272+
CC="$$(CC-$(target))" \
273+
MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
274+
./Configure darwin64-$$(ARCH-$(target))-cc no-tests \
275+
--prefix="$(PROJECT_DIR)/$$(OPENSSL_DIR-$(target))/_install" \
276+
--openssldir=/etc/ssl \
277+
2>&1 | tee ../openssl-$(target).config.log
263278
else
264279
cd $$(OPENSSL_DIR-$(target)) && \
265280
CC="$$(CC-$(target))" \
266281
CROSS_TOP="$$(dir $$(SDK_ROOT-$(target))).." \
267282
CROSS_SDK="$$(notdir $$(SDK_ROOT-$(target)))" \
268-
./Configure iphoneos-cross no-asm no-tests --prefix=$(PROJECT_DIR)/build/$(os)/openssl --openssldir=/etc/ssl
283+
./Configure iphoneos-cross no-asm no-tests \
284+
--prefix="$(PROJECT_DIR)/$$(OPENSSL_DIR-$(target))/_install" \
285+
--openssldir=/etc/ssl \
286+
2>&1 | tee ../openssl-$(target).config.log
287+
269288
endif
270289

271-
$$(OPENSSL_DIR-$(target))/libssl.a $$(OPENSSL_DIR-$(target))/libcrypto.a: $$(OPENSSL_DIR-$(target))/Makefile
290+
$$(OPENSSL_SSL_LIB-$(target)) $$(OPENSSL_CRYPTO_LIB-$(target)): $$(OPENSSL_DIR-$(target))/Makefile
272291
@echo ">>> Build and install OpenSSL for $(target)"
273-
# Make the build; install just the software (not the docs)
292+
# Make and install just the software (not the docs)
274293
cd $$(OPENSSL_DIR-$(target)) && \
275294
CC="$$(CC-$(target))" \
276295
CROSS_TOP="$$(dir $$(SDK_ROOT-$(target))).." \
277296
CROSS_SDK="$$(notdir $$(SDK_ROOT-$(target)))" \
278-
make all && make install_sw
297+
make install_sw \
298+
2>&1 | tee ../openssl-$(target).build.log
279299

280300
###########################################################################
281301
# Target: BZip2
282302
###########################################################################
283303

284304
BZIP2_DIR-$(target)=build/$(os)/bzip2-$(BZIP2_VERSION)-$(target)
285-
BZIP2_LIB-$(target)=build/$(os)/bzip2/$(target)/lib/libbz2.a
305+
BZIP2_LIB-$(target)=$$(BZIP2_DIR-$(target))/_install/lib/libbz2.a
286306

287307
$$(BZIP2_DIR-$(target))/Makefile: downloads/bzip2-$(BZIP2_VERSION).tgz
288308
@echo ">>> Unpack BZip2 sources for $(target)"
@@ -293,34 +313,38 @@ $$(BZIP2_DIR-$(target))/Makefile: downloads/bzip2-$(BZIP2_VERSION).tgz
293313

294314
$$(BZIP2_LIB-$(target)): $$(BZIP2_DIR-$(target))/Makefile
295315
@echo ">>> Build BZip2 for $(target)"
296-
mkdir -p build/$(os)/bzip2/$(target)
297316
cd $$(BZIP2_DIR-$(target)) && \
298317
make install \
299-
PREFIX="$(PROJECT_DIR)/build/$(os)/bzip2/$(target)" \
300-
CC="$$(CC-$(target))"
318+
PREFIX="$(PROJECT_DIR)/$$(BZIP2_DIR-$(target))/_install" \
319+
CC="$$(CC-$(target))" \
320+
2>&1 | tee ../bzip2-$(target).build.log
301321

302322
###########################################################################
303323
# Target: XZ (LZMA)
304324
###########################################################################
305325

306326
XZ_DIR-$(target)=build/$(os)/xz-$(XZ_VERSION)-$(target)
307-
XZ_LIB-$(target)=build/$(os)/xz/$(target)/lib/liblzma.a
327+
XZ_LIB-$(target)=$$(XZ_DIR-$(target))/_install/lib/liblzma.a
308328

309329
$$(XZ_DIR-$(target))/Makefile: downloads/xz-$(XZ_VERSION).tgz
310330
@echo ">>> Unpack XZ sources for $(target)"
311331
mkdir -p $$(XZ_DIR-$(target))
312332
tar zxf downloads/xz-$(XZ_VERSION).tgz --strip-components 1 -C $$(XZ_DIR-$(target))
313333
# Configure the build
314-
cd $$(XZ_DIR-$(target)) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) ./configure \
315-
CC="$$(CC-$(target))" \
316-
LDFLAGS="$$(LDFLAGS-$(target))" \
317-
--disable-shared --enable-static \
318-
--host=$$(MACHINE_SIMPLE-$(target))-apple-darwin \
319-
--prefix=$(PROJECT_DIR)/build/$(os)/xz/$(target)
334+
cd $$(XZ_DIR-$(target)) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) \
335+
./configure \
336+
CC="$$(CC-$(target))" \
337+
LDFLAGS="$$(LDFLAGS-$(target))" \
338+
--disable-shared --enable-static \
339+
--host=$$(MACHINE_SIMPLE-$(target))-apple-darwin \
340+
--prefix="$(PROJECT_DIR)/$$(XZ_DIR-$(target))/_install" \
341+
2>&1 | tee ../xz-$(target).config.log
320342

321343
$$(XZ_LIB-$(target)): $$(XZ_DIR-$(target))/Makefile
322344
@echo ">>> Build and install XZ for $(target)"
323-
cd $$(XZ_DIR-$(target)) && make && make install
345+
cd $$(XZ_DIR-$(target)) && \
346+
make install \
347+
2>&1 | tee ../xz-$(target).build.log
324348

325349
###########################################################################
326350
# Target: libFFI
@@ -370,7 +394,7 @@ $$(PYTHON_DIR-$(target))/Makefile: downloads/Python-$(PYTHON_VERSION).tgz $$(PYT
370394
CC="$$(CC-$(target))" LD="$$(CC-$(target))" \
371395
--host=$$(MACHINE_DETAILED-$(target))-apple-$(shell echo $(os) | tr '[:upper:]' '[:lower:]') \
372396
--build=x86_64-apple-darwin \
373-
--prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$(target))/dist \
397+
--prefix="$(PROJECT_DIR)/$$(PYTHON_DIR-$(target))/dist" \
374398
--without-doc-strings --enable-ipv6 --without-ensurepip \
375399
ac_cv_file__dev_ptmx=no ac_cv_file__dev_ptc=no \
376400
$$(PYTHON_CONFIGURE-$(os))
@@ -392,8 +416,12 @@ vars-$(target):
392416
@echo "CC-$(target): $$(CC-$(target))"
393417
@echo "LIBFFI_BUILD_DIR-$(target): $$(LIBFFI_BUILD_DIR-$(target))"
394418
@echo "OPENSSL_DIR-$(target): $$(OPENSSL_DIR-$(target))"
419+
@echo "OPENSSL_SSL_LIB-$(target): $$(OPENSSL_SSL_LIB-$(target))"
420+
@echo "OPENSSL_CRYPTO_LIB-$(target): $$(OPENSSL_CRYPTO_LIB-$(target))"
395421
@echo "BZIP2_DIR-$(target): $$(BZIP2_DIR-$(target))"
422+
@echo "BZIP2_LIB-$(target): $$(BZIP2_LIB-$(target))"
396423
@echo "XZ_DIR-$(target): $$(XZ_DIR-$(target))"
424+
@echo "XZ_LIB-$(target): $$(XZ_LIB-$(target))"
397425
@echo "LIBFFI_DIR-$(target): $$(LIBFFI_DIR-$(target))"
398426
@echo "PYTHON_DIR-$(target): $$(PYTHON_DIR-$(target))"
399427
@echo "pyconfig.h-$(target): $$(pyconfig.h-$(target))"
@@ -431,6 +459,19 @@ os=$2
431459
SDK_TARGETS-$(sdk)=$$(filter $(sdk).%,$$(TARGETS-$(os)))
432460
SDK_ARCHES-$(sdk)=$$(sort $$(subst .,,$$(suffix $$(SDK_TARGETS-$(sdk)))))
433461

462+
###########################################################################
463+
# SDK: OpenSSL
464+
###########################################################################
465+
466+
OPENSSL_FATLIB-$(sdk)=build/$(os)/openssl/$(sdk)/lib/libopenssl.a
467+
468+
$$(OPENSSL_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(OPENSSL_SSL_LIB-$$(target)) $$(OPENSSL_CRYPTO_LIB-$$(target)))
469+
@echo ">>> Build OpenSSL fat library for $(sdk)"
470+
mkdir -p build/$(os)/openssl/$(sdk)/lib
471+
xcrun --sdk $(sdk) libtool -static -o $$@ $$^
472+
# Copy headers from the first target associated with the SDK
473+
cp -r $$(OPENSSL_DIR-$$(firstword $$(SDK_TARGETS-$(sdk))))/_install/include build/$(os)/openssl/$(sdk)
474+
434475
###########################################################################
435476
# SDK: BZip2
436477
###########################################################################
@@ -442,7 +483,7 @@ $$(BZIP2_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(BZIP2_LIB-$
442483
mkdir -p build/$(os)/bzip2/$(sdk)/lib
443484
xcrun --sdk $(sdk) libtool -static -o $$@ $$^
444485
# Copy headers from the first target associated with the SDK
445-
cp -r build/$(os)/bzip2/$$(firstword $$(SDK_TARGETS-$(sdk)))/include build/$(os)/bzip2/$(sdk)
486+
cp -r $$(BZIP2_DIR-$$(firstword $$(SDK_TARGETS-$(sdk))))/_install/include build/$(os)/bzip2/$(sdk)
446487

447488
###########################################################################
448489
# SDK: XZ (LZMA)
@@ -455,7 +496,7 @@ $$(XZ_FATLIB-$(sdk)): $$(foreach target,$$(SDK_TARGETS-$(sdk)),$$(XZ_LIB-$$(targ
455496
mkdir -p build/$(os)/xz/$(sdk)/lib
456497
xcrun --sdk $(sdk) libtool -static -o $$@ $$^
457498
# Copy headers from the first target associated with the SDK
458-
cp -r build/$(os)/xz/$$(firstword $$(SDK_TARGETS-$(sdk)))/include build/$(os)/xz/$(sdk)
499+
cp -r $$(XZ_DIR-$$(firstword $$(SDK_TARGETS-$(sdk))))/_install/include build/$(os)/xz/$(sdk)
459500

460501
# Dump environment variables (for debugging purposes)
461502
vars-$(sdk):
@@ -492,7 +533,7 @@ clean-$(os):
492533
@echo ">>> Clean $(os) build products"
493534
rm -rf build/$(os)
494535

495-
dist/Python-$(PYTHON_VER)-$(os)-support.$(BUILD_NUMBER).tar.gz: $$(BZIP2_XCFRAMEWORK-$(os)) $$(XZ_XCFRAMEWORK-$(os)) $$(OPENSSL_FRAMEWORK-$(os)) $$(LIBFFI_FRAMEWORK-$(os)) $$(PYTHON_FRAMEWORK-$(os))
536+
dist/Python-$(PYTHON_VER)-$(os)-support.$(BUILD_NUMBER).tar.gz: $$(BZIP2_XCFRAMEWORK-$(os)) $$(XZ_XCFRAMEWORK-$(os)) $$(OPENSSL_XCFRAMEWORK-$(os)) $$(LIBFFI_FRAMEWORK-$(os)) $$(PYTHON_FRAMEWORK-$(os))
496537
@echo ">>> Create final distribution artefact for $(os)"
497538
mkdir -p dist
498539
echo "Python version: $(PYTHON_VERSION) " > build/$(os)/Support/VERSIONS
@@ -516,30 +557,15 @@ endif
516557
# Build: OpenSSL
517558
###########################################################################
518559

519-
OPENSSL_FRAMEWORK-$(os)=build/$(os)/Support/OpenSSL
520-
521-
OpenSSL-$(os): $$(OPENSSL_FRAMEWORK-$(os))
522-
523-
$$(OPENSSL_FRAMEWORK-$(os)): build/$(os)/libssl.a build/$(os)/libcrypto.a
524-
@echo ">>> Create OpenSSL Framework for $(os)"
525-
# Create framework directory structure
526-
mkdir -p $$(OPENSSL_FRAMEWORK-$(os))
527-
528-
# Copy the headers
529-
cp -f -r $$(OPENSSL_DIR-$$(firstword $$(TARGETS-$(os))))/include $$(OPENSSL_FRAMEWORK-$(os))/Headers
530-
531-
# Create the fat library
532-
xcrun libtool -no_warning_for_no_symbols -static \
533-
-o $$(OPENSSL_FRAMEWORK-$(os))/libOpenSSL.a $$^
560+
OPENSSL_XCFRAMEWORK-$(os)=build/$(os)/Support/OpenSSL.xcframework
534561

562+
$$(OPENSSL_XCFRAMEWORK-$(os)): $$(foreach sdk,$$(SDKS-$(os)),$$(OPENSSL_FATLIB-$$(sdk)))
563+
@echo ">>> Create OpenSSL.XCFramework on $(os)"
564+
mkdir -p $$(OPENSSL_XCFRAMEWORK-$(os))
565+
xcodebuild -create-xcframework \
566+
-output $$@ $$(foreach sdk,$$(SDKS-$(os)),-library $$(OPENSSL_FATLIB-$$(sdk)) -headers build/$(os)/openssl/$$(sdk)/include)
535567

536-
build/$(os)/libssl.a: $$(foreach target,$$(TARGETS-$(os)),$$(OPENSSL_DIR-$$(target))/libssl.a)
537-
mkdir -p build/$(os)
538-
xcrun lipo -create -output $$@ $$^
539-
540-
build/$(os)/libcrypto.a: $$(foreach target,$$(TARGETS-$(os)),$$(OPENSSL_DIR-$$(target))/libcrypto.a)
541-
mkdir -p build/$(os)
542-
xcrun lipo -create -output $$@ $$^
568+
OpenSSL-$(os): $$(OPENSSL_XCFRAMEWORK-$(os))
543569

544570
###########################################################################
545571
# Build: BZip2
@@ -634,11 +660,11 @@ $$(PYTHON_DIR-$(os))/Makefile: downloads/Python-$(PYTHON_VERSION).tgz
634660
cat $(PROJECT_DIR)/patch/Python/Setup.embedded $(PROJECT_DIR)/patch/Python/Setup.$(os) > $$(PYTHON_DIR-$(os))/Modules/Setup.local
635661
# Configure target Python
636662
cd $$(PYTHON_DIR-$(os)) && MACOSX_DEPLOYMENT_TARGET=$$(MACOSX_DEPLOYMENT_TARGET) ./configure \
637-
--prefix=$(PROJECT_DIR)/$$(PYTHON_DIR-$(os))/dist \
663+
--prefix="$(PROJECT_DIR)/$$(PYTHON_DIR-$(os))/dist" \
638664
--without-doc-strings --enable-ipv6 --without-ensurepip --enable-universalsdk --with-universal-archs=universal2 \
639665
$$(PYTHON_CONFIGURE-$(os))
640666

641-
$$(PYTHON_DIR-$(os))/dist/lib/libpython$(PYTHON_VER).a: $$(BZIP2_XCFRAMEWORK-$(os)) $$(XZ_XCFRAMEWORK-$(os)) $$(OPENSSL_FRAMEWORK-$(os)) $$(LIBFFI_FRAMEWORK-$(os)) $$(PYTHON_DIR-$(os))/Makefile
667+
$$(PYTHON_DIR-$(os))/dist/lib/libpython$(PYTHON_VER).a: $$(BZIP2_XCFRAMEWORK-$(os)) $$(XZ_XCFRAMEWORK-$(os)) $$(OPENSSL_XCFRAMEWORK-$(os)) $$(LIBFFI_FRAMEWORK-$(os)) $$(PYTHON_DIR-$(os))/Makefile
642668
@echo ">>> Build and install Python for $(os)"
643669
cd $$(PYTHON_DIR-$(os)) && PATH="$(PROJECT_DIR)/$(PYTHON_DIR-$(os))/dist/bin:$(PATH)" make all install
644670

@@ -681,7 +707,7 @@ build/$(os)/libpython$(PYTHON_VER).a: $$(foreach target,$$(PYTHON_TARGETS-$(os))
681707
vars-$(os): $$(foreach target,$$(TARGETS-$(os)),vars-$$(target)) $$(foreach arch,$$(ARCHES-$(os)),vars-$$(arch)) $$(foreach sdk,$$(SDKS-$(os)),vars-$$(sdk))
682708
@echo ">>> Environment variables for $(os)"
683709
@echo "ARCHES-$(os): $$(ARCHES-$(os))"
684-
@echo "OPENSSL_FRAMEWORK-$(os): $$(OPENSSL_FRAMEWORK-$(os))"
710+
@echo "OPENSSL_XCFRAMEWORK-$(os): $$(OPENSSL_XCFRAMEWORK-$(os))"
685711
@echo "BZIP2_XCFRAMEWORK-$(os): $$(BZIP2_XCFRAMEWORK-$(os))"
686712
@echo "XZ_XCFRAMEWORK-$(os): $$(XZ_XCFRAMEWORK-$(os))"
687713
@echo "LIBFFI_FRAMEWORK-$(os): $$(LIBFFI_FRAMEWORK-$(os))"
@@ -696,9 +722,12 @@ endef # build
696722
# Dump environment variables (for debugging purposes)
697723
vars: $(foreach os,$(OS_LIST),vars-$(os))
698724

699-
# Expand the build macro for every OS
700-
$(foreach os,$(OS_LIST),$(eval $(call build,$(os))))
701-
725+
# Expand cross-platform build targets for each library
702726
XZ: $(foreach os,$(OS_LIST),XZ-$(os))
703727
BZip2: $(foreach os,$(OS_LIST),BZip2-$(os))
728+
OpenSSL: $(foreach os,$(OS_LIST),OpenSSL-$(os))
729+
libFFI: $(foreach os,$(OS_LIST),libFFI-$(os))
730+
Python: $(foreach os,$(OS_LIST),Python-$(os))
704731

732+
# Expand the build macro for every OS
733+
$(foreach os,$(OS_LIST),$(eval $(call build,$(os))))

0 commit comments

Comments
 (0)