Skip to content

Instantly share code, notes, and snippets.

@colejhudson
Last active November 17, 2023 21:10
Show Gist options
  • Save colejhudson/9a16a7ff7dab74dc27567d955b08856d to your computer and use it in GitHub Desktop.
Save colejhudson/9a16a7ff7dab74dc27567d955b08856d to your computer and use it in GitHub Desktop.
A base Makefile for compiling swift targeted for iOS without using XCode
# Adapted from http://vojtastavik.com/2018/10/15/building-ios-app-without-xcode/
SYS_BASE := /usr/local
SYS_LIB := $(SYS_BASE)/lib
SYS_INCLUDE := $(SYS_BASE)/include
ORGANIZATION := # Organization Name
NAME := # App Name
BUNDLE := $(NAME).app
BUNDLE_ID := com.$(ORGANIZATION).$(NAME)
BUNDLE_PLIST := $(BUNDLE)/Info.plist
BUNDLE_BIN := $(LOCAL_BASE)/MacOS
BUNDLE_EXECUTABLE := $(BUNDLE_BIN)/$(NAME)
BUNDLE_STORYBOARDS := $(BUNDLE)/Base.lproj
LOCAL_BASE := .
LOCAL_SRC := $(LOCAL_BASE)/src
LOCAL_BIN := $(LOCAL_BASE)/bin
LOCAL_EXAMPLES := $(LOCAL_BASE)/examples
SIMULATOR := x86_64-apple-ios12.0-simulator
IPHONE := arm64-apple-ios12.0
MACOS := # The default target is for macos, thus it can be left blank
SDK_SIMULATOR := $(shell xcrun --show-sdk-path --sdk iphonesimulator)
SDK_IPHONE := $(shell xcrun --show-sdk-path --sdk iphoneos)
SDK_MACOS := $(shell xcrun --show-sdk-path --sdk macosx)
SDK ?= SDK_SIMULATOR
TARGET ?= SIMULATOR
SC := swiftc
SFLAGS := -sdk $(SDK) -target $(TARGET) -emit-executable
STORYBOARDS := $(LOCAL_SRC)/Base.lproj/
SBC := ibtool
SBFLAGS := --compilation-directory $(BUNDLE_STORYBOARDS)
PLISTC := /usr/libexec/PlistBuddy
PLISTFLAGS := -c "Add :CFBundleExecutable string '$(NAME)'" \
-c "Add :CFBundleIdentifier string '$(BUNDLE_ID)'" \
-c "Add :CFBundleName string '$(NAME)'" \
-c "Add :CFBundleInfoDictionaryVersion real 6.0"
run:
open -a "Simulator.app"
xcrun simctl install booted $(BUNDLE)
xcrun simctl launch booted $(BUNDLE_ID)
build:
mkdir -p $(BUNDLE) $(BUNDLE_BIN) $(BUNDLE_STORYBOARDS)
$(SC) $(SFLAGS) $(LOCAL_SRC)/*.swift -o $(BUNDLE_EXECUTABLE)
ls $(LOCAL_STORYBOARDS)/*.storyboard | xargs -I"{}" -L 1 bash -c "$(SBC) {} $(SBFLAGS)"
cp $(LOCAL_SRC) $(BUNDLE_PLIST)
$(PLISTC) $(PLISTFLAGS) $(BUNDLE_PLIST)
clean:
rm -rf $(BUNDLE) $(LOCAL_BIN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment