]>
Commit | Line | Data |
---|---|---|
1 | # Cycript - The Truly Universal Scripting Language | |
2 | # Copyright (C) 2009-2016 Jay Freeman (saurik) | |
3 | ||
4 | # GNU Affero General Public License, Version 3 {{{ | |
5 | # | |
6 | # This program is free software: you can redistribute it and/or modify | |
7 | # it under the terms of the GNU Affero General Public License as published by | |
8 | # the Free Software Foundation, either version 3 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # This program is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | # GNU Affero General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU Affero General Public License | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | # }}} | |
19 | ||
20 | .SECONDARY: | |
21 | .DELETE_ON_ERROR: | |
22 | SHELL := /bin/bash | |
23 | ||
24 | include codesign.mk | |
25 | ||
26 | lipo := $(shell xcrun --sdk iphoneos -f lipo) | |
27 | ||
28 | monotonic := $(shell git log -1 --pretty=format:%ct) | |
29 | version := $(shell git describe --always --tags --dirty="+" --match="v*" | sed -e 's@-\([^-]*\)-\([^-]*\)$$@+\1.\2@;s@^v@@;s@%@~@g') | |
30 | ||
31 | deb := cycript_$(version)_iphoneos-arm.deb | |
32 | zip := cycript_$(version).zip | |
33 | ||
34 | cycript := | |
35 | cycript += Cycript.lib/cycript | |
36 | cycript += Cycript.lib/cycript0.9 | |
37 | cycript += Cycript.lib/libcycript.dylib | |
38 | cycript += Cycript.lib/libcycript-sys.dylib | |
39 | cycript += Cycript.lib/libcycript-sim.dylib | |
40 | cycript += Cycript.lib/libcycript.cy | |
41 | cycript += Cycript.lib/libcycript.db | |
42 | cycript += Cycript.lib/libcycript.jar | |
43 | ||
44 | framework := | |
45 | framework += Cycript | |
46 | framework += Headers/Cycript.h | |
47 | ||
48 | framework := $(foreach os,ios osx,$(foreach file,$(framework),Cycript.$(os)/Cycript.framework/$(file))) | |
49 | ||
50 | links := | |
51 | links += Cycript.lib/cynject | |
52 | links += Cycript.lib/libsubstrate.dylib | |
53 | links += Cycript.lib/cycript0.9 | |
54 | ||
55 | all := cycript $(cycript) $(framework) | |
56 | all: $(all) | |
57 | ||
58 | $(zip): $(all) | |
59 | rm -f $@ | |
60 | zip -r9y $@ cycript Cycript.lib Cycript.{ios,osx} $(patsubst %,--exclude %,$(links)) | |
61 | zip -r9 $@ $(links) | |
62 | ||
63 | zip: $(zip) | |
64 | ln -sf $< cycript.zip | |
65 | ||
66 | $(deb): Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript.db | |
67 | rm -rf package | |
68 | mkdir -p package/DEBIAN | |
69 | sed -e 's/#/$(version)/' control.in >package/DEBIAN/control | |
70 | mkdir -p package/usr/{bin,lib} | |
71 | cp -a modules package/usr/lib/cycript0.9 | |
72 | $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript | |
73 | $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib | |
74 | ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib | |
75 | cp -a libcycript.cy package/usr/lib/libcycript.cy | |
76 | cp -a Cycript.lib/libcycript.db package/usr/lib/libcycript.db | |
77 | sqlite3 package/usr/lib/libcycript.db "delete from cache where system & $$(($$(cat build.ios-arm{v6,64}/Makefile | sed -e '/^CY_SYSTEM = \([0-9]*\)$$/{s//\1/;p;};d;' | tr $$'\n' '|') 0)) == 0; vacuum full;" | |
78 | ./dpkg-deb.sh -Zlzma -b package $@ | |
79 | ||
80 | deb: $(deb) | |
81 | ln -sf $< cycript.deb | |
82 | ||
83 | clean := | |
84 | ||
85 | db := | |
86 | ||
87 | library := libffi libuv | |
88 | ||
89 | # make stubbornly refuses to believe that these @'s are bugs | |
90 | # http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html | |
91 | ||
92 | define build_lar | |
93 | Cycript.lib/$(1).a: $(1).$(2)/.libs/$(1).a | |
94 | endef | |
95 | ||
96 | define build_any | |
97 | .PHONY: build-$(1)-$(2) | |
98 | build-$(1)-$(2): | |
99 | $$(MAKE) -C build.$(1)-$(2) | |
100 | build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2) | |
101 | @ | |
102 | clean-$(1)-$(2): | |
103 | $$(MAKE) -C build.$(1)-$(2) clean | |
104 | clean += clean-$(1)-$(2) | |
105 | db += build.$(1)-$(2)/libcycript.db | |
106 | build.$(1)-$(2)/libcycript.db: build-$(1)-$(2) | |
107 | @ | |
108 | ifneq ($(1),sim) | |
109 | $(foreach lib,$(library), | |
110 | $(call build_lar,$(lib),$(2)) | |
111 | ) | |
112 | endif | |
113 | endef | |
114 | ||
115 | define build_lib | |
116 | build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2) | |
117 | @ | |
118 | endef | |
119 | ||
120 | define build_osx | |
121 | $(call build_any,osx,$(1)) | |
122 | $(call build_lib,osx,$(1)) | |
123 | build.osx-$(1)/.libs/cycript: build-osx-$(1) | |
124 | @ | |
125 | build.osx-$(1)/libcycript.jar: build-osx-$(1) | |
126 | @ | |
127 | endef | |
128 | ||
129 | $(foreach arch,i386 x86_64,$(eval $(call build_osx,$(arch)))) | |
130 | ||
131 | define build_ios | |
132 | $(call build_any,ios,$(1)) | |
133 | endef | |
134 | ||
135 | $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch)))) | |
136 | ||
137 | define build_sim | |
138 | $(call build_any,sim,$(1)) | |
139 | $(call build_lib,sim,$(1)) | |
140 | endef | |
141 | ||
142 | $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch)))) | |
143 | ||
144 | define build_arm | |
145 | build.ios-$(1)/.libs/cycript: build-ios-$(1) | |
146 | @ | |
147 | endef | |
148 | ||
149 | $(foreach arch,armv6,$(eval $(call build_arm,$(arch)))) | |
150 | ||
151 | define build_arm | |
152 | $(call build_lib,ios,$(1)) | |
153 | endef | |
154 | ||
155 | $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch)))) | |
156 | ||
157 | clean: $(clean) | |
158 | rm -rf cycript Cycript.lib libcycript*.o | |
159 | ||
160 | $(patsubst %,Cycript.lib/%.a,$(library)): | |
161 | @mkdir -p $(dir $@) | |
162 | $(lipo) -create -output $@ $^ | |
163 | ||
164 | Cycript.lib/libcycript.dylib: build.osx-i386/.libs/libcycript.dylib build.osx-x86_64/.libs/libcycript.dylib build.ios-armv6/.libs/libcycript.dylib build.ios-arm64/.libs/libcycript.dylib | |
165 | @mkdir -p $(dir $@) | |
166 | $(lipo) -create -output $@ $^ | |
167 | install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@ | |
168 | codesign -s $(codesign) $@ | |
169 | ||
170 | %_: % | |
171 | @cp -af $< $@ | |
172 | install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@ | |
173 | codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@ | |
174 | ||
175 | Cycript.lib/%: build.osx-i386/.libs/%_ build.osx-x86_64/.libs/%_ build.ios-armv6/.libs/%_ | |
176 | @mkdir -p $(dir $@) | |
177 | $(lipo) -create -output $@ $^ | |
178 | ||
179 | Cycript.lib/libcycript-sys.dylib: | |
180 | @mkdir -p $(dir $@) | |
181 | ln -sf libcycript.dylib $@ | |
182 | ||
183 | Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib | |
184 | @mkdir -p $(dir $@) | |
185 | $(lipo) -create -output $@ $^ | |
186 | codesign -s $(codesign) $@ | |
187 | ||
188 | libcycript-%.o: build.%/.libs/libcycript.a $(patsubst %,Cycript.lib/%.a,$(library)) xcode.map | |
189 | @mkdir -p $(dir $@) | |
190 | ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map -x $(filter %.a,$^) | |
191 | ||
192 | libcycript-ios.o: libcycript-ios-armv6.o libcycript-ios-armv7.o libcycript-ios-armv7s.o libcycript-ios-arm64.o libcycript-sim-i386.o libcycript-sim-x86_64.o | |
193 | $(lipo) -create -output $@ $^ | |
194 | ||
195 | libcycript-osx.o: libcycript-osx-i386.o libcycript-osx-x86_64.o | |
196 | $(lipo) -create -output $@ $^ | |
197 | ||
198 | Cycript.%/Cycript.framework/Cycript: libcycript-%.o | |
199 | @mkdir -p $(dir $@) | |
200 | cp -a $< $@ | |
201 | ||
202 | Cycript.%/Cycript.framework/Headers/Cycript.h: Cycript.h | |
203 | @mkdir -p $(dir $@) | |
204 | cp -a $< $@ | |
205 | ||
206 | Cycript.lib/libcycript.cy: | |
207 | @mkdir -p $(dir $@) | |
208 | ln -sf ../libcycript.cy $@ | |
209 | ||
210 | Cycript.lib/libcycript.db: $(db) | |
211 | @mkdir -p $(dir $@) | |
212 | ./libcycript.sh 0 $@ | |
213 | ./libcycript.py $@ $^ | |
214 | ||
215 | Cycript.lib/libcycript.jar: build.osx-x86_64/libcycript.jar | |
216 | @mkdir -p $(dir $@) | |
217 | cp -af $< $@ | |
218 | ||
219 | Cycript.lib/cycript0.9: | |
220 | @mkdir -p $(dir $@) | |
221 | ln -s ../modules $@ | |
222 | ||
223 | cycript: cycript.in | |
224 | cp -af $< $@ | |
225 | chmod 755 $@ | |
226 | ||
227 | local := Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-sim.dylib | |
228 | ||
229 | debug: $(local) | |
230 | DYLD_LIBRARY_PATH=Cycript.lib lldb Cycript.lib/cycript | |
231 | ||
232 | install: $(local) | |
233 | sudo cp -af $(filter-out %.dylib,$^) /usr/bin | |
234 | sudo cp -af $(filter %.dylib,$^) /usr/lib | |
235 | ||
236 | ||
237 | cast: $(zip) | |
238 | appcast.sh cycript/mac $(monotonic) $(version) $< "$(CYCRIPT_CHANGES)" | |
239 | ||
240 | .PHONY: all cast clean debug install zip |