forked from mheily/libkqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.rb
executable file
·320 lines (269 loc) · 8.03 KB
/
configure.rb
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#!/usr/bin/env ruby
#
# Copyright (c) 2012 Mark Heily <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
begin
require 'makeconf'
rescue LoadError
$LOAD_PATH << "makeconf"
require 'makeconf'
end
# Determine the list of compiler flags
def get_cflags
cflags='-I./src/common -I./include -Wall -Wextra -Wno-missing-field-initializers -Werror -g -O2 -std=c99 -D_XOPEN_SOURCE=600'.split(/ /)
if Platform.is_linux?
# TODO - note this as a GCC 4.X dependency
cflags.push ' -fvisibility=hidden'
end
if Platform.is_solaris?
cflags.push "-D__EXTENSIONS__"
end
cflags
end
# Determine the list of source code files for libkqueue
def get_source_list(project)
src = %w{
src/common/filter.c
src/common/knote.c
src/common/map.c
src/common/kevent.c
src/common/kqueue.c
}
if Platform.is_solaris?
src.push 'src/solaris/signal.c',
'src/solaris/timer.c',
'src/solaris/platform.c',
'src/solaris/user.c'
end
if Platform.is_linux? or Platform.is_solaris?
src.push 'src/posix/platform.c'
end
if Platform.is_linux?
src.push 'src/linux/platform.c',
'src/linux/read.c',
'src/linux/write.c',
'src/linux/user.c',
'src/linux/vnode.c'
# FIXME: needed for RHEL5
#src.push 'src/posix/user.c'
if project.check_header('sys/signalfd.h')
src.push 'src/linux/signal.c'
else
src.push 'src/posix/signal.c'
end
src.push 'src/linux/timer.c'
end
if Platform.is_windows?
src.push 'src/windows/timer.c',
'src/windows/platform.c',
'src/windows/read.c',
'src/windows/user.c'
end
src
end
# Generate the linker flags
def get_ldadd
ldadd = ''
if Platform.is_linux? or Platform.is_solaris?
ldadd += ' -lpthread'
end
if Platform.is_linux?
ldadd += ' -lrt'
end
if Platform.is_windows?
ldadd += ' ws2_32.lib'
end
ldadd
end
#
# MAIN()
#
project = Project.new \
:id => 'libkqueue',
:version => '2.0.1'
kq = Library.new(
:id => 'libkqueue',
:cflags => get_cflags(),
:ldadd => get_ldadd(),
:sources => get_source_list(project)
)
project.check_header 'sys/event.h'
if Platform.is_linux?
project.check_decl 'EPOLLRDHUP', :include => 'sys/epoll.h'
project.check_decl 'ppoll', :cflags => '#define _GNU_SOURCE', :include => 'poll.h'
project.check_header('sys/epoll.h') or throw 'epoll is required'
project.check_header('sys/inotify.h') or throw 'inotify is required'
project.check_header %w{ sys/signalfd.h sys/timerfd.h sys/eventfd.h }
end
project.add(kq)
project.add(Header.new(
:id => 'event.h',
:sources => 'include/sys/event.h',
:namespace => 'kqueue/sys'
))
project.add(Manual.new('kqueue.2', :alias => 'kevent.2'))
test_ldadd = get_ldadd()
test_ldadd += ' libkqueue.a'
if Platform.is_windows?
project.add(
Test.new(
:id => 'kqtest',
:cflags => '-g -O0 -Wall -Werror -Iinclude -Itest',
:sources => %w{
test/main.c
test/kevent.c
test/test.c
test/read.c
test/timer.c
test/vnode.c
test/user.c
}, # NOTE: signal.c and proc.c are removed
:ldadd => test_ldadd.split(' ')
)
)
else
project.add(
Test.new(
:id => 'kqtest',
:cflags => '-g -O0 -Wall -Werror -I./include -I./test',
:sources => %w{
test/main.c
test/kevent.c
test/test.c
test/proc.c
test/read.c
test/signal.c
test/timer.c
test/vnode.c
test/user.c
},
:ldadd => test_ldadd.split(' ')
)
)
end
project.add(PkgConfig.new(
:name => 'libkqueue',
:description => 'Emulates FreeBSD kqueue(2) on other platforms',
:requires => '',
:libs => '-lkqueue',
:libs_private => '-lpthread',
:export_cflags => '-I${includedir}/kqueue'
))
project.packager.add 'libkqueue.spec'
mc = Makeconf.new()
mc.configure(project)
__END__
#
# BEGIN: old config.inc contents
#
program="libkqueue"
version="2.0a"
abi_major="0"
abi_minor="0"
abi_version="$abi_major.$abi_minor"
cflags="-Wall -Wextra -Wno-missing-field-initializers -Werror -g -O2 -std=c99 -D_XOPEN_SOURCE=600"
ldflags=""
sources="src/common/filter.c src/common/knote.c src/common/map.c
src/common/kevent.c src/common/kqueue.c"
libdepends=""
deps="src/common/private.h src/common/debug.h"
mans="kqueue.2"
headers="src/common/private.h"
extra_dist="*.in"
subdirs="src include test"
# Package metadata
pkg_summary="Emulates the kqueue and kevent system calls"
pkg_description="Emulates the kqueue and kevent system calls"
license="BSD"
author="Mark Heily"
pre_configure_hook() {
if [ "$debug" = "yes" ] ; then
cflags="$cflags -g3 -O0 -rdynamic"
fi
if [ "$target" != "windows" ] ; then
cflags="$cflags -fpic"
fi
optional_headers="err.h"
libdepends=" -L$libdir"
if [ $target = "linux" ] ; then
check_symbol sys/epoll.h EPOLLRDHUP
# TODO - note this as a GCC 4.X dependency
cflags="$cflags -fvisibility=hidden"
libdepends="$libdepends -lpthread -lrt"
required_headers="sys/epoll.h sys/inotify.h"
optional_headers="sys/signalfd.h sys/timerfd.h sys/eventfd.h"
fi
if [ $target = "solaris" ] ; then
cflags="$cflags -m64"
ldflags="$ldflags -m64"
libdepends="$libdepends -lsocket -lnsl"
fi
}
post_configure_hook() {
finalize target "$target"
platform="src/posix/platform.c"
evfilt_signal="src/posix/signal.c"
evfilt_proc="src/$target/proc.c"
evfilt_socket="src/$target/socket.c"
evfilt_timer="src/posix/timer.c"
evfilt_user="src/posix/user.c"
evfilt_vnode="src/$target/vnode.c"
if [ $target = "linux" ] ; then
evfilt_user="src/linux/user.c"
evfilt_socket="src/linux/read.c src/linux/write.c"
#XXX-FIXME disabled
evfilt_proc=""
if [ "$have_sys_signalfd_h" = "yes" ] ; then
evfilt_signal="src/linux/signal.c"
fi
if [ "$have_sys_timerfd_h" = "yes" ] ; then
evfilt_timer="src/linux/timer.c"
fi
platform="$platform src/linux/platform.c"
fi
if [ $target = "solaris" ] ; then
cflags="$cflags -D__EXTENSIONS__"
platform="$platform src/solaris/platform.c"
evfilt_timer="src/solaris/timer.c"
evfilt_user="src/solaris/user.c"
evfilt_signal="src/solaris/signal.c"
evfilt_proc=""
evfilt_vnode=""
fi
# FIXME: This will compile but not actually work
if [ $target = "freebsd" ] ; then
evfilt_signal="src/posix/signal.c"
evfilt_proc=""
evfilt_socket=""
evfilt_timer=""
evfilt_vnode=""
fi
if [ $target = "windows" ] ; then
platform="src/windows/platform.c"
cflags="$cflags -march=i686 -lws2_32"
ldflags="$ldflags -march=i686"
ldadd="-lws2_32"
evfilt_proc=""
evfilt_signal=""
#evfilt_socket="src/windows/read.c src/linux/write.c"
evfilt_socket="src/windows/read.c"
evfilt_timer="src/windows/timer.c"
evfilt_user="src/windows/user.c"
evfilt_vnode=""
fi
sources="$sources $platform
$evfilt_signal $evfilt_proc
$evfilt_socket $evfilt_timer $evfilt_user $evfilt_vnode"
}