]> git.saurik.com Git - cycript.git/blame - makefile
Added a stupid hack because Apple sucks at SDKs.
[cycript.git] / makefile
CommitLineData
f37e3501 1SHELL := $(shell which bash 2>/dev/null)
be4442da 2
ea2d184c
JF
3ifndef PKG_TARG
4target :=
5else
6target := $(PKG_TARG)-
7endif
8
a4dbf05b 9gcc := g++
aabea98c
JF
10flags ?= -g3 -O0 -DYYDEBUG=1
11
e0625f37 12paths := $(foreach path,$(paths),$(wildcard $(path)))
aabea98c 13flags += $(foreach path,$(paths),-I$(path) -L$(path))
eacba955 14objc :=
ea2d184c 15
9e20b0b7 16svn := $(shell svnversion)
9e20b0b7 17
1e7ce557 18all:
9cad30fa 19all := cycript
1e7ce557 20
bb9f5eef 21dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null)
1e7ce557 22ifneq ($(dpkg_architecture),)
bb9f5eef 23arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null)
1e7ce557
JF
24endif
25
6a981250 26header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
9cad30fa
JF
27
28code :=
9185d5ef
JF
29code += Replace.o Output.o
30code += Cycript.tab.o lex.cy.o
31code += Network.o Parser.o
cbaa5f0f 32code += JavaScriptCore.o Library.o
1e7ce557 33
b6961e53
JF
34inject :=
35
9cad30fa 36filters := #E4X
82149e4b 37ldid := true
b6961e53 38entitle := $(ldid)
4e869640 39lib := lib
1e7ce557 40dll := so
107e5814 41apr := $(shell apr-1-config --link-ld)
4e869640 42library := $(apr)
dfa452c2 43console := $(apr) -lreadline
f37e3501 44depends :=
1e7ce557 45
fb81b01c
JF
46restart ?= $(MAKE)
47uname_s ?= $(shell uname -s)
48uname_p ?= $(shell uname -p)
4c2a7d11 49uname_m ?= $(shell uname -m)
e0625f37 50
1e7ce557
JF
51-include $(uname_s).mk
52-include $(uname_s)-$(uname_p).mk
4c2a7d11
JF
53-include $(uname_s)-$(uname_m).mk
54
55ifneq ($(shell pkg-config libffi --modversion 2>/dev/null),)
56flags += $(shell pkg-config --cflags libffi)
57endif
1e7ce557 58
9cad30fa 59ifdef CY_EXECUTE
993f82f8
JF
60ifeq ($(filter ObjectiveC,$(filters)),)
61ifneq ($(shell which gnustep-config 2>/dev/null),)
ba4fa42f 62include GNUstep.mk
993f82f8
JF
63endif
64endif
9cad30fa 65endif
993f82f8 66
82149e4b 67flags += -Wall -Werror -Wno-parentheses #-Wno-unused
4e869640 68flags += -fno-common
7c6c5b0a 69flags += -I. -Iinclude -I$(shell apr-1-config --includedir)
cbaa5f0f 70
4e869640 71all += $(lib)cycript.$(dll)
f7c38a29 72
be36c292
JF
73filters += $(shell bison <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
74
1e7ce557 75ifdef arch
b5dd57dc 76deb := $(shell grep ^Package: control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: control.in | cut -d ' ' -f 2 | sed -e 's/\#/$(svn)/')_$(arch).deb
1e7ce557 77
d3c59903 78all:
1e7ce557 79
9cad30fa 80extra::
f37e3501 81
65cf734f 82ifeq ($(depends)$(dll),dylib)
4e869640 83control.tmp: control.in cycript $(lib)cycript.dylib
65cf734f
JF
84 sed -e 's/&/'"$$(dpkg-query -S $$(otool -lah cycript *.dylib | grep dylib | grep -v ':$$' | sed -e 's/^ *name //;s/ (offset [0-9]*)$$//' | sort -u) 2>/dev/null | sed -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
85else
86ifeq ($(depends)$(dll),so)
4e869640
JF
87control.tmp: control.in cycript $(lib)cycript.so
88 sed -e 's/&/'"$$(dpkg-query -S $$(ldd cycript $(lib)cycript.so | sed -e '/:$$/ d; s/^[ \t]*\([^ ]* => \)\?\([^ ]*\) .*/\2/' | sort -u) 2>/dev/null | sed -e 's/:.*//; /^cycript$$/ d; s/$$/,/' | sort -u | tr '\n' ' ')"'/;s/, $$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
b5dd57dc 89else
afe00096 90control.tmp: control.in
b5dd57dc
JF
91 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
92endif
65cf734f 93endif
b5dd57dc 94
afe00096 95control: control.tmp
f7720478 96 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
afe00096 97
b5dd57dc 98$(deb): $(all) control
1e7ce557
JF
99 rm -rf package
100 mkdir -p package/DEBIAN
7c6c5b0a 101 cp -pR control package/DEBIAN
1e7ce557 102 mkdir -p package/usr/{bin,lib,sbin}
9cad30fa 103 $(restart) extra
4e869640 104 cp -pR $(lib)cycript.$(dll) package/usr/lib
7c6c5b0a
JF
105 cp -pR cycript package/usr/bin
106 #cp -pR cyrver package/usr/sbin
1e7ce557
JF
107 dpkg-deb -b package $(deb)
108endif
9b5527f0 109
8953777c 110all: $(all)
ea2d184c
JF
111
112clean:
4e869640 113 rm -f *.o $(lib)cycript.$(dll) $(all) Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.yy Cycript.l control Bridge.hpp
88c977fa 114
4e869640 115%.yy: %.yy.in
cb02f8ae
JF
116 ./Filter.sh <$< >$@ $(filters)
117
118%.l: %.l.in
4de0686f
JF
119 ./Filter.sh <$< >$@ $(filters)
120
4e869640 121Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
e7ed5354 122 bison -v --report=state $<
e5332278
JF
123
124lex.cy.c: Cycript.l
125 flex $<
126
e5332278
JF
127#Parser.hpp: Parser.py Parser.dat
128# ./Parser.py <Parser.dat >$@
129
cacd1a88 130Cycript.tab.o: Cycript.tab.cc $(header)
a4dbf05b 131 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 132
cacd1a88 133lex.cy.o: lex.cy.c $(header)
a4dbf05b 134 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 135
f7c38a29 136%.o: %.cpp $(header)
a4dbf05b 137 $(target)$(gcc) $(flags) -c -o $@ $<
057f943f 138
cacd1a88 139#objc := -x c++
f7c38a29 140%.o: %.mm $(header)
a4dbf05b 141 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
5999c315 142
4e869640 143$(lib)cycript.$(dll): $(code)
a4dbf05b 144 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
82149e4b 145 $(ldid) $@
ea2d184c 146
4e869640 147cycript: Console.o $(lib)cycript.$(dll) $(inject)
a4dbf05b 148 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
b6961e53 149 $(entitle) cycript
262e358c 150
9b5527f0
JF
151package: $(deb)
152
153test: $(deb)
9e20b0b7 154 dpkg -i $(deb)
029bc65b 155 if [[ -e target.cy ]]; then cycript -c target.cy && echo; fi
45d0c928 156 if [[ -e jquery.js ]]; then /usr/bin/time cycript -c jquery.js >jquery.cyc.js; gzip -9c jquery.cyc.js >jquery.cyc.js.gz; wc -c jquery.{mam,gcc,cyc,bak,yui}.js; wc -c jquery.{cyc,gcc,bak,mam,yui}.js.gz; fi
029bc65b 157 if [[ -e test.cy ]]; then cycript test.cy; fi
1dbba6cc 158
d3c59903
JF
159install: cycript $(lib)cycript.$(dll)
160 cp -p cycript /usr/bin
161 cp -p $(lib)cycript.$(dll) /usr/lib
162
afe00096 163.PHONY: all clean extra package control.tmp