-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathMakefile.ios
132 lines (110 loc) · 4.39 KB
/
Makefile.ios
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Makefile fragment for iOS app build
# use ios-deploy to deploy the resulting app
# debugging can be accomplished in Xcode by connecting to running app
# ref: https://vojtastavik.com/2018/10/15/building-ios-app-without-xcode/
# run `xcrun --sdk iphoneos --find clang` to get path to clang
XCODE ?= /Applications/Xcode.app/Contents/Developer
SIM ?= 0
ifneq ($(SIM), 0)
# SIMSDKROOT and SDKROOT can be set in Makefile.local to avoid running xcrun every time
SIMSDKROOT ?= $(shell xcrun --sdk iphonesimulator --show-sdk-path)
SDKROOT = $(SIMSDKROOT)
ARCH = x86_64
# no signing id needed for sim; mobileprovision file also not needed
CODESIGN = /usr/bin/codesign --force --sign - --timestamp=none
XCENT = ios/Sim.app.xcent
else
SDKROOT ?= $(shell xcrun --sdk iphoneos --show-sdk-path)
ARCH = arm64
endif
# := so $(SDKROOT) is only evaluated once
CLANG := $(XCODE)/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch $(ARCH) -isysroot $(SDKROOT) -miphoneos-version-min=11.0
# note that we omit --output-partial-info-plist and assume it will not be needed
IBTOOL = XCODE_DEVELOPER_USR_PATH=$(XCODE)/usr $(XCODE)/usr/bin/ibtool --errors --warnings --notices --auto-activate-custom-fonts --target-device iphone --target-device ipad --minimum-deployment-target 11.0 --output-format human-readable-text
ACTOOL = $(XCODE)/usr/bin/actool --output-format human-readable-text --notices --warnings --app-icon AppIcon --compress-pngs --enable-on-demand-resources YES --development-region en --target-device iphone --target-device ipad --minimum-deployment-target 11.0 --platform iphoneos --product-type com.apple.product-type.application
PLISTBUDDY = /usr/libexec/PlistBuddy
CFLAGS = -MMD -Wall -Wshadow
CXX = $(CLANG)
CXXFLAGS = --std=c++14 -fno-rtti -fno-exceptions -Werror=return-type
CC = $(CLANG) -x c
CCFLAGS = --std=c99
MC = $(CLANG) -x objective-c
MFLAGS = -fobjc-arc
# linker
LD = $(CXX)
LDFLAGS =
DEBUG ?= 1
ifneq ($(SIM), 0)
CFLAGS += -O2 -DNDEBUG
BUILDDIR = SimDebug
else ifneq ($(DEBUG), 0)
CFLAGS += -O0 -g
LDFLAGS += -rdynamic
BUILDDIR = Debug
else
CFLAGS += -O2 -DNDEBUG
BUILDDIR = Release
LDFLAGS += -dead_strip
endif
# project independent stuff
ifneq ($(TOPDIR),)
OBJDIR=$(BUILDDIR)/$(TOPDIR)
else
OBJDIR=$(BUILDDIR)
endif
# include files
INCFLAGS = $(INC:%=-I%) $(INCSYS:%=-isystem%)
# defines
CFLAGS += $(DEFS:%=-D%)
# frameworks
LIBS += $(FRAMEWORKS:%=-framework %)
SRCBASE=$(basename $(SOURCES))
OBJ=$(SRCBASE:%=$(OBJDIR)/%.o)
DEPS=$(SRCBASE:%=$(OBJDIR)/%.d)
TGTDIR=$(BUILDDIR)/$(APPDIR)
TGT=$(TGTDIR)/$(TARGET)
IPA=$(BUILDDIR)/$(TARGET).ipa
# xcent file to be modified
TMPXCENT = $(BUILDDIR)/App.xcent
# interface builder
XIBBASE=$(basename $(XIB))
NIB=$(XIBBASE:%=$(OBJDIR)/%.nib)
# gcc will not create directories, so depend on existence of all directories in output folder
# sort removes duplicates (which cause make error)
BUILDDIRS=$(sort $(dir $(OBJ))) $(TGTDIR)
.PHONY: all ipa clean distclean
all: $(TGT)
ipa: $(IPA)
$(OBJDIR)/%.o: %.cpp
$(CXX) -c $(CFLAGS) $(CXXFLAGS) $(INCFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.c
$(CC) -c $(CFLAGS) $(CCFLAGS) $(INCFLAGS) -o $@ $<
$(OBJDIR)/%.o: %.m
$(MC) -c $(CFLAGS) $(MFLAGS) $(INCFLAGS) -o $@ $<
$(OBJDIR)/%.nib: %.xib
$(IBTOOL) --module $(TARGET) --compile $@ $<
$(TGT): $(OBJ) $(IOSRES) $(NIB) $(XCENT)
$(LD) -o $@ $(OBJ) $(LDFLAGS) $(LIBS)
cp -R $(IOSRES) $(TGTDIR)
test -z $(XCASSETS) || $(ACTOOL) --export-dependency-info $(OBJDIR)/assetcatalog_dependencies --output-partial-info-plist $(OBJDIR)/assetcatalog_info.plist --compile $(TGTDIR) $(XCASSETS)
test -z $(NIB) || cp -R $(NIB) $(TGTDIR)
cp $(PROVISIONING_PROFILE) $(TGTDIR)/embedded.mobileprovision
cp $(XCENT) $(TMPXCENT)
$(PLISTBUDDY) $(TMPXCENT) -c "Set :com.apple.developer.team-identifier $(TEAM_ID)"
$(PLISTBUDDY) $(TMPXCENT) -c "Set :application-identifier $(TEAM_ID).$(BUNDLE_ID)"
$(PLISTBUDDY) $(TMPXCENT) -c "Add :keychain-access-groups: string $(TEAM_ID).$(BUNDLE_ID)"
$(PLISTBUDDY) $(TGTDIR)/Info.plist -c "Set :CFBundleIdentifier $(BUNDLE_ID)"
$(CODESIGN) --entitlements $(TMPXCENT) $(TGTDIR)
$(IPA): $(TGT)
(cd $(BUILDDIR) && zip -rXm $(TARGET).ipa Payload)
# | (pipe) operator causes make to just check for existence instead of timestamp
$(OBJ): | $(BUILDDIRS)
$(BUILDDIRS):
mkdir -p $(BUILDDIRS)
clean:
rm -f $(TGT) $(OBJ) $(DEPS)
rm -r $(TGTDIR)
distclean:
rm -rf ./Debug ./Release
# dependency files generated by gcc (-MMD switch) ("-include" ignores file if missing)
-include $(DEPS)