Skip to content

Instantly share code, notes, and snippets.

@RyanKung
Last active July 21, 2020 10:19
Show Gist options
  • Save RyanKung/4e418f0983eb338ceb87df89b8aa1c4f to your computer and use it in GitHub Desktop.
Save RyanKung/4e418f0983eb338ceb87df89b8aa1c4f to your computer and use it in GitHub Desktop.
Makefile
# ref: https://medium.com/better-programming/writing-ios-apps-without-xcode-89450d0de21a
# MetaData
CLANG = /usr/bin/clang
CLANG_OBF = /usr/local/opt/llvm/bin/clang
PROJECT_NAME = Test
SOURCE_DIR = Test
BUNDLE_DIR = ${PROJECT_NAME}.app
TEMP_DIR = _BuildTemp
# Obj-C Config
TARGET = x86_64-apple-ios13.6-simulator
SDK_PATH= `xcrun --show-sdk-path --sdk iphonesimulator`
FRAMEWORKS=${SDK_PATH}/System/Library/Frameworks
# StoryBoard Config
STORYBOARDS=${SOURCE_DIR}/Base.lproj/*storyboard
STORYBOARD_OUT_DIR=${BUNDLE_DIR}/Base.lproj
# PLIST Config
ORIGINAL_INFO_PLIST=${SOURCE_DIR}/Info.plist
TEMP_INFO_PLIST=${TEMP_DIR}/Info.plist
PROCESSED_INFO_PLIST=${BUNDLE_DIR}/Info.plist
APP_BUNDLE_IDENTIFIER=rk.${PROJECT_NAME}
PLIST_BUDDY=/usr/libexec/PlistBuddy
# Sign Config
TEAM_IDENTIFIER = 7LB2BBJ2SN
IDENTITY=49868FCB1681F28F5758EC62D78E79A97AFB1FFB
XCENT_FILE = ${TEMP_DIR}/${PROJECT_NAME}.xcent
build:
make reset
make bin
make storyb
make plist
make install
reset:
rm -rf ${BUNDLE_DIR}
rm -rf ${TEMP_DIR}
mkdir ${BUNDLE_DIR}
mkdir ${TEMP_DIR}
ir:
for f in $(shell ls ${SOURCE_DIR}/*.m); do \
${CLANG_OBF} -S -isysroot ${SDK_PATH} \
-fobjc-arc -fmodules \
-emit-llvm \
-target ${TARGET} \
$$f \
-o $$f.ll; \
done
for f in $(shell ls ${SOURCE_DIR}/*.ll); do \
llc $$f -filetype=obj -o $${f}.o; \
done
bin:
make ir
${CLANG} -isysroot ${SDK_PATH} \
-fobjc-arc -fmodules \
-target ${TARGET} \
-framework Foundation -framework UIKit \
$(shell ls ${SOURCE_DIR}/*.o) \
-o ${BUNDLE_DIR}/${PROJECT_NAME}
storyb:
mkdir -p ${STORYBOARD_OUT_DIR}
for f in $(shell ls ${STORYBOARDS}); do \
ibtool $${f} --compilation-directory ${STORYBOARD_OUT_DIR}; \
done
plist:
cp ${ORIGINAL_INFO_PLIST} ${TEMP_INFO_PLIST}
${PLIST_BUDDY} -c "Set :CFBundleExecutable ${PROJECT_NAME}" ${TEMP_INFO_PLIST}
${PLIST_BUDDY} -c "Set :CFBundleIdentifier ${APP_BUNDLE_IDENTIFIER}" ${TEMP_INFO_PLIST}
${PLIST_BUDDY} -c "Set :CFBundleName ${PROJECT_NAME}" ${TEMP_INFO_PLIST}
${PLIST_BUDDY} -c "Set :CFBundlePackageType APPL" ${TEMP_INFO_PLIST}
${PLIST_BUDDY} -c "Set :CFBundleDevelopmentRegion en" ${TEMP_INFO_PLIST}
cp ${TEMP_INFO_PLIST} ${PROCESSED_INFO_PLIST}
xcent:
rm -rf ${XCENT_FILE}
${PLIST_BUDDY} -c "Add :application-identifier string ${TEAM_IDENTIFIER}.${APP_BUNDLE_IDENTIFIER}" ${XCENT_FILE}
${PLIST_BUDDY} -c "Add :com.apple.developer.team-identifier string ${TEAM_IDENTIFIER}" ${XCENT_FILE}
sign:
make xcent
codesign \
--force \
--timestamp=none \
--sign ${IDENTITY} \
--keychain ~/Library/Keychains/login.keychain \
--entitlements ${XCENT_FILE} \
${BUNDLE_DIR}
install:
xcrun -v simctl install booted ${BUNDLE_DIR}
xcrun -v simctl launch booted rk.Test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment