]> git.saurik.com Git - cycript.git/blob - xcode.mk
Avoid infinite recursion while CYONifying objects.
[cycript.git] / xcode.mk
1 # Cycript - Optimizing JavaScript Compiler/Runtime
2 # Copyright (C) 2009-2013 Jay Freeman (saurik)
3
4 # GNU General Public License, Version 3 {{{
5 #
6 # Cycript is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published
8 # by the Free Software Foundation, either version 3 of the License,
9 # or (at your option) any later version.
10 #
11 # Cycript is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Cycript. If not, see <http://www.gnu.org/licenses/>.
18 # }}}
19
20 .DELETE_ON_ERROR:
21 SHELL := /bin/bash
22
23 include codesign.mk
24
25 lipo := $(shell xcrun --sdk iphoneos -f lipo)
26
27 version := $(shell git describe --always --tags --dirty="+" --match="v*" | sed -e 's@-\([^-]*\)-\([^-]*\)$$@+\1.\2@;s@^v@@;s@%@~@g')
28 deb := cycript_$(version)_iphoneos-arm.deb
29
30 cycript :=
31 cycript += Cycript.lib/cycript
32 cycript += Cycript.lib/cycript0.9
33 cycript += Cycript.lib/libcycript.dylib
34 cycript += Cycript.lib/libcycript-any.dylib
35 cycript += Cycript.lib/libcycript-sys.dylib
36 cycript += Cycript.lib/libcycript-sim.dylib
37
38 framework :=
39 framework += Cycript
40 framework += Headers/Cycript.h
41
42 framework := $(foreach os,ios mac,$(foreach file,$(framework),Cycript-$(os).framework/$(file)))
43
44 links :=
45 links += Cycript.lib/libsubstrate.dylib
46 links += Cycript.lib/cycript0.9
47
48 all: cycript $(cycript) $(framework)
49
50 cycript.zip: all
51 rm -f $@
52 zip -r9y $@ cycript Cycript.lib Cycript-{ios,mac}.framework $(patsubst %,--exclude %,$(links))
53 zip -r9 $@ $(links)
54
55 package: cycript.zip
56
57 $(deb): Cycript.lib/cycript Cycript.lib/libcycript.dylib
58 rm -rf package
59 mkdir -p package/DEBIAN
60 sed -e 's/#/$(version)/' control.in >package/DEBIAN/control
61 mkdir -p package/usr/{bin,lib}
62 cp -a modules package/usr/lib/cycript0.9
63 $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript
64 $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib
65 ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib
66 dpkg-deb -Zlzma -b package $@
67
68 deb: $(deb)
69 ln -sf $< cycript.deb
70
71 clean:
72 rm -rf cycript Cycript.lib libcycript*.o
73
74 # make stubbornly refuses to believe that these @'s are bugs
75 # http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html
76
77 define build_any
78 .PHONY: build-$(1)-$(2)
79 build-$(1)-$(2):
80 $(MAKE) -C build.$(1)-$(2)
81 build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2)
82 @
83 endef
84
85 define build_lib
86 build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2)
87 @
88 endef
89
90 define build_mac
91 $(call build_any,mac,$(1))
92 $(call build_lib,mac,$(1))
93 build.mac-$(1)/.libs/cycript: build-mac-$(1)
94 @
95 endef
96
97 $(foreach arch,i386 x86_64,$(eval $(call build_mac,$(arch))))
98
99 define build_ios
100 $(call build_any,ios,$(1))
101 endef
102
103 $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch))))
104
105 define build_sim
106 $(call build_any,sim,$(1))
107 $(call build_lib,sim,$(1))
108 build.sim-$(1)/.libs/libcycript-any.dylib: build-sim-$(1)
109 @
110 endef
111
112 $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch))))
113
114 define build_arm
115 build.ios-$(1)/.libs/cycript: build-ios-$(1)
116 @
117 endef
118
119 $(foreach arch,armv6,$(eval $(call build_arm,$(arch))))
120
121 define build_arm
122 $(call build_lib,ios,$(1))
123 endef
124
125 $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch))))
126
127 Cycript.lib/libcycript-any.dylib: build.sim-i386/.libs/libcycript-any.dylib build.sim-x86_64/.libs/libcycript-any.dylib
128 @mkdir -p $(dir $@)
129 $(lipo) -create -output $@ $^
130 codesign -s $(codesign) $@
131
132 Cycript.lib/libcycript.dylib: build.mac-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib build.ios-armv6/.libs/libcycript.dylib build.ios-arm64/.libs/libcycript.dylib
133 @mkdir -p $(dir $@)
134 $(lipo) -create -output $@ $^
135 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
136 codesign -s $(codesign) $@
137
138 %_: %
139 @cp -af $< $@
140 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
141 codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@
142
143 Cycript.lib/%: build.mac-i386/.libs/%_ build.mac-x86_64/.libs/%_ build.ios-armv6/.libs/%_
144 @mkdir -p $(dir $@)
145 $(lipo) -create -output $@ $^
146
147 Cycript.lib/libcycript-sys.dylib:
148 @mkdir -p $(dir $@)
149 ln -sf libcycript.dylib $@
150
151 Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib
152 @mkdir -p $(dir $@)
153 $(lipo) -create -output $@ $^
154 codesign -s $(codesign) $@
155
156 libcycript-%.o: build.%/.libs/libcycript.a xcode.map
157 @mkdir -p $(dir $@)
158 ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map $< libffi.a
159
160 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
161 $(lipo) -create -output $@ $^
162
163 libcycript-mac.o: libcycript-mac-i386.o libcycript-mac-x86_64.o
164 $(lipo) -create -output $@ $^
165
166 Cycript-%.framework/Cycript: libcycript-%.o
167 @mkdir -p $(dir $@)
168 cp -a $< $@
169
170 Cycript-%.framework/Headers/Cycript.h: Cycript.h
171 @mkdir -p $(dir $@)
172 cp -a $< $@
173
174 Cycript.lib/cycript0.9:
175 @mkdir -p $(dir $@)
176 ln -s ../modules $@
177
178 cycript: cycript.in
179 cp -af $< $@
180 chmod 755 $@
181
182 install: Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-any.dylib Cycript.lib/libcycript-sim.dylib
183 sudo cp -af $(filter-out %.dylib,$^) /usr/bin
184 sudo cp -af $(filter %.dylib,$^) /usr/lib
185
186 .PHONY: all clean install package