]> git.saurik.com Git - cycript.git/blame - makefile
Fixing various FreeBSD issues.
[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)
1e7ce557 39dll := so
da858962 40apr := -lapr-1
9cad30fa 41library :=
dfa452c2 42console := $(apr) -lreadline
f37e3501 43depends :=
1e7ce557 44
fb81b01c
JF
45restart ?= $(MAKE)
46uname_s ?= $(shell uname -s)
47uname_p ?= $(shell uname -p)
e0625f37 48
1e7ce557
JF
49-include $(uname_s).mk
50-include $(uname_s)-$(uname_p).mk
51
9cad30fa 52ifdef CY_EXECUTE
993f82f8
JF
53ifeq ($(filter ObjectiveC,$(filters)),)
54ifneq ($(shell which gnustep-config 2>/dev/null),)
ba4fa42f 55include GNUstep.mk
993f82f8
JF
56endif
57endif
9cad30fa 58endif
993f82f8 59
82149e4b 60flags += -Wall -Werror -Wno-parentheses #-Wno-unused
cbaa5f0f 61flags += -fPIC -fno-common
7c6c5b0a 62flags += -I. -Iinclude -I$(shell apr-1-config --includedir)
cbaa5f0f 63
1e7ce557 64all += libcycript.$(dll)
f7c38a29 65
1e7ce557 66ifdef arch
b5dd57dc 67deb := $(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
JF
68
69all: $(deb)
70
9cad30fa 71extra::
f37e3501 72
65cf734f 73ifeq ($(depends)$(dll),dylib)
afe00096 74control.tmp: control.in cycript libcycript.dylib
65cf734f
JF
75 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)/' $< >$@
76else
77ifeq ($(depends)$(dll),so)
afe00096 78control.tmp: control.in cycript libcycript.so
b5dd57dc
JF
79 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)/' $< >$@
80else
afe00096 81control.tmp: control.in
b5dd57dc
JF
82 sed -e 's/&/$(foreach depend,$(depends),$(depend),)/;s/,$$//;s/#/$(svn)/;s/%/$(arch)/' $< >$@
83endif
65cf734f 84endif
b5dd57dc 85
afe00096 86control: control.tmp
f7720478 87 [[ -e control ]] && diff control control.tmp &>/dev/null || cp -pRf control.tmp control
afe00096 88
b5dd57dc 89$(deb): $(all) control
1e7ce557
JF
90 rm -rf package
91 mkdir -p package/DEBIAN
7c6c5b0a 92 cp -pR control package/DEBIAN
1e7ce557 93 mkdir -p package/usr/{bin,lib,sbin}
9cad30fa 94 $(restart) extra
7c6c5b0a
JF
95 cp -pR libcycript.$(dll) package/usr/lib
96 cp -pR cycript package/usr/bin
97 #cp -pR cyrver package/usr/sbin
1e7ce557
JF
98 dpkg-deb -b package $(deb)
99endif
9b5527f0 100
8953777c 101all: $(all)
ea2d184c
JF
102
103clean:
9cad30fa 104 rm -f *.o libcycript.$(dll) $(all) Struct.hpp lex.cy.c Cycript.tab.cc Cycript.tab.hh location.hh position.hh stack.hh cyrver Cycript.y Cycript.l control
88c977fa 105
cb02f8ae
JF
106%.y: %.y.in
107 ./Filter.sh <$< >$@ $(filters)
108
109%.l: %.l.in
4de0686f
JF
110 ./Filter.sh <$< >$@ $(filters)
111
5999c315 112Cycript.tab.cc Cycript.tab.hh location.hh position.hh: Cycript.y
e7ed5354 113 bison -v --report=state $<
e5332278
JF
114
115lex.cy.c: Cycript.l
116 flex $<
117
e5332278
JF
118#Parser.hpp: Parser.py Parser.dat
119# ./Parser.py <Parser.dat >$@
120
cacd1a88 121Cycript.tab.o: Cycript.tab.cc $(header)
a4dbf05b 122 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 123
cacd1a88 124lex.cy.o: lex.cy.c $(header)
a4dbf05b 125 $(target)$(gcc) $(flags) -c -o $@ $<
5999c315 126
f7c38a29 127%.o: %.cpp $(header)
a4dbf05b 128 $(target)$(gcc) $(flags) -c -o $@ $<
057f943f 129
cacd1a88 130#objc := -x c++
f7c38a29 131%.o: %.mm $(header)
a4dbf05b 132 $(target)$(gcc) $(objc) $(flags) -c -o $@ $<
5999c315 133
4de0686f 134libcycript.$(dll): $(code)
a4dbf05b 135 $(target)$(gcc) $(flags) -shared -dynamiclib -o $@ $(filter %.o,$^) $(library) $(link)
82149e4b 136 $(ldid) $@
ea2d184c 137
b6961e53 138cycript: Console.o libcycript.$(dll) $(inject)
a4dbf05b 139 $(target)$(gcc) $(flags) -o $@ $(filter %.o,$^) -L. -lcycript $(console) $(link)
b6961e53 140 $(entitle) cycript
262e358c 141
9b5527f0
JF
142package: $(deb)
143
144test: $(deb)
9e20b0b7 145 dpkg -i $(deb)
029bc65b 146 if [[ -e target.cy ]]; then cycript -c target.cy && echo; fi
45d0c928 147 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 148 if [[ -e test.cy ]]; then cycript test.cy; fi
1dbba6cc 149
afe00096 150.PHONY: all clean extra package control.tmp