]> git.saurik.com Git - cycript.git/blob - GNUmakefile.in
Better version checking for bison, flex, and gperf that falls through to other versio...
[cycript.git] / GNUmakefile.in
1 # @configure_input@
2
3 SHELL := @_BASH@
4 VPATH := @srcdir@
5
6 ifndef PKG_TARG
7 target :=
8 else
9 target := $(PKG_TARG)-
10 endif
11
12 srcdir := @srcdir@
13 top_builddir := @top_builddir@
14 flex := @FLEX@
15 libtool := @LIBTOOL@
16 cxx := @CXX@
17 objcxx := @OBJCXX@
18 cflags := @CPPFLAGS@ @CXXFLAGS@ -DYYDEBUG=1 $(filter -DHAVE_FFI%,@DEFS@)
19 objcxxflags := @OBJCXXFLAGS@
20 ldflags := @LDFLAGS@
21 library := @LIBS@ @LTLIBAPR@ @LTLIBICONV@
22 sed := @SED@
23 bison := @BISON@
24 time := @TIME@
25 gperf := @GPERF@
26 otool := @OTOOL@
27
28 INSTALL := @INSTALL@
29 INSTALL_PROGRAM := @INSTALL_PROGRAM@
30 INSTALL_DATA := @INSTALL_DATA@
31
32 PACKAGE_TARNAME := @PACKAGE_TARNAME@
33 prefix := @prefix@
34 exec_prefix := @exec_prefix@
35 bindir := @bindir@
36 sbindir := @sbindir@
37 libexecdir := @libexecdir@
38 datarootdir := @datarootdir@
39 datadir := @datadir@
40 sysconfdir := @sysconfdir@
41 sharedstatedir := @sharedstatedir@
42 localstatedir := @localstatedir@
43 includedir := @includedir@
44 oldincludedir := @oldincludedir@
45 docdir := @docdir@
46 infodir := @infodir@
47 htmldir := @htmldir@
48 dvidir := @dvidir@
49 pdfdir := @pdfdir@
50 psdir := @psdir@
51 libdir := @libdir@
52 localedir := @localedir@
53 mandir := @mandir@
54
55 CY_EXECUTE := @CY_EXECUTE@
56 CY_OBJECTIVEC := @CY_OBJECTIVEC@
57 CY_OBJECTIVEC_MACH := @CY_OBJECTIVEC_MACH@
58
59 paths := $(foreach path,$(paths),$(wildcard $(path)))
60 cflags += $(foreach path,$(paths),-I$(path) -L$(path))
61
62 svn := $(shell svnversion $(srcdir))
63
64 all:
65 all := cycript
66
67 dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null)
68 ifneq ($(dpkg_architecture),)
69 arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null)
70 endif
71
72 header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
73
74 code :=
75 code += Replace.lo Output.lo
76 code += Cycript.tab.lo lex.cy.lo
77 code += Network.lo Parser.lo
78 code += JavaScriptCore.lo Library.lo
79
80 inject :=
81
82 filters := #E4X
83 ldid := true
84 entitle := $(ldid)
85 lib := lib
86 dll := so
87 depends :=
88
89 restart ?= $(MAKE)
90 uname_s ?= $(shell uname -s)
91 uname_p ?= $(shell uname -p)
92
93 ifeq ($(CY_EXECUTE),1)
94 cflags += -DCY_EXECUTE
95 code += sig/ffi_type.lo sig/parse.lo sig/copy.lo
96 code += Execute.lo Bridge.lo
97 filters += C
98 endif
99
100 cflags += -Wall -Werror -Wno-parentheses #-Wno-unused
101 cflags += -fno-common
102 ifneq ($(srcdir),.)
103 cflags += -I.
104 endif
105 cflags += -I$(srcdir) -I$(srcdir)/include
106
107 all += libcycript.la
108
109 filters += $(shell $(bison) <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
110
111 ifdef arch
112 deb := $(shell grep ^Package: $(srcdir)/control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: $(srcdir)/control.in | cut -d ' ' -f 2 | $(sed) -e 's/\#/$(svn)/')_$(arch).deb
113
114 all:
115
116 extra::
117
118 ifeq ($(depends)$(dll),dylib)
119 control.tmp: control.in cycript $(lib)cycript.dylib
120 $(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)/' $< >$@
121 else
122 ifeq ($(depends)$(dll),so)
123 control.tmp: control.in cycript $(lib)cycript.so
124 $(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)/' $< >$@
125 else
126 control.tmp: control.in
127 $(sed) -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
128 endif
129 endif
130
131 control: control.tmp
132 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
133
134 $(deb): $(all) control
135 rm -rf package
136 mkdir -p package/DEBIAN
137 cp -pR control package/DEBIAN
138 mkdir -p package/usr/{bin,lib,sbin}
139 $(restart) extra
140 cp -pR $(lib)cycript.$(dll) package/usr/lib
141 cp -pR cycript package/usr/bin
142 #cp -pR cyrver package/usr/sbin
143 dpkg-deb -b package $(deb)
144 endif
145
146 ifeq ($(CY_EXECUTE),1)
147 Bridge.gperf: Bridge.def Bridge.sh
148 $(srcdir)/Bridge.sh $< >$@
149
150 Bridge.hpp: Bridge.gperf
151 $(gperf) $< | $(sed) -e 's/defined __GNUC_STDC_INLINE__ || defined __GNUC_GNU_INLINE__/0/' >$@
152
153 Bridge.lo: Bridge.hpp
154 endif
155
156 ifeq ($(CY_OBJECTIVEC),1)
157 filters += ObjectiveC
158 header += Struct.hpp ObjectiveC/Internal.hpp ObjectiveC/Syntax.hpp
159 code += ObjectiveC/Output.lo ObjectiveC/Replace.lo ObjectiveC/Library.lo
160
161 Struct.hpp:
162 $$($(objcxx) -print-prog-name=cc1obj) -print-objc-runtime-info </dev/null >$@
163
164 ifeq ($(CY_OBJECTIVEC_MACH),1)
165 code += Handler.lo
166 cflags += -DCY_ATTACH
167 inject += Mach/Inject.lo
168
169 Mach/Inject.lo: Trampoline.t.hpp Baton.hpp
170
171 %.t.hpp: %.t.cpp
172 $(libtool) --mode=compile $(cxx) -c -fno-exceptions -I$(srcdir)/include -o $*.t.lo $< $(cflags) && { file=($$($(otool) -l .libs/$*.t.o | $(sed) -e 'x; /^1/ { x; /^ *filesize / { s/^.* //; p; }; /^ *fileoff / { s/^.* //; p; }; x; }; x; /^ *cmd LC_SEGMENT$$/ { s/.*/1/; x; }; d;')); od -t x1 -j $${file[0]} -N $${file[1]} .libs/$*.t.o | $(sed) -e 's/^[^ ]*//' | tr $$'\n' ' ' | $(sed) -e 's/ */ /g;s/^ *//;s/ $$//;s/ /,/g;s/\([^,][^,]\)/0x\1/g' | $(sed) -e 's/^/static const char $*_[] = {/;s/$$/};/' && echo && echo "/*" && $(otool) -vVt .libs/$*.t.o && echo "*/"; } >$@ && rm -f $*.t.lo .libs/$*.t.o
173 endif
174 endif
175
176 all: $(all)
177
178 clean::
179 rm -rf *.lo *.o *.d *.t.hpp .libs */*.lo */.libs libcycript.la $(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.gperf Bridge.hpp Cycript.output
180 ifneq ($(srcdir),.)
181 rm -rf Mach ObjectiveC sig
182 endif
183
184 distclean: clean
185 rm -f GNUmakefile Makefile config.log config.status libtool
186
187 %.yy: %.yy.in
188 $(srcdir)/Filter.sh <$< >$@ $(filters)
189
190 %.l: %.l.in
191 $(srcdir)/Filter.sh <$< >$@ $(filters)
192
193 Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
194 $(bison) -v --report=state $<
195
196 lex.cy.c: Cycript.l
197 $(flex) -t $< | $(sed) -e 's/int yyl;/yy_size_t yyl;/;s/int yyleng_r;/yy_size_t yyleng_r;/' >$@
198
199 #Parser.hpp: Parser.py Parser.dat
200 # ./Parser.py <Parser.dat >$@
201
202 Cycript.tab.lo: Cycript.tab.cc $(header)
203 $(libtool) --mode=compile $(cxx) $(cflags) -c -o $@ $<
204
205 lex.cy.lo: lex.cy.c $(header)
206 $(libtool) --mode=compile $(cxx) $(cflags) -c -o $@ $<
207
208 %.lo: %.cpp $(header)
209 $(libtool) --mode=compile $(cxx) $(cflags) -c -o $@ $<
210
211 %.lo: %.mm $(header)
212 $(libtool) --mode=compile $(objcxx) $(objcxxflags) $(cflags) -c -o $@ $<
213
214 libcycript.la: $(code)
215 $(libtool) --mode=link $(cxx) $(ldflags) -o $@ $(filter %.lo,$^) $(library) $(link) -rpath $(libdir)
216 $(ldid) $@
217
218 cycript: Console.lo libcycript.la $(inject)
219 $(libtool) --mode=link $(cxx) $(ldflags) -o $@ $(filter %.lo,$^) libcycript.la $(link) -rpath $(libdir)
220 $(entitle) cycript
221
222 package: $(deb)
223
224 test: cycript
225 if [[ -e target.cy ]]; then ./cycript -c target.cy && echo; fi
226 if [[ -e jquery.js ]]; then $(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
227 if [[ -e test.cy ]]; then ./cycript test.cy; fi
228
229 install: cycript libcycript.la
230 $(INSTALL) -d $(DESTDIR)$(bindir) $(DESTDIR)$(libdir)
231 $(libtool) --mode=install $(INSTALL_PROGRAM) libcycript.la $(DESTDIR)$(libdir)/libcycript.la
232 $(libtool) --mode=install $(INSTALL_PROGRAM) cycript $(DESTDIR)$(bindir)/cycript
233
234 uninstall:
235 $(libtool) --mode=uninstall rm -f $(DESTDIR)$(bindir)/cycript
236 $(libtool) --mode=uninstall rm -f $(DESTDIR)$(libdir)/libcycript.la
237
238 .PHONY: all clean extra install uninstall package test control.tmp