From ca69368ba4ba238a227060d6f4406d6235792a96 Mon Sep 17 00:00:00 2001 From: Jertzukka Date: Mon, 1 Jul 2024 23:35:31 +0300 Subject: MacOS: Support CommandLineTools for building (#1371) Full Xcode application which can take up-to 40GB of disk space is not necessary for building VeraCrypt, rather the CommandLineTools for XCode are sufficient which only take few gigabytes. Instead of hardcoding the SDK location, use xcrun --show-sdk-path to support also the CommandLineTools instance. The reason for switching the logic for the XCode version is because the xcodebuild will not report a correct XCode version for the CommandLineTools, thus it can't be relied for whether to use the -Wl,-ld_classic flags. Instead, we can just check the ld version in use in the active developer directory, and see whether we are using dyld (the new) or ld64 (the old). --- README.md | 2 +- src/Makefile | 18 ++++++++---------- src/Readme.txt | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 68afe8ca..21f46ca7 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ it is also available [online](https://www.veracrypt.fr/en/CompilingGuidelineLinu - GNU Make - GNU C++ Compiler 4.0 or compatible -- Apple Xcode (Mac OS X only) +- Apple Xcode or Xcode command line tools (Mac OS X only) - YASM 1.3.0 or newer (Linux only, x86/x64 architecture only) - pkg-config - wxWidgets 3.0 shared library and header files installed or diff --git a/src/Makefile b/src/Makefile index 65d9a4ef..5e3c903c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -294,7 +294,10 @@ ifeq "$(shell uname -s)" "Darwin" #check to see if XCode 3 path exists.Otherwise, use XCode 4 path VC_OSX_SDK_PATH := /Developer/SDKs/MacOSX$(VC_OSX_SDK).sdk ifeq ($(wildcard $(VC_OSX_SDK_PATH)/SDKSettings.plist),) - VC_OSX_SDK_PATH := /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$(VC_OSX_SDK).sdk + VC_OSX_SDK_PATH := $(shell xcrun --sdk macosx$(VC_OSX_SDK) --show-sdk-path) + ifeq ($(VC_OSX_SDK_PATH),) +$(error Specified SDK version was not found, ensure your active developer directory is correct through xcode-select) + endif endif #----- Legacy build if OSX <= 10.8: we build both 32-bit and 64-bit ---- @@ -310,17 +313,12 @@ ifeq "$(shell uname -s)" "Darwin" CXXFLAGS += -std=c++11 C_CXX_FLAGS += -DTC_UNIX -DTC_BSD -DTC_MACOSX -mmacosx-version-min=$(VC_OSX_TARGET) -isysroot $(VC_OSX_SDK_PATH) LFLAGS += -mmacosx-version-min=$(VC_OSX_TARGET) -Wl,-syslibroot $(VC_OSX_SDK_PATH) - #Xcode 15 linker emits a warning "no platform load command found" when linking object files generated by yasm + # Xcode 15 linker emits a warning "no platform load command found" when linking object files generated by yasm # To suppress this warning, we need to use -Wl,-ld_classic flag in order to use the old ld64 linker # https://mjtsai.com/blog/2024/03/15/xcode-15-no-platform-load-command-found/ - # Check Xcode version for using specific linker flag - XCODE_VERSION := $(shell xcodebuild -version 2>/dev/null | grep 'Xcode' | sed -E 's/Xcode ([0-9]+).*/\1/') - ifneq ($(XCODE_VERSION),) - ifeq "$(shell expr $(XCODE_VERSION) \>= 15)" "1" - LFLAGS += -Wl,-ld_classic - endif - else - $(error Xcode not found, please check your installation) + # We can check whether newer linker is in use if ld -v reports dyld instead of ld64. + ifeq ($(shell xcrun --sdk macosx$(VC_OSX_SDK) ld -v 2>&1 | grep -oE 'PROJECT:[^-]+' | cut -d: -f2),dyld) + LFLAGS += -Wl,-ld_classic endif WX_CONFIGURE_FLAGS += --with-macosx-version-min=$(VC_OSX_TARGET) --with-macosx-sdk=$(VC_OSX_SDK_PATH) diff --git a/src/Readme.txt b/src/Readme.txt index 9e6c794f..a20ab4f8 100644 --- a/src/Readme.txt +++ b/src/Readme.txt @@ -101,7 +101,7 @@ Requirements for Building VeraCrypt for Linux and Mac OS X: - GNU Make - GNU C++ Compiler 4.0 or compatible -- Apple Xcode (Mac OS X only) +- Apple Xcode or Xcode command line tools (Mac OS X only) - YASM 1.3.0 or newer (Linux only, x86/x64 architecture only) - pkg-config - wxWidgets 3.0 shared library and header files installed or -- cgit v1.2.3