]>
Commit | Line | Data |
---|---|---|
7341eedb JF |
1 | # Cycript - The Truly Universal Scripting Language |
2 | # Copyright (C) 2009-2016 Jay Freeman (saurik) | |
3370d0c0 | 3 | |
f95d2598 | 4 | # GNU Affero General Public License, Version 3 {{{ |
3370d0c0 | 5 | # |
f95d2598 JF |
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. | |
3370d0c0 | 10 | # |
f95d2598 JF |
11 | # This program is distributed in the hope that it will be useful, |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
3370d0c0 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f95d2598 | 14 | # GNU Affero General Public License for more details. |
3370d0c0 | 15 | # |
f95d2598 JF |
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/>. | |
3370d0c0 JF |
18 | # }}} |
19 | ||
1ed2735b | 20 | .SECONDARY: |
3370d0c0 JF |
21 | .DELETE_ON_ERROR: |
22 | SHELL := /bin/bash | |
23 | ||
cd0c51c7 JF |
24 | include codesign.mk |
25 | ||
e9abea04 JF |
26 | lipo := $(shell xcrun --sdk iphoneos -f lipo) |
27 | ||
bb99d698 | 28 | monotonic := $(shell git log -1 --pretty=format:%ct) |
3615a2f7 | 29 | version := $(shell git describe --always --tags --dirty="+" --match="v*" | sed -e 's@-\([^-]*\)-\([^-]*\)$$@+\1.\2@;s@^v@@;s@%@~@g') |
bb99d698 | 30 | |
3615a2f7 | 31 | deb := cycript_$(version)_iphoneos-arm.deb |
7c3b4d9a | 32 | zip := cycript_$(version).zip |
3615a2f7 | 33 | |
6219596c | 34 | cycript := |
1ed581bb JF |
35 | cycript += Cycript.lib/cycript-apl |
36 | cycript += Cycript.lib/cycript-a32 | |
37 | cycript += Cycript.lib/libcycript.so | |
c22e009d | 38 | cycript += Cycript.lib/cycript0.9 |
fb718684 | 39 | cycript += Cycript.lib/libcycript.dylib |
fb718684 JF |
40 | cycript += Cycript.lib/libcycript-sys.dylib |
41 | cycript += Cycript.lib/libcycript-sim.dylib | |
3f7ac48b | 42 | cycript += Cycript.lib/libcycript.cy |
8d20f0f1 | 43 | cycript += Cycript.lib/libcycript.db |
dbf05bfd | 44 | cycript += Cycript.lib/libcycript.jar |
1ed581bb JF |
45 | cycript += Cycript.lib/libJavaScriptCore.so |
46 | cycript += Cycript.lib/l/linux | |
47 | cycript += Cycript.lib/u/unknown | |
3370d0c0 | 48 | |
7d894647 | 49 | framework := |
5da4d29c JF |
50 | framework += Cycript |
51 | framework += Headers/Cycript.h | |
52 | ||
9d3cfb4a | 53 | framework := $(foreach os,ios osx,$(foreach file,$(framework),Cycript.$(os)/Cycript.framework/$(file))) |
7d894647 | 54 | |
c22e009d | 55 | links := |
7cfc264c | 56 | links += Cycript.lib/cynject |
c22e009d JF |
57 | links += Cycript.lib/libsubstrate.dylib |
58 | links += Cycript.lib/cycript0.9 | |
59 | ||
1ed581bb JF |
60 | data := |
61 | data += Cycript.lib/libcycript.jar | |
62 | data += Cycript.lib/libcycript.db | |
63 | data += Cycript.lib/libcycript.cy | |
64 | ||
65 | local := $(data) | |
66 | local += Cycript.lib/cycript-apl | |
67 | local += Cycript.lib/libcycript.dylib | |
68 | local += Cycript.lib/libcycript-sys.dylib | |
69 | local += Cycript.lib/libcycript-sim.dylib | |
70 | ||
71 | android := $(data) | |
72 | android += Cycript.lib/cycript-a32 | |
73 | android += Cycript.lib/libcycript.so | |
74 | android += Cycript.lib/libJavaScriptCore.so | |
75 | android += Cycript.lib/l/linux | |
76 | android += Cycript.lib/u/unknown | |
77 | ||
bb99d698 JF |
78 | all := cycript $(cycript) $(framework) |
79 | all: $(all) | |
7d894647 | 80 | |
bb99d698 | 81 | $(zip): $(all) |
7d894647 | 82 | rm -f $@ |
9d3cfb4a | 83 | zip -r9y $@ cycript Cycript.lib Cycript.{ios,osx} $(patsubst %,--exclude %,$(links)) |
c22e009d | 84 | zip -r9 $@ $(links) |
7d894647 | 85 | |
7c3b4d9a JF |
86 | zip: $(zip) |
87 | ln -sf $< cycript.zip | |
3370d0c0 | 88 | |
1ed581bb | 89 | $(deb): Cycript.lib/cycript-apl Cycript.lib/libcycript.dylib Cycript.lib/libcycript.db |
3615a2f7 JF |
90 | rm -rf package |
91 | mkdir -p package/DEBIAN | |
92 | sed -e 's/#/$(version)/' control.in >package/DEBIAN/control | |
93 | mkdir -p package/usr/{bin,lib} | |
c22e009d | 94 | cp -a modules package/usr/lib/cycript0.9 |
1ed581bb | 95 | $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript-apl |
fb718684 | 96 | $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib |
3615a2f7 | 97 | ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib |
3f7ac48b | 98 | cp -a libcycript.cy package/usr/lib/libcycript.cy |
8d20f0f1 JF |
99 | cp -a Cycript.lib/libcycript.db package/usr/lib/libcycript.db |
100 | 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;" | |
910c40de | 101 | ./dpkg-deb.sh -Zlzma -b package $@ |
3615a2f7 JF |
102 | |
103 | deb: $(deb) | |
104 | ln -sf $< cycript.deb | |
105 | ||
436b2050 | 106 | clean := |
3370d0c0 | 107 | |
8d20f0f1 JF |
108 | db := |
109 | ||
ae1b611e JF |
110 | library := libffi libuv |
111 | ||
3370d0c0 JF |
112 | # make stubbornly refuses to believe that these @'s are bugs |
113 | # http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html | |
114 | ||
ae1b611e JF |
115 | define build_lar |
116 | Cycript.lib/$(1).a: $(1).$(2)/.libs/$(1).a | |
117 | endef | |
118 | ||
a412fff4 JF |
119 | define build_any |
120 | .PHONY: build-$(1)-$(2) | |
121 | build-$(1)-$(2): | |
511f56b0 | 122 | $$(MAKE) -C build.$(1)-$(2) |
a412fff4 | 123 | build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2) |
3370d0c0 | 124 | @ |
436b2050 JF |
125 | clean-$(1)-$(2): |
126 | $$(MAKE) -C build.$(1)-$(2) clean | |
127 | clean += clean-$(1)-$(2) | |
8d20f0f1 JF |
128 | db += build.$(1)-$(2)/libcycript.db |
129 | build.$(1)-$(2)/libcycript.db: build-$(1)-$(2) | |
130 | @ | |
ae1b611e JF |
131 | ifneq ($(1),sim) |
132 | $(foreach lib,$(library), | |
133 | $(call build_lar,$(lib),$(2)) | |
134 | ) | |
135 | endif | |
a412fff4 JF |
136 | endef |
137 | ||
138 | define build_lib | |
139 | build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2) | |
3370d0c0 | 140 | @ |
a412fff4 JF |
141 | endef |
142 | ||
9d3cfb4a JF |
143 | define build_osx |
144 | $(call build_any,osx,$(1)) | |
145 | $(call build_lib,osx,$(1)) | |
146 | build.osx-$(1)/.libs/cycript: build-osx-$(1) | |
3370d0c0 | 147 | @ |
c9c16dde JF |
148 | build.osx-$(1)/libcycript.jar: build-osx-$(1) |
149 | @ | |
abc804fa | 150 | endef |
3370d0c0 | 151 | |
9d3cfb4a | 152 | $(foreach arch,i386 x86_64,$(eval $(call build_osx,$(arch)))) |
abc804fa JF |
153 | |
154 | define build_ios | |
a412fff4 | 155 | $(call build_any,ios,$(1)) |
abc804fa JF |
156 | endef |
157 | ||
0ad8029f | 158 | $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch)))) |
3370d0c0 | 159 | |
abc804fa | 160 | define build_sim |
a412fff4 JF |
161 | $(call build_any,sim,$(1)) |
162 | $(call build_lib,sim,$(1)) | |
abc804fa JF |
163 | endef |
164 | ||
3615a2f7 | 165 | $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch)))) |
3370d0c0 | 166 | |
1510e2d9 JF |
167 | define build_arm |
168 | build.ios-$(1)/.libs/cycript: build-ios-$(1) | |
169 | @ | |
3615a2f7 JF |
170 | endef |
171 | ||
172 | $(foreach arch,armv6,$(eval $(call build_arm,$(arch)))) | |
173 | ||
174 | define build_arm | |
a412fff4 | 175 | $(call build_lib,ios,$(1)) |
1510e2d9 JF |
176 | endef |
177 | ||
3615a2f7 | 178 | $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch)))) |
1510e2d9 | 179 | |
1ed581bb JF |
180 | define build_and |
181 | .PHONY: build-and-$(1) | |
182 | build-and-$(1): | |
183 | $$(MAKE) -C build.and-$(1) | |
184 | clean-and-$(1): | |
185 | $$(MAKE) -C build.and-$(1) clean | |
186 | clean += clean-and-$(1) | |
187 | db += build.and-$(1)/libcycript.db | |
188 | build.and-$(1)/.libs/cycript: build-and-$(1) | |
189 | @ | |
190 | build.and-$(1)/.libs/libcycript.so: build-and-$(1) | |
191 | @ | |
192 | build.and-$(1)/libcycript.db: build-and-$(1) | |
193 | @ | |
194 | endef | |
195 | ||
196 | $(foreach arch,armeabi,$(eval $(call build_and,$(arch)))) | |
197 | ||
436b2050 JF |
198 | clean: $(clean) |
199 | rm -rf cycript Cycript.lib libcycript*.o | |
200 | ||
ae1b611e JF |
201 | $(patsubst %,Cycript.lib/%.a,$(library)): |
202 | @mkdir -p $(dir $@) | |
203 | $(lipo) -create -output $@ $^ | |
204 | ||
9d3cfb4a | 205 | 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 |
0ad8029f JF |
206 | @mkdir -p $(dir $@) |
207 | $(lipo) -create -output $@ $^ | |
3615a2f7 JF |
208 | install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@ |
209 | codesign -s $(codesign) $@ | |
0ad8029f | 210 | |
1ed581bb JF |
211 | Cycript.lib/libcycript.so: build.and-armeabi/.libs/libcycript.so |
212 | @mkdir -p $(dir $@) | |
213 | cp -af $< $@ | |
214 | ||
215 | Cycript.lib/libJavaScriptCore.so: android/armeabi/libJavaScriptCore.so | |
216 | @mkdir -p $(dir $@) | |
217 | cp -af $< $@ | |
218 | ||
219 | Cycript.lib/%: terminfo/% | |
220 | @mkdir -p $(dir $@) | |
221 | cp -af $< $@ | |
222 | ||
69d4f99a JF |
223 | %_: % |
224 | @cp -af $< $@ | |
3615a2f7 | 225 | install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@ |
69d4f99a JF |
226 | codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@ |
227 | ||
1ed581bb | 228 | Cycript.lib/cycript-apl: build.osx-i386/.libs/cycript_ build.osx-x86_64/.libs/cycript_ build.ios-armv6/.libs/cycript_ |
6219596c | 229 | @mkdir -p $(dir $@) |
e9abea04 | 230 | $(lipo) -create -output $@ $^ |
3370d0c0 | 231 | |
1ed581bb JF |
232 | Cycript.lib/cycript-a32: build.and-armeabi/.libs/cycript |
233 | @mkdir -p $(dir $@) | |
234 | cp -af $< $@ | |
235 | ||
236 | Cycrit.lib/libcycript.so: build.and-armeabi/.libs/libcycript.so | |
237 | @mkdir -p $(dir $@) | |
238 | cp -af $< $@ | |
239 | ||
fb718684 | 240 | Cycript.lib/libcycript-sys.dylib: |
6219596c | 241 | @mkdir -p $(dir $@) |
3370d0c0 JF |
242 | ln -sf libcycript.dylib $@ |
243 | ||
fb718684 | 244 | Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib |
6219596c | 245 | @mkdir -p $(dir $@) |
8ccd2bee | 246 | $(lipo) -create -output $@ $^ |
cd0c51c7 | 247 | codesign -s $(codesign) $@ |
3370d0c0 | 248 | |
ae1b611e | 249 | libcycript-%.o: build.%/.libs/libcycript.a $(patsubst %,Cycript.lib/%.a,$(library)) xcode.map |
6219596c | 250 | @mkdir -p $(dir $@) |
ae1b611e | 251 | ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map -x $(filter %.a,$^) |
3370d0c0 | 252 | |
5da4d29c JF |
253 | 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 |
254 | $(lipo) -create -output $@ $^ | |
255 | ||
9d3cfb4a | 256 | libcycript-osx.o: libcycript-osx-i386.o libcycript-osx-x86_64.o |
e9abea04 | 257 | $(lipo) -create -output $@ $^ |
3370d0c0 | 258 | |
9d3cfb4a | 259 | Cycript.%/Cycript.framework/Cycript: libcycript-%.o |
7d894647 JF |
260 | @mkdir -p $(dir $@) |
261 | cp -a $< $@ | |
262 | ||
9d3cfb4a | 263 | Cycript.%/Cycript.framework/Headers/Cycript.h: Cycript.h |
7d894647 JF |
264 | @mkdir -p $(dir $@) |
265 | cp -a $< $@ | |
266 | ||
3f7ac48b JF |
267 | Cycript.lib/libcycript.cy: |
268 | @mkdir -p $(dir $@) | |
269 | ln -sf ../libcycript.cy $@ | |
270 | ||
8d20f0f1 JF |
271 | Cycript.lib/libcycript.db: $(db) |
272 | @mkdir -p $(dir $@) | |
273 | ./libcycript.sh 0 $@ | |
274 | ./libcycript.py $@ $^ | |
275 | ||
dbf05bfd JF |
276 | Cycript.lib/libcycript.jar: build.osx-x86_64/libcycript.jar |
277 | @mkdir -p $(dir $@) | |
278 | cp -af $< $@ | |
279 | ||
c22e009d JF |
280 | Cycript.lib/cycript0.9: |
281 | @mkdir -p $(dir $@) | |
282 | ln -s ../modules $@ | |
283 | ||
1ed581bb | 284 | cycript: cycript.in |
3370d0c0 JF |
285 | cp -af $< $@ |
286 | chmod 755 $@ | |
287 | ||
558c3305 | 288 | debug: $(local) |
1ed581bb | 289 | DYLD_LIBRARY_PATH=Cycript.lib lldb Cycript.lib/cycript-apl |
558c3305 JF |
290 | |
291 | install: $(local) | |
278e0646 JF |
292 | sudo cp -af $(filter-out %.dylib,$^) /usr/bin |
293 | sudo cp -af $(filter %.dylib,$^) /usr/lib | |
294 | ||
1ed581bb JF |
295 | push: cycript $(android) |
296 | adb push cycript /data/local/tmp/cycript | |
297 | adb shell mkdir -p /data/local/tmp/cycript/Cycript.lib/{l,u} | |
298 | for x in $(android); do adb push $$x /data/local/tmp/$$x; done | |
bb99d698 JF |
299 | |
300 | cast: $(zip) | |
301 | appcast.sh cycript/mac $(monotonic) $(version) $< "$(CYCRIPT_CHANGES)" | |
302 | ||
558c3305 | 303 | .PHONY: all cast clean debug install zip |