]> git.saurik.com Git - cycript.git/blame - apple.mk
Update the copyright year now that 2016 has begun.
[cycript.git] / apple.mk
CommitLineData
7341eedb
JF
1# Cycript - The Truly Universal Scripting Language
2# Copyright (C) 2009-2016 Jay Freeman (saurik)
3370d0c0 3
f95d2598 4# GNU Affero General Public License, Version 3 {{{
3370d0c0 5#
f95d2598
JF
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.
3370d0c0 10#
f95d2598
JF
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
3370d0c0 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f95d2598 14# GNU Affero General Public License for more details.
3370d0c0 15#
f95d2598
JF
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/>.
3370d0c0
JF
18# }}}
19
1ed2735b 20.SECONDARY:
3370d0c0
JF
21.DELETE_ON_ERROR:
22SHELL := /bin/bash
23
cd0c51c7
JF
24include codesign.mk
25
e9abea04
JF
26lipo := $(shell xcrun --sdk iphoneos -f lipo)
27
bb99d698 28monotonic := $(shell git log -1 --pretty=format:%ct)
3615a2f7 29version := $(shell git describe --always --tags --dirty="+" --match="v*" | sed -e 's@-\([^-]*\)-\([^-]*\)$$@+\1.\2@;s@^v@@;s@%@~@g')
bb99d698 30
3615a2f7 31deb := cycript_$(version)_iphoneos-arm.deb
7c3b4d9a 32zip := cycript_$(version).zip
3615a2f7 33
6219596c 34cycript :=
c22e009d
JF
35cycript += Cycript.lib/cycript
36cycript += Cycript.lib/cycript0.9
fb718684 37cycript += Cycript.lib/libcycript.dylib
fb718684
JF
38cycript += Cycript.lib/libcycript-sys.dylib
39cycript += Cycript.lib/libcycript-sim.dylib
3f7ac48b 40cycript += Cycript.lib/libcycript.cy
8d20f0f1 41cycript += Cycript.lib/libcycript.db
dbf05bfd 42cycript += Cycript.lib/libcycript.jar
3370d0c0 43
7d894647 44framework :=
5da4d29c
JF
45framework += Cycript
46framework += Headers/Cycript.h
47
9d3cfb4a 48framework := $(foreach os,ios osx,$(foreach file,$(framework),Cycript.$(os)/Cycript.framework/$(file)))
7d894647 49
c22e009d 50links :=
7cfc264c 51links += Cycript.lib/cynject
c22e009d
JF
52links += Cycript.lib/libsubstrate.dylib
53links += Cycript.lib/cycript0.9
54
bb99d698
JF
55all := cycript $(cycript) $(framework)
56all: $(all)
7d894647 57
bb99d698 58$(zip): $(all)
7d894647 59 rm -f $@
9d3cfb4a 60 zip -r9y $@ cycript Cycript.lib Cycript.{ios,osx} $(patsubst %,--exclude %,$(links))
c22e009d 61 zip -r9 $@ $(links)
7d894647 62
7c3b4d9a
JF
63zip: $(zip)
64 ln -sf $< cycript.zip
3370d0c0 65
8d20f0f1 66$(deb): Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript.db
3615a2f7
JF
67 rm -rf package
68 mkdir -p package/DEBIAN
69 sed -e 's/#/$(version)/' control.in >package/DEBIAN/control
70 mkdir -p package/usr/{bin,lib}
c22e009d
JF
71 cp -a modules package/usr/lib/cycript0.9
72 $(lipo) -extract armv6 -output package/usr/bin/cycript Cycript.lib/cycript
fb718684 73 $(lipo) -extract armv6 -extract arm64 -output package/usr/lib/libcycript.dylib Cycript.lib/libcycript.dylib
3615a2f7 74 ln -s libcycript.dylib package/usr/lib/libcycript.0.dylib
3f7ac48b 75 cp -a libcycript.cy package/usr/lib/libcycript.cy
8d20f0f1
JF
76 cp -a Cycript.lib/libcycript.db package/usr/lib/libcycript.db
77 sqlite3 package/usr/lib/libcycript.db "delete from cache where system & $$(($$(cat build.ios-arm{v6,64}/Makefile | sed -e '/^CY_SYSTEM = \([0-9]*\)$$/{s//\1/;p;};d;' | tr $$'\n' '|') 0)) == 0; vacuum full;"
910c40de 78 ./dpkg-deb.sh -Zlzma -b package $@
3615a2f7
JF
79
80deb: $(deb)
81 ln -sf $< cycript.deb
82
436b2050 83clean :=
3370d0c0 84
8d20f0f1
JF
85db :=
86
ae1b611e
JF
87library := libffi libuv
88
3370d0c0
JF
89# make stubbornly refuses to believe that these @'s are bugs
90# http://osdir.com/ml/help-make-gnu/2012-04/msg00008.html
91
ae1b611e
JF
92define build_lar
93Cycript.lib/$(1).a: $(1).$(2)/.libs/$(1).a
94endef
95
a412fff4
JF
96define build_any
97.PHONY: build-$(1)-$(2)
98build-$(1)-$(2):
511f56b0 99 $$(MAKE) -C build.$(1)-$(2)
a412fff4 100build.$(1)-$(2)/.libs/libcycript.a: build-$(1)-$(2)
3370d0c0 101 @
436b2050
JF
102clean-$(1)-$(2):
103 $$(MAKE) -C build.$(1)-$(2) clean
104clean += clean-$(1)-$(2)
8d20f0f1
JF
105db += build.$(1)-$(2)/libcycript.db
106build.$(1)-$(2)/libcycript.db: build-$(1)-$(2)
107 @
ae1b611e
JF
108ifneq ($(1),sim)
109$(foreach lib,$(library),
110$(call build_lar,$(lib),$(2))
111)
112endif
a412fff4
JF
113endef
114
115define build_lib
116build.$(1)-$(2)/.libs/libcycript.dylib: build-$(1)-$(2)
3370d0c0 117 @
a412fff4
JF
118endef
119
9d3cfb4a
JF
120define build_osx
121$(call build_any,osx,$(1))
122$(call build_lib,osx,$(1))
123build.osx-$(1)/.libs/cycript: build-osx-$(1)
3370d0c0 124 @
c9c16dde
JF
125build.osx-$(1)/libcycript.jar: build-osx-$(1)
126 @
abc804fa 127endef
3370d0c0 128
9d3cfb4a 129$(foreach arch,i386 x86_64,$(eval $(call build_osx,$(arch))))
abc804fa
JF
130
131define build_ios
a412fff4 132$(call build_any,ios,$(1))
abc804fa
JF
133endef
134
0ad8029f 135$(foreach arch,armv6 armv7 armv7s arm64,$(eval $(call build_ios,$(arch))))
3370d0c0 136
abc804fa 137define build_sim
a412fff4
JF
138$(call build_any,sim,$(1))
139$(call build_lib,sim,$(1))
abc804fa
JF
140endef
141
3615a2f7 142$(foreach arch,i386 x86_64,$(eval $(call build_sim,$(arch))))
3370d0c0 143
1510e2d9
JF
144define build_arm
145build.ios-$(1)/.libs/cycript: build-ios-$(1)
146 @
3615a2f7
JF
147endef
148
149$(foreach arch,armv6,$(eval $(call build_arm,$(arch))))
150
151define build_arm
a412fff4 152$(call build_lib,ios,$(1))
1510e2d9
JF
153endef
154
3615a2f7 155$(foreach arch,armv6 arm64,$(eval $(call build_arm,$(arch))))
1510e2d9 156
436b2050
JF
157clean: $(clean)
158 rm -rf cycript Cycript.lib libcycript*.o
159
ae1b611e
JF
160$(patsubst %,Cycript.lib/%.a,$(library)):
161 @mkdir -p $(dir $@)
162 $(lipo) -create -output $@ $^
163
9d3cfb4a 164Cycript.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
0ad8029f
JF
165 @mkdir -p $(dir $@)
166 $(lipo) -create -output $@ $^
3615a2f7
JF
167 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
168 codesign -s $(codesign) $@
0ad8029f 169
69d4f99a
JF
170%_: %
171 @cp -af $< $@
3615a2f7 172 install_name_tool -change /System/Library/{,Private}Frameworks/JavaScriptCore.framework/JavaScriptCore $@
69d4f99a
JF
173 codesign -s $(codesign) --entitlement cycript-$(word 2,$(subst ., ,$(subst -, ,$*))).xml $@
174
9d3cfb4a 175Cycript.lib/%: build.osx-i386/.libs/%_ build.osx-x86_64/.libs/%_ build.ios-armv6/.libs/%_
6219596c 176 @mkdir -p $(dir $@)
e9abea04 177 $(lipo) -create -output $@ $^
3370d0c0 178
fb718684 179Cycript.lib/libcycript-sys.dylib:
6219596c 180 @mkdir -p $(dir $@)
3370d0c0
JF
181 ln -sf libcycript.dylib $@
182
fb718684 183Cycript.lib/libcycript-sim.dylib: build.sim-i386/.libs/libcycript.dylib build.sim-x86_64/.libs/libcycript.dylib
6219596c 184 @mkdir -p $(dir $@)
8ccd2bee 185 $(lipo) -create -output $@ $^
cd0c51c7 186 codesign -s $(codesign) $@
3370d0c0 187
ae1b611e 188libcycript-%.o: build.%/.libs/libcycript.a $(patsubst %,Cycript.lib/%.a,$(library)) xcode.map
6219596c 189 @mkdir -p $(dir $@)
ae1b611e 190 ld -r -arch $$($(lipo) -detailed_info $< | sed -e '/^Non-fat file: / ! d; s/.*: //') -o $@ -all_load -exported_symbols_list xcode.map -x $(filter %.a,$^)
3370d0c0 191
5da4d29c
JF
192libcycript-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
193 $(lipo) -create -output $@ $^
194
9d3cfb4a 195libcycript-osx.o: libcycript-osx-i386.o libcycript-osx-x86_64.o
e9abea04 196 $(lipo) -create -output $@ $^
3370d0c0 197
9d3cfb4a 198Cycript.%/Cycript.framework/Cycript: libcycript-%.o
7d894647
JF
199 @mkdir -p $(dir $@)
200 cp -a $< $@
201
9d3cfb4a 202Cycript.%/Cycript.framework/Headers/Cycript.h: Cycript.h
7d894647
JF
203 @mkdir -p $(dir $@)
204 cp -a $< $@
205
3f7ac48b
JF
206Cycript.lib/libcycript.cy:
207 @mkdir -p $(dir $@)
208 ln -sf ../libcycript.cy $@
209
8d20f0f1
JF
210Cycript.lib/libcycript.db: $(db)
211 @mkdir -p $(dir $@)
212 ./libcycript.sh 0 $@
213 ./libcycript.py $@ $^
214
dbf05bfd
JF
215Cycript.lib/libcycript.jar: build.osx-x86_64/libcycript.jar
216 @mkdir -p $(dir $@)
217 cp -af $< $@
218
c22e009d
JF
219Cycript.lib/cycript0.9:
220 @mkdir -p $(dir $@)
221 ln -s ../modules $@
222
3370d0c0
JF
223cycript: cycript.in
224 cp -af $< $@
225 chmod 755 $@
226
558c3305
JF
227local := Cycript.lib/cycript Cycript.lib/libcycript.dylib Cycript.lib/libcycript-sys.dylib Cycript.lib/libcycript-sim.dylib
228
229debug: $(local)
230 DYLD_LIBRARY_PATH=Cycript.lib lldb Cycript.lib/cycript
231
232install: $(local)
278e0646
JF
233 sudo cp -af $(filter-out %.dylib,$^) /usr/bin
234 sudo cp -af $(filter %.dylib,$^) /usr/lib
235
bb99d698
JF
236
237cast: $(zip)
238 appcast.sh cycript/mac $(monotonic) $(version) $< "$(CYCRIPT_CHANGES)"
239
558c3305 240.PHONY: all cast clean debug install zip