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