]> git.saurik.com Git - cycript.git/blob - apple.mk
Disallow void values and support (void) arguments.
[cycript.git] / apple.mk
1 # Cycript - Optimizing JavaScript Compiler/Runtime
2 # Copyright (C) 2009-2015 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
36 cycript += Cycript.lib/cycript0.9
37 cycript += Cycript.lib/libcycript.dylib
38 cycript += Cycript.lib/libcycript-sys.dylib
39 cycript += Cycript.lib/libcycript-sim.dylib
40 cycript += Cycript.lib/libcycript.cy
41
42 framework :=
43 framework += Cycript
44 framework += Headers/Cycript.h
45
46 framework := $(foreach os,ios osx,$(foreach file,$(framework),Cycript.$(os)/Cycript.framework/$(file)))
47
48 links :=
49 links += Cycript.lib/cynject
50 links += Cycript.lib/libsubstrate.dylib
51 links += Cycript.lib/cycript0.9
52
53 all := cycript $(cycript) $(framework)
54 all: $(all)
55
56 $(zip): $(all)
57 rm -f $@
58 zip -r9y $@ cycript Cycript.lib Cycript.{ios,osx} $(patsubst %,--exclude %,$(links))
59 zip -r9 $@ $(links)
60
61 zip: $(zip)
62 ln -sf $< cycript.zip
63
64 $(deb): Cycript.lib/cycript Cycript.lib/libcycript.dylib
65 rm -rf package
66 mkdir -p package/DEBIAN
67 sed -e 's/#/$(version)/' control.in >package/DEBIAN/control
68 mkdir -p package/usr/{bin,lib}
69 cp -a modules package/usr/lib/cycript0.9
70 $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript
71 $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib
72 ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib
73 cp -a libcycript.cy package/usr/lib/libcycript.cy
74 ./dpkg-deb.sh -Zlzma -b package $@
75
76 deb: $(deb)
77 ln -sf $< cycript.deb
78
79 clean :=
80
81 library := libffi libuv
82
83 # make stubbornly refuses to believe that these @'s are bugs
84 # http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html
85
86 define build_lar
87 Cycript.lib/$(1).a: $(1).$(2)/.libs/$(1).a
88 endef
89
90 define build_any
91 .PHONY: build-$(1)-$(2)
92 build-$(1)-$(2):
93 $$(MAKE) -C build.$(1)-$(2)
94 build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2)
95 @
96 clean-$(1)-$(2):
97 $$(MAKE) -C build.$(1)-$(2) clean
98 clean += clean-$(1)-$(2)
99 ifneq ($(1),sim)
100 $(foreach lib,$(library),
101 $(call build_lar,$(lib),$(2))
102 )
103 endif
104 endef
105
106 define build_lib
107 build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2)
108 @
109 endef
110
111 define build_osx
112 $(call build_any,osx,$(1))
113 $(call build_lib,osx,$(1))
114 build.osx-$(1)/.libs/cycript: build-osx-$(1)
115 @
116 endef
117
118 $(foreach arch,i386 x86_64,$(eval $(call build_osx,$(arch))))
119
120 define build_ios
121 $(call build_any,ios,$(1))
122 endef
123
124 $(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch))))
125
126 define build_sim
127 $(call build_any,sim,$(1))
128 $(call build_lib,sim,$(1))
129 endef
130
131 $(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch))))
132
133 define build_arm
134 build.ios-$(1)/.libs/cycript: build-ios-$(1)
135 @
136 endef
137
138 $(foreach arch,armv6,$(eval $(call build_arm,$(arch))))
139
140 define build_arm
141 $(call build_lib,ios,$(1))
142 endef
143
144 $(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch))))
145
146 clean: $(clean)
147 rm -rf cycript Cycript.lib libcycript*.o
148
149 $(patsubst %,Cycript.lib/%.a,$(library)):
150 @mkdir -p $(dir $@)
151 $(lipo) -create -output $@ $^
152
153 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
154 @mkdir -p $(dir $@)
155 $(lipo) -create -output $@ $^
156 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
157 codesign -s $(codesign) $@
158
159 %_: %
160 @cp -af $< $@
161 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
162 codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@
163
164 Cycript.lib/%: build.osx-i386/.libs/%_ build.osx-x86_64/.libs/%_ build.ios-armv6/.libs/%_
165 @mkdir -p $(dir $@)
166 $(lipo) -create -output $@ $^
167
168 Cycript.lib/libcycript-sys.dylib:
169 @mkdir -p $(dir $@)
170 ln -sf libcycript.dylib $@
171
172 Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib
173 @mkdir -p $(dir $@)
174 $(lipo) -create -output $@ $^
175 codesign -s $(codesign) $@
176
177 libcycript-%.o: build.%/.libs/libcycript.a $(patsubst %,Cycript.lib/%.a,$(library)) xcode.map
178 @mkdir -p $(dir $@)
179 ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map -x $(filter %.a,$^)
180
181 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
182 $(lipo) -create -output $@ $^
183
184 libcycript-osx.o: libcycript-osx-i386.o libcycript-osx-x86_64.o
185 $(lipo) -create -output $@ $^
186
187 Cycript.%/Cycript.framework/Cycript: libcycript-%.o
188 @mkdir -p $(dir $@)
189 cp -a $< $@
190
191 Cycript.%/Cycript.framework/Headers/Cycript.h: Cycript.h
192 @mkdir -p $(dir $@)
193 cp -a $< $@
194
195 Cycript.lib/libcycript.cy:
196 @mkdir -p $(dir $@)
197 ln -sf ../libcycript.cy $@
198
199 Cycript.lib/cycript0.9:
200 @mkdir -p $(dir $@)
201 ln -s ../modules $@
202
203 cycript: cycript.in
204 cp -af $< $@
205 chmod 755 $@
206
207 local := Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-sim.dylib
208
209 debug: $(local)
210 DYLD_LIBRARY_PATH=Cycript.lib lldb Cycript.lib/cycript
211
212 install: $(local)
213 sudo cp -af $(filter-out %.dylib,$^) /usr/bin
214 sudo cp -af $(filter %.dylib,$^) /usr/lib
215
216
217 cast: $(zip)
218 appcast.sh cycript/mac $(monotonic) $(version) $< "$(CYCRIPT_CHANGES)"
219
220 .PHONY: all cast clean debug install zip