3

Prime Objective: I want a setup where I can compile both with the standard SDK, and with a modified SDK for kernel development by passing the correct SDK into xcodebuild.

When building a MacOS X kernel, the default SDK must be modified. These modifications then can interfere with normal app development.

Apple obviously has a macosx.internal SDK for that purpose (and probably various other purposes). Can I hijack the SDKROOT=macosx.internal setting somehow?

Simply putting a macosx.internal or macosx.internal.sdk folder into $(xcode-select -p)Platforms/MacOSX.platform/Developer/SDKs does not seem to do the trick.

Am I missing something?

below
  • 929
  • 6
  • 26

1 Answers1

0

You might try using xnu-make, a project for building xnu. It serves as a standalone build environment and automatically creates a local copy of the SDK instead of modifying the default one. See the lines below from its Makefile which are used to copy the SDK and create a symlink in Xcode so it can be used:

MACOSX_SDK = MacOSX10.11
...
#make a copy of the current sdk to the build directory and create a symlink in the Xcode SDKs directory
XCODE_SDKS_DIR := $(shell xcrun -sdk macosx --show-sdk-platform-path)/Developer/SDKs
MACOSX_SDK_SRC := $(XCODE_SDKS_DIR)/$(MACOSX_SDK).sdk
MACOSX_SDK_DST := $(CURDIR)/build/sdk/$(MACOSX_SDK)-xnu.sdk
MACOSX_SDK_LNK := $(XCODE_SDKS_DIR)/$(shell basename $(MACOSX_SDK_DST))
MACOSX_SDK_XNU := $(shell echo $(MACOSX_SDK) | tr A-Z a-z)-xnu

sdk:
ifeq ($(shell test -d $(MACOSX_SDK_SRC); echo $$?), 1)
    $(error "The SDK $(MACOSX_SDK) cannot be found, make sure that the latest Xcode version is installed")
endif
    mkdir -p $(MACOSX_SDK_DST)
    cd $(MACOSX_SDK_SRC) && rsync -rtpl . $(MACOSX_SDK_DST)
    plutil -replace CanonicalName -string $(MACOSX_SDK_XNU) $(MACOSX_SDK_DST)/SDKSettings.plist
    rm -f $(MACOSX_SDK_LNK)
    ln -sf $(MACOSX_SDK_DST) $(MACOSX_SDK_LNK)

I updated the Makefile slightly to build MacOSX10.13 and replaced the .gitmodules with newer sources of the xnu code and supporting libraries, but once I did those things, this built the kernel without modifying the local SDK.

You could also simply adapt the lines above into a script for copying the SDK if you don't want to use the xnu-make project.

eckenrod
  • 519
  • 4
  • 17
  • 1
    Thanks! We actually had to modify that script for 10.13.2, and I was able to add a custom internal SDK. I will post instructions after my vacation ;) – below Aug 22 '18 at 17:30
  • 2
    @below Did you return from your vacations yet? ;), it would be pretty helpful to read the instructions! – antonone Nov 04 '20 at 06:58