]> git.saurik.com Git - cycript.git/blob - build.mk
Do not allow JavaMethod calls on non-Java objects.
[cycript.git] / build.mk
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-apl
36 cycript += Cycript.lib/cycript-a32
37 cycript += Cycript.lib/libcycript.so
38 cycript += Cycript.lib/cycript0.9
39 cycript += Cycript.lib/libcycript.dylib
40 cycript += Cycript.lib/libcycript-sys.dylib
41 cycript += Cycript.lib/libcycript-sim.dylib
42 cycript += Cycript.lib/libcycript.cy
43 cycript += Cycript.lib/libcycript.db
44 cycript += Cycript.lib/libcycript.jar
45 cycript += Cycript.lib/libJavaScriptCore.so
46 cycript += Cycript.lib/l/linux
47 cycript += Cycript.lib/u/unknown
48
49 framework :=
50 framework += Cycript
51 framework += Headers/Cycript.h
52
53 framework := $(foreach os,ios osx,$(foreach file,$(framework),Cycript.$(os)/Cycript.framework/$(file)))
54
55 links :=
56 links += Cycript.lib/cynject
57 links += Cycript.lib/libsubstrate.dylib
58 links += Cycript.lib/cycript0.9
59
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/cycript-pie
74 android += Cycript.lib/libcycript.so
75 android += Cycript.lib/libJavaScriptCore.so
76 android += Cycript.lib/l/linux
77 android += Cycript.lib/u/unknown
78
79 all := cycript $(cycript) $(framework)
80 all: $(all)
81
82 $(zip): $(all)
83 rm -f $@
84 zip -r9y $@ cycript Cycript.lib Cycript.{ios,osx} $(patsubst %,--exclude %,$(links))
85 zip -r9 $@ $(links)
86
87 zip: $(zip)
88 ln -sf $< cycript.zip
89
90 $(deb): Cycript.lib/cycript-apl Cycript.lib/libcycript.dylib Cycript.lib/libcycript.db
91 rm -rf package
92 mkdir -p package/DEBIAN
93 sed -e 's/#/$(version)/' control.in >package/DEBIAN/control
94 mkdir -p package/usr/{bin,lib}
95 cp -a cycript0.9 package/usr/lib/cycript0.9
96 $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript-apl
97 $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib
98 ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib
99 cp -a libcycript.cy package/usr/lib/libcycript.cy
100 cp -a Cycript.lib/libcycript.db package/usr/lib/libcycript.db
101 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;"
102 ./dpkg-deb.sh -Zlzma -b package $@
103
104 deb: $(deb)
105 ln -sf $< cycript.deb
106
107 clean :=
108
109 db :=
110
111 library := libffi libuv
112
113 # make stubbornly refuses to believe that these @'s are bugs
114 # http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html
115
116 define build_lar
117 Cycript.lib/$(1).a: $(1).$(2)/.libs/$(1).a
118 endef
119
120 define build_any
121 .PHONY: build-$(1)-$(2)
122 build-$(1)-$(2):
123 $$(MAKE) -C build.$(1)-$(2)
124 build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2)
125 @
126 clean-$(1)-$(2):
127 $$(MAKE) -C build.$(1)-$(2) clean
128 clean += clean-$(1)-$(2)
129 db += build.$(1)-$(2)/libcycript.db
130 build.$(1)-$(2)/libcycript.db: build-$(1)-$(2)
131 @
132 ifneq ($(1),sim)
133 $(foreach lib,$(library),
134 $(call build_lar,$(lib),$(2))
135 )
136 endif
137 endef
138
139 define build_lib
140 build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2)
141 @
142 endef
143
144 define build_osx
145 $(call build_any,osx,$(1))
146 $(call build_lib,osx,$(1))
147 build.osx-$(1)/.libs/cycript: build-osx-$(1)
148 @
149 build.osx-$(1)/libcycript.jar: build-osx-$(1)
150 @
151 endef
152
153 $(foreach arch,i386 x86_64,$(eval $(call build_osx,$(arch))))
154
155 define build_ios
156 $(call build_any,ios,$(1))
157 endef
158
159 $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch))))
160
161 define build_sim
162 $(call build_any,sim,$(1))
163 $(call build_lib,sim,$(1))
164 endef
165
166 $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch))))
167
168 define build_arm
169 build.ios-$(1)/.libs/cycript: build-ios-$(1)
170 @
171 endef
172
173 $(foreach arch,armv6,$(eval $(call build_arm,$(arch))))
174
175 define build_arm
176 $(call build_lib,ios,$(1))
177 endef
178
179 $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch))))
180
181 define build_and
182 .PHONY: build-and-$(1)
183 build-and-$(1):
184 $$(MAKE) -C build.and-$(1)
185 clean-and-$(1):
186 $$(MAKE) -C build.and-$(1) clean
187 clean += clean-and-$(1)
188 db += build.and-$(1)/libcycript.db
189 build.and-$(1)/.libs/cycript: build-and-$(1)
190 @
191 build.and-$(1)/cycript-pie: build-and-$(1)
192 @
193 build.and-$(1)/.libs/libcycript.so: build-and-$(1)
194 @
195 build.and-$(1)/libcycript.db: build-and-$(1)
196 @
197 endef
198
199 $(foreach arch,armeabi,$(eval $(call build_and,$(arch))))
200
201 clean: $(clean)
202 rm -rf cycript Cycript.lib libcycript*.o
203
204 $(patsubst %,Cycript.lib/%.a,$(library)):
205 @mkdir -p $(dir $@)
206 $(lipo) -create -output $@ $^
207
208 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
209 @mkdir -p $(dir $@)
210 $(lipo) -create -output $@ $^
211 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
212 codesign -s $(codesign) $@
213
214 Cycript.lib/libcycript.so: build.and-armeabi/.libs/libcycript.so
215 @mkdir -p $(dir $@)
216 cp -af $< $@
217
218 Cycript.lib/libJavaScriptCore.so: android/armeabi/libJavaScriptCore.so
219 @mkdir -p $(dir $@)
220 cp -af $< $@
221
222 Cycript.lib/%: terminfo/%
223 @mkdir -p $(dir $@)
224 cp -af $< $@
225
226 Cycript.lib/cycript-pie: build.and-armeabi/cycript-pie
227 @mkdir -p $(dir $@)
228 cp -af $< $@
229
230 %_: %
231 @cp -af $< $@
232 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
233 codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@
234
235 Cycript.lib/cycript-apl: build.osx-i386/.libs/cycript_ build.osx-x86_64/.libs/cycript_ build.ios-armv6/.libs/cycript_
236 @mkdir -p $(dir $@)
237 $(lipo) -create -output $@ $^
238
239 Cycript.lib/cycript-a32: build.and-armeabi/.libs/cycript
240 @mkdir -p $(dir $@)
241 cp -af $< $@
242
243 Cycrit.lib/libcycript.so: build.and-armeabi/.libs/libcycript.so
244 @mkdir -p $(dir $@)
245 cp -af $< $@
246
247 Cycript.lib/libcycript-sys.dylib:
248 @mkdir -p $(dir $@)
249 ln -sf libcycript.dylib $@
250
251 Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib
252 @mkdir -p $(dir $@)
253 $(lipo) -create -output $@ $^
254 codesign -s $(codesign) $@
255
256 libcycript-%.o: build.%/.libs/libcycript.a $(patsubst %,Cycript.lib/%.a,$(library)) xcode.map
257 @mkdir -p $(dir $@)
258 ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map -x $(filter %.a,$^)
259
260 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
261 $(lipo) -create -output $@ $^
262
263 libcycript-osx.o: libcycript-osx-i386.o libcycript-osx-x86_64.o
264 $(lipo) -create -output $@ $^
265
266 Cycript.%/Cycript.framework/Cycript: libcycript-%.o
267 @mkdir -p $(dir $@)
268 cp -a $< $@
269
270 Cycript.%/Cycript.framework/Headers/Cycript.h: Cycript.h
271 @mkdir -p $(dir $@)
272 cp -a $< $@
273
274 Cycript.lib/libcycript.cy:
275 @mkdir -p $(dir $@)
276 ln -sf ../libcycript.cy $@
277
278 Cycript.lib/libcycript.db: $(db)
279 @mkdir -p $(dir $@)
280 ./libcycript.py 0 $@ $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) $^ </dev/null
281
282 Cycript.lib/libcycript.jar: build.osx-x86_64/libcycript.jar
283 @mkdir -p $(dir $@)
284 cp -af $< $@
285
286 Cycript.lib/cycript0.9:
287 @mkdir -p $(dir $@)
288 ln -sf ../cycript0.9 $@
289
290 cycript: cycript.in
291 cp -af $< $@
292 chmod 755 $@
293
294 debug: $(local)
295 DYLD_LIBRARY_PATH=Cycript.lib lldb Cycript.lib/cycript-apl
296
297 install: $(local)
298 sudo cp -af $(filter-out %.dylib,$^) /usr/bin
299 sudo cp -af $(filter %.dylib,$^) /usr/lib
300
301 push: cycript $(android)
302 adb push cycript /data/local/tmp/cycript
303 adb shell mkdir -p /data/local/tmp/cycript/Cycript.lib/{l,u}
304 for x in $(android); do adb push $$x /data/local/tmp/$$x; done
305
306 cast: $(zip)
307 appcast.sh cycript/mac $(monotonic) $(version) $< "$(CYCRIPT_CHANGES)"
308
309 .PHONY: all cast clean debug install zip