-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
executable file
·153 lines (124 loc) · 4.54 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
PYTHON=$(shell which python)
SYSTEM=$(shell $(PYTHON) -c "import platform; print platform.system()")
ifeq (Linux, $(SYSTEM))
LIBEVENTDLL=libevent.so
endif
ifeq (Darwin, $(SYSTEM))
LIBEVENTDLL=libevent.dylib
ECHOOPTS=-e
endif
ifndef LIBEVENTDLL
fail
endif
egg: eggs
eggs: clean libeventdll
$(PYTHON) setup.py bdist_egg
all: eggs
distclean: fullclean
mrproper: fullclean
fullclean: clean
@echo "[*] removing _all_ automatically generated files"
rm -f evserver/libevent.so evserver/libevent.dylib
rm -f evserver/ctypes_event_*.py
clean:
find . -name "*.pyc" | xargs rm -f
find . -name "*.pyo" | xargs rm -f
rm -rf build dist evserver.egg-info
rm -f /tmp/fifo
rm -f log
propset: clean
find evserver Makefile *py README -type f -a -not -path \*.svn\* |xargs svn propset svn:mime-type 'text/plain'
svn propset svn:mime-type 'application/octet-stream' evserver/$(LIBEVENTDLL)
# needs:
# sudo apt-get install gccxml python-setuptools
# sudo easy_install ctypeslib
# libevent >= 1.4.2 compiled sources in LIBEVENTSOURCES
# (1.4.1 has a bug in chunked encoding and requires patching)
# libevent-1.4.6, libevent-1.4.7, libevent-1.4.8 *DON'T* work for me.
# no time still to investigate where is the bug
# for example:
# cd /tmp/libevent
# ./configure --prefix=/usr
# make
# use libevent sources, this will need the application to be runned with LD_LIBRARY_PATH
ifndef LIBEVENTSOURCES
ifeq (ok, $(shell [ -e "../libevent" ] && echo ok))
LIBEVENTSOURCES=../libevent
endif
ifeq (ok, $(shell [ -e "/tmp/libevent" ] && echo ok))
LIBEVENTSOURCES=/tmp/libevent
endif
endif
LIBEVENTLIB=$(LIBEVENTSOURCES)/.libs
LIBEVENTINCLUDE=$(LIBEVENTSOURCES)
LIBEVENTPRELOAD=$(LIBEVENTLIB)/$(LIBEVENTDLL)
VERSION=$(shell $(PYTHON) -c "import evserver.main; print evserver.main.get_libevent_version('$(LIBEVENTPRELOAD)').replace('-','_').replace('.','_')" )
CTYPESPY=evserver/ctypes_event_$(VERSION).py
# figuring this out was painful
#$ :D_LIBRARY_PATH="." python -c "import ctypes; ctypes.CDLL('libevent.so')";
bindings: libeventdll
@if [ ! -e "$(LIBEVENTPRELOAD)" ] ; then \
echo "Not found $(LIBEVENTPRELOAD). Check the libevent sources path in LIBEVENTSOURCES." ;\
echo "You should run: LIBEVENTSOURCES=../my/path/to/compiled/libevent make"; \
exit 1 ;\
fi
@if [ ! -e "$(LIBEVENTINCLUDE)/http-internal.h" ] ; then \
echo "Not found $(LIBEVENTINCLUDE)/http-internal.h. Check the libevent sources path in LIBEVENTSOURCES." ;\
echo "You should run: LIBEVENTSOURCES=../my/path/to/compiled/libevent make"; \
exit 1 ;\
fi
# testing dependencies
@gccxml --version
@python -c "import ctypeslib; import sys; sys.exit(0)"
@echo "[*] preparing headers"
cp $(LIBEVENTINCLUDE)/event.h .
cp $(LIBEVENTINCLUDE)/http-internal.h .
@echo $(ECHOOPTS) "\
#ifndef TAILQ_ENTRY \n\
#define _EVENT_DEFINED_TQENTRY \n\
#define TAILQ_ENTRY(type) \\\\\n\
struct { \\\\\n\
struct type *tqe_next; /* next element */ \\\\\n\
struct type **tqe_prev; /* address of previous next element */ \\\\\n\
} \n\
#endif /* !TAILQ_ENTRY */ \n\
" > evhttp.h
cat $(LIBEVENTINCLUDE)/evhttp.h >> evhttp.h
@echo $(ECHOOPTS) "\
extern \"C\" { \n\
#import <stdlib.h> \n\
#import <sys/queue.h> \n\
#import <sys/socket.h> \n\
#import \"event.h\" \n\
#import \"evhttp.h\" \n\
#import \"http-internal.h\" \n\
} \n\
" > d.h
@echo $(ECHOOPTS) "\
# don't touch. automatically generated by 'make ctypes' \n\
# for file $(LIBEVENTPRELOAD) \n\
import ctypes \n\
c_longdouble = ctypes.c_double \n\
" > $(CTYPESPY)
@echo "[*] magick happens" --preload "$(LIBEVENTPRELOAD)"
h2xml.py -I"$(LIBEVENTINCLUDE)" $(PWD)/d.h -o d.xml -c -q
sed "s/13u/13/g" d.xml > d2.xml
sed "s/15u/13/g" d2.xml > d.xml
LD_LIBRARY_PATH=$(LIBEVENTLIB) xml2py.py -l$(LIBEVENTDLL) -d d.xml -r "(event_|signal_|evbuffer_|evhttp|evtimer|EV).*" >> $(CTYPESPY)
# fix output
sed "s/CDLL('$(LIBEVENTDLL)')/CDLL(libeventbinary)/g" $(CTYPESPY) > $(CTYPESPY)2
mv $(CTYPESPY)2 $(CTYPESPY)
@echo "[*] new bindings to libevent are in $(CTYPESPY)"
rm d.xml d2.xml evhttp.h event.h http-internal.h d.h
libeventdll:
@if [ ! -e "$(LIBEVENTPRELOAD)" ] ; then \
echo "Not found $(LIBEVENTPRELOAD). Check the libevent sources path in LIBEVENTSOURCES." ;\
echo "You should run: LIBEVENTSOURCES=../my/path/to/compiled/libevent make"; \
exit 1 ;\
fi
rm -f evserver/libevent.so evserver/libevent.dylib
cp $(LIBEVENTPRELOAD) evserver/$(LIBEVENTDLL)
test:
PYTHONPATH="." $(PYTHON) test.py
rm -f log
prepare: clean ctypes