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