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