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