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