1 SHELL := $(shell which bash 2>/dev/null)
10 flags ?= -g3 -O0 -DYYDEBUG=1
12 paths := $(foreach path,$(paths),$(wildcard $(path)))
13 flags += $(foreach path,$(paths),-I$(path) -L$(path))
16 svn := $(shell svnversion)
21 dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null)
22 ifneq ($(dpkg_architecture),)
23 arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null)
26 header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
29 code += Replace.o Output.o
30 code += Cycript.tab.o lex.cy.o
31 code += Network.o Parser.o
32 code += JavaScriptCore.o Library.o
41 apr_config := apr-1-config
47 uname_s ?= $(shell uname -s)
48 uname_p ?= $(shell uname -p)
50 -include $(uname_s).mk
51 -include $(uname_s)-$(uname_p).mk
53 ifneq ($(shell pkg-config libffi --modversion 2>/dev/null),)
54 flags += $(shell pkg-config --cflags libffi)
58 ifeq ($(filter ObjectiveC,$(filters)),)
59 ifneq ($(shell which gnustep-config 2>/dev/null),)
65 apr := $(shell $(apr_config) --link-ld)
69 flags += -Wall -Werror -Wno-parentheses #-Wno-unused
71 flags += -I. -Iinclude -I$(shell $(apr_config) --includedir)
73 all += $(lib)cycript.$(dll)
75 filters += $(shell bison <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
78 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
84 ifeq ($(depends)$(dll),dylib)
85 control.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)/' $< >$@
88 ifeq ($(depends)$(dll),so)
89 control.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)/' $< >$@
92 control.tmp: control.in
93 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
98 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
100 $(deb): $(all) control
102 mkdir -p package/DEBIAN
103 cp -pR control package/DEBIAN
104 mkdir -p package/usr/{bin,lib,sbin}
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)
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 Cycript.output
118 ./Filter.sh <$< >$@ $(filters)
121 ./Filter.sh <$< >$@ $(filters)
123 Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
124 bison -v --report=state $<
127 flex -t $< | sed -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@
129 #Parser.hpp: Parser.py Parser.dat
130 # ./Parser.py <Parser.dat >$@
132 Cycript.tab.o: Cycript.tab.cc $(header)
133 $(target)$(gcc) $(flags) -c -o $@ $<
135 lex.cy.o: lex.cy.c $(header)
136 $(target)$(gcc) $(flags) -c -o $@ $<
139 $(target)$(gcc) $(flags) -c -o $@ $<
143 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
145 $(lib)cycript.$(dll): $(code)
146 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
149 cycript: Console.o $(lib)cycript.$(dll) $(inject)
150 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
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
161 install: cycript $(lib)cycript.$(dll)
162 sudo cp -p cycript /usr/bin
163 sudo cp -p $(lib)cycript.$(dll) /usr/lib
164 sudo chgrp procmod /usr/bin/cycript
165 sudo chmod g+s /usr/bin/cycript
168 sudo rm -f /usr/bin/cycript /usr/lib/libcycript.dylib
170 .PHONY: all clean extra package control.tmp