]>
Commit | Line | Data |
---|---|---|
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 | flags ?= -g3 -O0 -DYYDEBUG=1 | |
10 | ||
11 | paths := $(foreach path,$(paths),$(wildcard $(path))) | |
12 | flags += $(foreach path,$(paths),-I$(path) -L$(path)) | |
13 | objc := | |
14 | ||
15 | svn := $(shell svnversion) | |
16 | ||
17 | all: | |
18 | all := libcycript.db cycript | |
19 | ||
20 | dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null) | |
21 | ifneq ($(dpkg_architecture),) | |
22 | arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null) | |
23 | endif | |
24 | ||
25 | header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp | |
26 | code := sig/ffi_type.o sig/parse.o sig/copy.o | |
27 | code += Replace.o Output.o | |
28 | code += Cycript.tab.o lex.cy.o | |
29 | code += Network.o Parser.o | |
30 | code += JavaScriptCore.o Library.o | |
31 | ||
32 | inject := | |
33 | ||
34 | filters := C #E4X | |
35 | ldid := true | |
36 | entitle := $(ldid) | |
37 | dll := so | |
38 | apr := $(shell apr-1-config --link-ld) | |
39 | library := $(apr) -lffi -lsqlite3 | |
40 | console := $(apr) -lreadline | |
41 | depends := | |
42 | ||
43 | restart ?= $(MAKE) | |
44 | uname_s ?= $(shell uname -s) | |
45 | uname_p ?= $(shell uname -p) | |
46 | ||
47 | -include $(uname_s).mk | |
48 | -include $(uname_s)-$(uname_p).mk | |
49 | ||
50 | ifeq ($(filter ObjectiveC,$(filters)),) | |
51 | ifneq ($(shell which gnustep-config 2>/dev/null),) | |
52 | #include GNUstep.mk | |
53 | endif | |
54 | endif | |
55 | ||
56 | flags += -Wall -Werror -Wno-parentheses #-Wno-unused | |
57 | flags += -fPIC -fno-common | |
58 | flags += -I. -I$(shell apr-1-config --includedir) | |
59 | ||
60 | all += libcycript.$(dll) | |
61 | ||
62 | ifdef arch | |
63 | 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 | |
64 | ||
65 | all: $(deb) | |
66 | ||
67 | extra: | |
68 | ||
69 | ifeq ($(depends),) | |
70 | control: control.in cycript libcycript.so | |
71 | sed -e 's/&/'"$$(dpkg-query -S $$(ldd cycript libcycript.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)/' $< >$@ | |
72 | else | |
73 | control: control.in | |
74 | sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@ | |
75 | endif | |
76 | ||
77 | $(deb): $(all) control | |
78 | rm -rf package | |
79 | mkdir -p package/DEBIAN | |
80 | cp -a control package/DEBIAN | |
81 | $(restart) extra | |
82 | mkdir -p package/usr/{bin,lib,sbin} | |
83 | cp -a libcycript.$(dll) package/usr/lib | |
84 | cp -a cycript package/usr/bin | |
85 | #cp -a cyrver package/usr/sbin | |
86 | cp -a libcycript.db package/usr/lib | |
87 | dpkg-deb -b package $(deb) | |
88 | endif | |
89 | ||
90 | all: $(all) | |
91 | ||
92 | clean: | |
93 | rm -f *.o libcycript.$(dll) cycript libcycript.db Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.y Cycript.l control | |
94 | ||
95 | libcycript.db: Bridge.def | |
96 | rm -f libcycript.db | |
97 | { \ | |
98 | echo 'create table "bridge" ("mode" int not null, "name" text not null, "value" text null);'; \ | |
99 | grep '^[CFV]' Bridge.def | sed -e 's/^C/0/;s/^F/1/;s/^V/2/' | sed -e 's/"/\\"/g;s/^\([^ ]*\) \([^ ]*\) \(.*\)$$/insert into "bridge" ("mode", "name", "value") values (\1, '"'"'\2'"'"', '"'"'\3'"'"');/'; \ | |
100 | grep '^:' Bridge.def | sed -e 's/^: \([^ ]*\) \(.*\)/insert into "bridge" ("mode", "name", "value") values (-1, '"'"'\1'"'"', '"'"'\2'"'"');/'; \ | |
101 | grep '^[EST]' Bridge.def | sed -e 's/^S/3/;s/^T/4/;s/^E/5/' | sed -e 's/^5\(.*\)$$/4\1 i/' | sed -e 's/^\([^ ]*\) \([^ ]*\) \(.*\)$$/insert into "bridge" ("mode", "name", "value") values (\1, '"'"'\2'"'"', '"'"'\3'"'"');/'; \ | |
102 | } | sqlite3 libcycript.db | |
103 | ||
104 | %.y: %.y.in | |
105 | ./Filter.sh <$< >$@ $(filters) | |
106 | ||
107 | %.l: %.l.in | |
108 | ./Filter.sh <$< >$@ $(filters) | |
109 | ||
110 | Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.y | |
111 | bison -v --report=state $< | |
112 | ||
113 | lex.cy.c: Cycript.l | |
114 | flex $< | |
115 | ||
116 | #Parser.hpp: Parser.py Parser.dat | |
117 | # ./Parser.py <Parser.dat >$@ | |
118 | ||
119 | Cycript.tab.o: Cycript.tab.cc $(header) | |
120 | $(target)g++ $(flags) -c -o $@ $< | |
121 | ||
122 | lex.cy.o: lex.cy.c $(header) | |
123 | $(target)g++ $(flags) -c -o $@ $< | |
124 | ||
125 | %.o: %.cpp $(header) | |
126 | $(target)g++ $(flags) -c -o $@ $< | |
127 | ||
128 | #objc := -x c++ | |
129 | %.o: %.mm $(header) | |
130 | $(target)g++ $(objc) $(flags) -c -o $@ $< | |
131 | ||
132 | libcycript.$(dll): $(code) | |
133 | $(target)g++ $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link) | |
134 | $(ldid) $@ | |
135 | ||
136 | cycript: Console.o libcycript.$(dll) $(inject) | |
137 | $(target)g++ $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link) | |
138 | $(entitle) cycript | |
139 | ||
140 | package: $(deb) | |
141 | ||
142 | test: $(deb) | |
143 | dpkg -i $(deb) | |
144 | cycript test.cy | |
145 | ||
146 | .PHONY: all clean extra package |