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