Skip to content

Commit

Permalink
Update Makefile to use SPM build
Browse files Browse the repository at this point in the history
This also avoids the incredibly cursed SDK parsing
  • Loading branch information
Samasaur1 committed Dec 5, 2024
1 parent c431f08 commit 69e4b8d
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,15 @@ VERSION = 2
LIBRARY_PREFIX = pam_watchid
LIBRARY_NAME = $(LIBRARY_PREFIX).so
DESTINATION = /usr/local/lib/pam
TARGET = apple-darwin$(shell uname -r)
TARGET = apple-macosx10.15
PAM_FILE_BASE = /etc/pam.d/sudo
PAM_TEXT = auth sufficient $(LIBRARY_NAME)
PAM_TID_TEXT = auth sufficient pam_tid.so

# Determine if the macOS Sequoia SDK or later is available.
DEFINES =
# Due to the different ways in which the CLT and Xcode structure their SDK paths, one of the following will always be an empty string depending on what is configured by xcode-select.
CLT_SDK_MAJOR_VER = $(shell xcrun --sdk macosx --show-sdk-path | xargs readlink -f | xargs basename | sed 's/MacOSX//' | cut -d. -f1)
XCODE_SDK_MAJOR_VER = $(shell xcrun --sdk macosx --show-sdk-path | xargs basename | sed 's/MacOSX//' | cut -d. -f1)
SDK_REQUIRED_MAJOR_VER = 15
ifeq "$(SDK_REQUIRED_MAJOR_VER)" "$(word 1, $(sort $(SDK_REQUIRED_MAJOR_VER) $(XCODE_SDK_MAJOR_VER) $(CLT_SDK_MAJOR_VER)))"
DEFINES += -DSEQUOIASDK
endif

all:
swiftc watchid-pam-extension.swift $(DEFINES) -o $(LIBRARY_PREFIX)_x86_64.so -target x86_64-$(TARGET) -emit-library
swiftc watchid-pam-extension.swift $(DEFINES) -o $(LIBRARY_PREFIX)_arm64.so -target arm64-$(TARGET) -emit-library
lipo -create $(LIBRARY_PREFIX)_arm64.so $(LIBRARY_PREFIX)_x86_64.so -output $(LIBRARY_NAME)
swift build -c release --triple x86_64-$(TARGET)
swift build -c release --triple arm64-$(TARGET)
lipo -create .build/x86_64-apple-macosx/release/libpam-watchid.dylib .build/arm64-apple-macosx/release/libpam-watchid.dylib -output $(LIBRARY_NAME)

install: all
sudo mkdir -p $(DESTINATION)
Expand Down

0 comments on commit 69e4b8d

Please sign in to comment.