]> git.saurik.com Git - cycript.git/blob - makefile
Finished porting to GNUstep, although it doesn't actually work (but it /did/ find...
[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 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 filters := C #E4X
33 ldid := true
34 dll := so
35 apr := $(shell apr-1-config --link-ld)
36 library := $(apr) -lffi -lsqlite3
37 console := $(apr) -lreadline
38 depends :=
39
40 restart ?= $(MAKE)
41 uname_s ?= $(shell uname -s)
42 uname_p ?= $(shell uname -p)
43
44 -include $(uname_s).mk
45 -include $(uname_s)-$(uname_p).mk
46
47 ifeq ($(filter ObjectiveC,$(filters)),)
48 ifneq ($(shell which gnustep-config 2>/dev/null),)
49 #include GNUstep.mk
50 endif
51 endif
52
53 flags += -Wall -Werror -Wno-parentheses #-Wno-unused
54 flags += -fPIC -fno-common
55 flags += -I. -I$(shell apr-1-config --includedir)
56
57 all += libcycript.$(dll)
58
59 ifdef arch
60 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
61
62 all: $(deb)
63
64 extra:
65
66 control: control.in cycript libcycript.so
67 ifeq ($(depends),)
68 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)/' $< >$@
69 else
70 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
71 endif
72
73 $(deb): $(all) control
74 rm -rf package
75 mkdir -p package/DEBIAN
76 cp -a control package/DEBIAN
77 $(restart) extra
78 mkdir -p package/usr/{bin,lib,sbin}
79 cp -a libcycript.$(dll) package/usr/lib
80 cp -a cycript package/usr/bin
81 #cp -a cyrver package/usr/sbin
82 cp -a libcycript.db package/usr/lib
83 dpkg-deb -b package $(deb)
84 endif
85
86 all: $(all)
87
88 clean:
89 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
90
91 libcycript.db: Bridge.def
92 rm -f libcycript.db
93 { \
94 echo 'create table "bridge" ("mode" int not null, "name" text not null, "value" text null);'; \
95 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'"'"');/'; \
96 grep '^:' Bridge.def | sed -e 's/^: \([^ ]*\) \(.*\)/insert into "bridge" ("mode", "name", "value") values (-1, '"'"'\1'"'"', '"'"'\2'"'"');/'; \
97 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'"'"');/'; \
98 } | sqlite3 libcycript.db
99
100 %.y: %.y.in
101 ./Filter.sh <$< >$@ $(filters)
102
103 %.l: %.l.in
104 ./Filter.sh <$< >$@ $(filters)
105
106 Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.y
107 bison -v --report=state $<
108
109 lex.cy.c: Cycript.l
110 flex $<
111
112 #Parser.hpp: Parser.py Parser.dat
113 # ./Parser.py <Parser.dat >$@
114
115 Cycript.tab.o: Cycript.tab.cc $(header)
116 $(target)g++ $(flags) -c -o $@ $<
117
118 lex.cy.o: lex.cy.c $(header)
119 $(target)g++ $(flags) -c -o $@ $<
120
121 %.o: %.cpp $(header)
122 $(target)g++ $(flags) -c -o $@ $<
123
124 #objc := -x c++
125 %.o: %.mm $(header)
126 $(target)g++ $(objc) $(flags) -c -o $@ $<
127
128 libcycript.$(dll): $(code)
129 $(target)g++ $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
130 $(ldid) $@
131
132 cycript: Console.o libcycript.$(dll)
133 $(target)g++ $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
134 $(ldid) cycript
135
136 package: $(deb)
137
138 test: $(deb)
139 dpkg -i $(deb)
140 cycript test.cy
141
142 .PHONY: all clean extra package