]> git.saurik.com Git - cycript.git/blob - makefile
Attempting to abstract 64-bit Mac.
[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 gcc := g++
10 flags ?= -g3 -O0 -DYYDEBUG=1
11
12 paths := $(foreach path,$(paths),$(wildcard $(path)))
13 flags += $(foreach path,$(paths),-I$(path) -L$(path))
14 objc :=
15
16 svn := $(shell svnversion)
17
18 all:
19 all := cycript
20
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)
24 endif
25
26 header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
27
28 code :=
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
33
34 inject :=
35
36 filters := #E4X
37 ldid := true
38 entitle := $(ldid)
39 lib := lib
40 dll := so
41 apr := $(shell apr-1-config --link-ld)
42 library := $(apr)
43 console := $(apr) -lreadline
44 depends :=
45
46 restart ?= $(MAKE)
47 uname_s ?= $(shell uname -s)
48 uname_p ?= $(shell uname -p)
49 uname_m ?= $(shell uname -m)
50
51 -include $(uname_s).mk
52 -include $(uname_s)-$(uname_p).mk
53 -include $(uname_s)-$(uname_m).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 flags += -Wall -Werror -Wno-parentheses #-Wno-unused
68 flags += -fno-common
69 flags += -I. -Iinclude -I$(shell apr-1-config --includedir)
70
71 all += $(lib)cycript.$(dll)
72
73 filters += $(shell bison <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
74
75 ifdef arch
76 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
77
78 all:
79
80 extra::
81
82 ifeq ($(depends)$(dll),dylib)
83 control.tmp: control.in cycript $(lib)cycript.dylib
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)/' $< >$@
85 else
86 ifeq ($(depends)$(dll),so)
87 control.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)/' $< >$@
89 else
90 control.tmp: control.in
91 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
92 endif
93 endif
94
95 control: control.tmp
96 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
97
98 $(deb): $(all) control
99 rm -rf package
100 mkdir -p package/DEBIAN
101 cp -pR control package/DEBIAN
102 mkdir -p package/usr/{bin,lib,sbin}
103 $(restart) extra
104 cp -pR $(lib)cycript.$(dll) package/usr/lib
105 cp -pR cycript package/usr/bin
106 #cp -pR cyrver package/usr/sbin
107 dpkg-deb -b package $(deb)
108 endif
109
110 all: $(all)
111
112 clean:
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
114
115 %.yy: %.yy.in
116 ./Filter.sh <$< >$@ $(filters)
117
118 %.l: %.l.in
119 ./Filter.sh <$< >$@ $(filters)
120
121 Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
122 bison -v --report=state $<
123
124 lex.cy.c: Cycript.l
125 flex $<
126
127 #Parser.hpp: Parser.py Parser.dat
128 # ./Parser.py <Parser.dat >$@
129
130 Cycript.tab.o: Cycript.tab.cc $(header)
131 $(target)$(gcc) $(flags) -c -o $@ $<
132
133 lex.cy.o: lex.cy.c $(header)
134 $(target)$(gcc) $(flags) -c -o $@ $<
135
136 %.o: %.cpp $(header)
137 $(target)$(gcc) $(flags) -c -o $@ $<
138
139 #objc := -x c++
140 %.o: %.mm $(header)
141 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
142
143 $(lib)cycript.$(dll): $(code)
144 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
145 $(ldid) $@
146
147 cycript: Console.o $(lib)cycript.$(dll) $(inject)
148 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
149 $(entitle) cycript
150
151 package: $(deb)
152
153 test: $(deb)
154 dpkg -i $(deb)
155 if [[ -e target.cy ]]; then cycript -c target.cy && echo; fi
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
157 if [[ -e test.cy ]]; then cycript test.cy; fi
158
159 install: cycript $(lib)cycript.$(dll)
160 cp -p cycript /usr/bin
161 cp -p $(lib)cycript.$(dll) /usr/lib
162
163 .PHONY: all clean extra package control.tmp