]> git.saurik.com Git - cycript.git/blob - makefile
Generalized fix for injector.
[cycript.git] / makefile
1 SHELL := $(shell which bash 2>/dev/null)
2
3 ifndef PKG_TARG
4 target :=
5 else
6 target := $(PKG_TARG)-
7 endif
8
9 prefix := /usr
10
11 gcc := g++
12 flags ?= -g3 -O0 -DYYDEBUG=1
13
14 paths := $(foreach path,$(paths),$(wildcard $(path)))
15 flags += $(foreach path,$(paths),-I$(path) -L$(path))
16 objc :=
17
18 svn := $(shell svnversion)
19
20 all:
21 all := cycript
22
23 dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null)
24 ifneq ($(dpkg_architecture),)
25 arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null)
26 endif
27
28 header := Cycript.tab.hh Parser.hpp Pooling.hpp List.hpp Local.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
29
30 code :=
31 code += Replace.o Output.o
32 code += Cycript.tab.o lex.cy.o
33 code += Network.o Parser.o
34 code += JavaScriptCore.o Library.o
35
36 inject :=
37
38 filters := #E4X
39 ldid := true
40 entitle := $(ldid)
41 lib := lib
42 dll := so
43 apr_config := apr-1-config
44 library :=
45 console := -lreadline
46 depends :=
47
48 restart ?= $(MAKE)
49 uname_s ?= $(shell uname -s)
50 uname_p ?= $(shell uname -p)
51
52 -include $(uname_s).mk
53 -include $(uname_s)-$(uname_p).mk
54
55 ifneq ($(shell pkg-config libffi --modversion 2>/dev/null),)
56 flags += $(shell pkg-config --cflags libffi)
57 endif
58
59 ifdef CY_EXECUTE
60 ifeq ($(filter ObjectiveC,$(filters)),)
61 ifneq ($(shell which gnustep-config 2>/dev/null),)
62 include GNUstep.mk
63 endif
64 endif
65 endif
66
67 apr := $(shell $(apr_config) --link-ld)
68 library += $(apr)
69 console += $(apr)
70
71 flags += -Wall -Werror -Wno-parentheses #-Wno-unused
72 flags += -fno-common
73 flags += -I. -Iinclude -I$(shell $(apr_config) --includedir)
74
75 all += $(lib)cycript.$(dll)
76
77 filters += $(shell bison <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
78
79 ifdef arch
80 deb := $(shell grep ^Package: control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: control.in | cut -d ' ' -f 2 | sed -e 's/\#/$(svn)/')_$(arch).deb
81
82 all:
83
84 extra::
85
86 ifeq ($(depends)$(dll),dylib)
87 control.tmp: control.in cycript $(lib)cycript.dylib
88 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)/' $< >$@
89 else
90 ifeq ($(depends)$(dll),so)
91 control.tmp: control.in cycript $(lib)cycript.so
92 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)/' $< >$@
93 else
94 control.tmp: control.in
95 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
96 endif
97 endif
98
99 control: control.tmp
100 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
101
102 $(deb): $(all) control
103 rm -rf package
104 mkdir -p package/DEBIAN
105 cp -pR control package/DEBIAN
106 mkdir -p package$(prefix)/{bin,lib,sbin}
107 $(restart) extra
108 cp -pR $(lib)cycript.$(dll) package$(prefix)/lib
109 cp -pR cycript package$(prefix)/bin
110 #cp -pR cyrver package$(prefix)/sbin
111 dpkg-deb -b package $(deb)
112 endif
113
114 all: $(all)
115
116 clean::
117 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 Cycript.output
118
119 %.yy: %.yy.in
120 ./Filter.sh <$< >$@ $(filters)
121
122 %.l: %.l.in
123 ./Filter.sh <$< >$@ $(filters)
124
125 Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
126 bison -v --report=state $<
127
128 lex.cy.c: Cycript.l
129 flex -t $< | sed -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@
130
131 #Parser.hpp: Parser.py Parser.dat
132 # ./Parser.py <Parser.dat >$@
133
134 Cycript.tab.o: Cycript.tab.cc $(header)
135 $(target)$(gcc) $(flags) -c -o $@ $<
136
137 lex.cy.o: lex.cy.c $(header)
138 $(target)$(gcc) $(flags) -c -o $@ $<
139
140 %.o: %.cpp $(header)
141 $(target)$(gcc) $(flags) -c -o $@ $<
142
143 #objc := -x c++
144 %.o: %.mm $(header)
145 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
146
147 $(lib)cycript.$(dll): $(code)
148 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
149 $(ldid) $@
150
151 cycript: Console.o $(lib)cycript.$(dll) $(inject)
152 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
153 $(entitle) cycript
154
155 package: $(deb)
156
157 test: $(deb)
158 dpkg -i $(deb)
159 if [[ -e target.cy ]]; then cycript -c target.cy && echo; fi
160 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
161 if [[ -e test.cy ]]; then cycript test.cy; fi
162
163 install: cycript $(lib)cycript.$(dll)
164 sudo cp -p cycript /usr/bin
165 sudo cp -p $(lib)cycript.$(dll) /usr/lib
166 sudo chgrp procmod /usr/bin/cycript
167 sudo chmod g+s /usr/bin/cycript
168
169 uninstall:
170 sudo rm -f /usr/bin/cycript /usr/lib/libcycript.dylib
171
172 .PHONY: all clean extra package control.tmp