]> git.saurik.com Git - cycript.git/blame - makefile
Added a saner make install path.
[cycript.git] / makefile
CommitLineData
f37e3501 1SHELL := $(shell which bash 2>/dev/null)
be4442da 2
ea2d184c
JF
3ifndef PKG_TARG
4target :=
5else
6target := $(PKG_TARG)-
7endif
8
a4dbf05b 9gcc := g++
aabea98c
JF
10flags ?= -g3 -O0 -DYYDEBUG=1
11
e0625f37 12paths := $(foreach path,$(paths),$(wildcard $(path)))
aabea98c 13flags += $(foreach path,$(paths),-I$(path) -L$(path))
eacba955 14objc :=
ea2d184c 15
9e20b0b7 16svn := $(shell svnversion)
9e20b0b7 17
1e7ce557 18all:
9cad30fa 19all := cycript
1e7ce557 20
bb9f5eef 21dpkg_architecture := $(shell which dpkg-architecture 2>/dev/null)
1e7ce557 22ifneq ($(dpkg_architecture),)
bb9f5eef 23arch := $(shell $(dpkg_architecture) -qDEB_HOST_ARCH 2>/dev/null)
1e7ce557
JF
24endif
25
6a981250 26header := Cycript.tab.hh Parser.hpp Pooling.hpp cycript.hpp Internal.hpp Error.hpp String.hpp Exception.hpp Standard.hpp
9cad30fa
JF
27
28code :=
9185d5ef
JF
29code += Replace.o Output.o
30code += Cycript.tab.o lex.cy.o
31code += Network.o Parser.o
cbaa5f0f 32code += JavaScriptCore.o Library.o
1e7ce557 33
b6961e53
JF
34inject :=
35
9cad30fa 36filters := #E4X
82149e4b 37ldid := true
b6961e53 38entitle := $(ldid)
4e869640 39lib := lib
1e7ce557 40dll := so
107e5814 41apr := $(shell apr-1-config --link-ld)
4e869640 42library := $(apr)
dfa452c2 43console := $(apr) -lreadline
f37e3501 44depends :=
1e7ce557 45
fb81b01c
JF
46restart ?= $(MAKE)
47uname_s ?= $(shell uname -s)
48uname_p ?= $(shell uname -p)
e0625f37 49
1e7ce557
JF
50-include $(uname_s).mk
51-include $(uname_s)-$(uname_p).mk
52
9cad30fa 53ifdef CY_EXECUTE
993f82f8
JF
54ifeq ($(filter ObjectiveC,$(filters)),)
55ifneq ($(shell which gnustep-config 2>/dev/null),)
ba4fa42f 56include GNUstep.mk
993f82f8
JF
57endif
58endif
9cad30fa 59endif
993f82f8 60
82149e4b 61flags += -Wall -Werror -Wno-parentheses #-Wno-unused
4e869640 62flags += -fno-common
7c6c5b0a 63flags += -I. -Iinclude -I$(shell apr-1-config --includedir)
cbaa5f0f 64
4e869640 65all += $(lib)cycript.$(dll)
f7c38a29 66
be36c292
JF
67filters += $(shell bison <(echo '%code{}%%_:') -o/dev/null 2>/dev/null && echo Bison24 || echo Bison23)
68
1e7ce557 69ifdef arch
b5dd57dc 70deb := $(shell grep ^Package: control.in | cut -d ' ' -f 2-)_$(shell grep ^Version: control.in | cut -d ' ' -f 2 | sed -e 's/\#/$(svn)/')_$(arch).deb
1e7ce557 71
d3c59903 72all:
1e7ce557 73
9cad30fa 74extra::
f37e3501 75
65cf734f 76ifeq ($(depends)$(dll),dylib)
4e869640 77control.tmp: control.in cycript $(lib)cycript.dylib
65cf734f
JF
78 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)/' $< >$@
79else
80ifeq ($(depends)$(dll),so)
4e869640
JF
81control.tmp: control.in cycript $(lib)cycript.so
82 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)/' $< >$@
b5dd57dc 83else
afe00096 84control.tmp: control.in
b5dd57dc
JF
85 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
86endif
65cf734f 87endif
b5dd57dc 88
afe00096 89control: control.tmp
f7720478 90 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
afe00096 91
b5dd57dc 92$(deb): $(all) control
1e7ce557
JF
93 rm -rf package
94 mkdir -p package/DEBIAN
7c6c5b0a 95 cp -pR control package/DEBIAN
1e7ce557 96 mkdir -p package/usr/{bin,lib,sbin}
9cad30fa 97 $(restart) extra
4e869640 98 cp -pR $(lib)cycript.$(dll) package/usr/lib
7c6c5b0a
JF
99 cp -pR cycript package/usr/bin
100 #cp -pR cyrver package/usr/sbin
1e7ce557
JF
101 dpkg-deb -b package $(deb)
102endif
9b5527f0 103
8953777c 104all: $(all)
ea2d184c
JF
105
106clean:
4e869640 107 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
88c977fa 108
4e869640 109%.yy: %.yy.in
cb02f8ae
JF
110 ./Filter.sh <$< >$@ $(filters)
111
112%.l: %.l.in
4de0686f
JF
113 ./Filter.sh <$< >$@ $(filters)
114
4e869640 115Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.yy
e7ed5354 116 bison -v --report=state $<
e5332278
JF
117
118lex.cy.c: Cycript.l
119 flex $<
120
e5332278
JF
121#Parser.hpp: Parser.py Parser.dat
122# ./Parser.py <Parser.dat >$@
123
cacd1a88 124Cycript.tab.o: Cycript.tab.cc $(header)
a4dbf05b 125 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 126
cacd1a88 127lex.cy.o: lex.cy.c $(header)
a4dbf05b 128 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 129
f7c38a29 130%.o: %.cpp $(header)
a4dbf05b 131 $(target)$(gcc) $(flags) -c -o $@ $<
057f943f 132
cacd1a88 133#objc := -x c++
f7c38a29 134%.o: %.mm $(header)
a4dbf05b 135 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
5999c315 136
4e869640 137$(lib)cycript.$(dll): $(code)
a4dbf05b 138 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
82149e4b 139 $(ldid) $@
ea2d184c 140
4e869640 141cycript: Console.o $(lib)cycript.$(dll) $(inject)
a4dbf05b 142 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
b6961e53 143 $(entitle) cycript
262e358c 144
9b5527f0
JF
145package: $(deb)
146
147test: $(deb)
9e20b0b7 148 dpkg -i $(deb)
029bc65b 149 if [[ -e target.cy ]]; then cycript -c target.cy && echo; fi
45d0c928 150 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
029bc65b 151 if [[ -e test.cy ]]; then cycript test.cy; fi
1dbba6cc 152
d3c59903
JF
153install: cycript $(lib)cycript.$(dll)
154 cp -p cycript /usr/bin
155 cp -p $(lib)cycript.$(dll) /usr/lib
156
afe00096 157.PHONY: all clean extra package control.tmp