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