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