-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
391 lines (294 loc) · 12.8 KB
/
Rakefile
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
require 'mkmf'
require 'rake'
require 'rake/clean'
FileList['build/rake/**.rb'].each do |f| load f end
VERSION = '0.2pre'
PREFIX = ENV['PREFIX'] || '/usr'
LIBDIR = ENV['LIBDIR'] || "#{PREFIX}/lib"
LOCALESTATEDIR = ENV['LOCALESTATEDIR'] || '/var'
DATADIR = ENV['DATADIR'] || "#{PREFIX}/share"
SYSCONFDIR = ENV['SYSCONFDIR'] || '/etc'
$CFLAGS << ' ${CFLAGS}'
$INCFLAGS << ' ${CFLAGS}'
$LDFLAGS << ' ${LDFLAGS}'
CC = ENV['CC'] || 'gcc'
CFLAGS = "-Wall -Wno-unused -std=gnu99 -fPIC -DCRAFTD_VERSION='\"#{VERSION}\"' -DPACKAGE_STRING='\"craftd #{VERSION}\"' #{ENV['CFLAGS']}"
LDFLAGS = "-export-dynamic #{ENV['LDFLAGS']}"
if ENV['DEBUG']
CFLAGS << ' -g3 -O0 -DCRAFTD_DEBUG'
else
CFLAGS << ' -DNDEBUG -Os'
end
# Stuff building
task :default => ['craftd:build', 'plugins:build']
task :all => ['craftd:build', 'plugins:build', 'scripting:build']
# Stuff installation
task :install => ['craftd:install']
namespace :craftd do |craftd|
craftd.headers = FileList['include/**/*.h']
craftd.sources = FileList['src/**/*.c', 'third-party/bstring/{bstrlib,bstraux}.c']
craftd.libraries = %w(pthread z event event_pthreads pcre ltdl config)
CLEAN.include craftd.sources.ext('o')
CLOBBER.include 'craftd', 'include/craftd/config.h', 'craftd.conf.dist'
craftd.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
desc 'Check for craftd requirements'
task :requirements => 'include/craftd/config.h'
file 'include/craftd/config.h' do
have_library 'ltdl', 'lt_dlopen' or fail 'libtool not found'
# check thread stuff
have_header 'pthread.h' or fail 'pthread-dev not found'
have_library 'pthread' or fail 'pthread not found'
have_func 'pthread_spin_init', 'pthread.h'
# check for libevent 2
have_library 'event' or fail 'libevent2 not found'
have_library 'event_pthreads' or fail 'libevent2 with pthreads not found'
have_macro '((_EVENT_NUMERIC_VERSION >> 24) == 2)', 'event2/event.h' do |c|
c.sub('ifndef', 'if !')
end
# zlib checks
have_header 'zlib.h' or fail 'zlib-dev not found'
have_library 'z' or fail 'zlib not found'
# pcre checks
have_header 'pcre.h' or fail 'libpcre-dev not found'
have_library 'pcre' or fail 'libpcre not found'
# endianness stuff
have_header 'endian.h'
have_header 'sys/endian.h'
have_header 'netinet/in.h'
have_header 'arpa/inet.h'
have_func 'be64toh'
have_func 'htobe64'
check_sizeof 'FUNCTION_POINTER' do |c|
"typedef void(*FUNCTION_POINTER)();\n" + c
end
check_sizeof 'POINTER' do |c|
"typedef void* POINTER;\n" + c
end
have_library 'config' or fail 'libconfig not found'
have_header 'libconfig.h' or fail 'libconfig-dev not found'
# check for libjansson2 for RPC.JSON
if have_header 'jansson.h' and have_library 'jansson' and have_macro '(JANSSON_MAJOR_VERSION == 2)', 'jansson.h' do |c| c.sub('ifndef', 'if !') end
craftd.libraries << global_libs_add('jansson')
$defs << '-DHAVE_JSON'
end
# check for libxml2 for RPC.XML
if have_library 'xml2'
craftd.libraries << global_libs_add('xml2')
$defs << '-DHAVE_XML'
end
create_config 'include/craftd/config.h'
end
file 'craftd' => craftd.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{craftd.sources.ext('o')} -o craftd #{ldflags(craftd.libraries)}"
end
file 'craftd.conf.dist' => 'craftd.conf.dist.in' do
sh %{rm -f craftd.conf.dist craftd.conf.dist.tmp}
sh %{srcdir=''}
sh %{test -f ./craftd.conf.dist.in || srcdir=./;}
sh %{sed \
-e "s|@localstatedir[@]|#{Regexp.escape(LOCALESTATEDIR)}|g" \
-e "s|@datadir[@]|#{Regexp.escape(DATADIR)}|g" \
-e "s|@sysconfdir[@]|#{Regexp.escape(SYSCONFDIR)}|g" \
-e "s|@libdir[@]|#{Regexp.escape(LIBDIR)}|g" \
craftd.conf.dist.in > craftd.conf.dist.tmp}
sh %{mv craftd.conf.dist.tmp craftd.conf.dist}
end
task :build => [:requirements, 'craftd', 'craftd.conf.dist']
task :install => :build
end
namespace :plugins do |plugin|
desc 'Build all plugins'
task :build => ['survival:build']
class << plugin
def file (name)
"#{name}.#{CONFIG['DLEXT']}"
end
end
namespace :survival do |plugin|
class << plugin
def file (name)
"survival.#{name}.#{CONFIG['DLEXT']}"
end
end
task :build => ['httpd:build', 'base:build', 'persistence:build', 'mapgen:build', 'commands:build', 'tests:build']
namespace :base do |base|
base.sources = FileList['plugins/survival/base/main.c']
CLEAN.include base.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('base')}"
base.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('base')}" => base.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{base.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('base')} -o plugins/#{plugin.file('base')} #{ldflags}"
end
desc 'Build SMP base plugin'
task :build => "plugins/#{plugin.file('base')}"
end
namespace :persistence do |persistence|
task :build => ['nbt:build']
namespace :nbt do |nbt|
nbt.cflags = '-Iplugins/survival/persistence/nbt -Iplugins/survival/persistence/nbt/include'
nbt.sources = FileList[
'plugins/survival/persistence/nbt/main.c',
'plugins/survival/persistence/nbt/src/*.c',
'plugins/survival/persistence/nbt/cNBT/nbt_{loading,parsing,treeops,util}.c',
'plugins/survival/persistence/nbt/cNBT/{buffer}.c']
CLEAN.include nbt.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('persistence.nbt')}"
nbt.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude #{nbt.cflags} -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('persistence.nbt')}" => nbt.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{nbt.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('persistence.nbt')} -o plugins/#{plugin.file('persistence.nbt')} #{ldflags}"
end
desc 'Build nbt plugin'
task :build => "plugins/#{plugin.file('persistence.nbt')}"
end
end
namespace :mapgen do |mapgen|
task :build => ['classic:build', 'trivial:build']
namespace :classic do |classic|
classic.cflags = '-Iplugins/survival/mapgen'
classic.sources = FileList['plugins/survival/mapgen/classic/main.c', 'plugins/survival/mapgen/noise/simplexnoise1234.c']
classic.libraries = %w(m)
CLEAN.include classic.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('mapgen.classic')}"
classic.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude #{classic.cflags} -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('mapgen.classic')}" => classic.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{classic.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('persistence.nbt')} -o plugins/#{plugin.file('mapgen.classic')} #{ldflags(classic.libraries)} #{ldflags}"
end
desc 'Build classic mapgen'
task :build => "plugins/#{plugin.file('mapgen.classic')}"
end
namespace :trivial do |trivial|
trivial.sources = FileList['plugins/survival/mapgen/trivial/main.c']
CLEAN.include trivial.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('mapgen.trivial')}"
trivial.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('mapgen.trivial')}" => trivial.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{trivial.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('persistence.nbt')} -o plugins/#{plugin.file('mapgen.trivial')} #{ldflags}"
end
desc 'Build trivial mapgen'
task :build => "plugins/#{plugin.file('mapgen.trivial')}"
end
end
namespace :commands do |commands|
task :build => []#'admin:build']
namespace :admin do |admin|
admin.sources = FileList['plugins/commands/admin/main.c']
CLEAN.include admin.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('commands.admin')}"
admin.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('commands.admin')}" => admin.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{admin.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('commands.admin')} -o plugins/#{plugin.file('commands.admin')}"
end
desc 'Build admin plugin'
task :build => "plugins/#{plugin.file('commands.admin')}"
end
end
namespace :tests do |tests|
tests.cflags = '-Iplugins/survival/tests'
tests.sources = FileList['plugins/survival/tests/main.c', 'plugins/survival/tests/tinytest/tinytest.c']
CLEAN.include tests.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('tests')}"
tests.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude #{tests.cflags} -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('tests')}" => tests.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{tests.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('tests')} -o plugins/#{plugin.file('tests')} #{ldflags}"
end
desc 'Build tests plugin'
task :build => "plugins/#{plugin.file('tests')}"
end
end
namespace :httpd do |httpd|
httpd.sources = FileList['plugins/httpd/main.c', 'plugins/httpd/src/**.c']
CLEAN.include httpd.sources.ext('o')
CLOBBER.include "plugins/#{plugin.file('httpd')}"
httpd.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "plugins/#{plugin.file('httpd')}" => httpd.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{httpd.sources.ext('o')} -shared -Wl,-soname,#{plugin.file('httpd')} -o plugins/#{plugin.file('httpd')} #{ldflags} #{ldflags}"
end
desc 'Build RPC daemon'
task :build => "plugins/#{plugin.file('httpd')}"
end
end
namespace :scripting do |scripting|
desc 'Build all scripting support'
task :build => ['craftd:build', 'lisp:build', 'javascript:build']
class << scripting
def file (name)
"#{name}.#{CONFIG['DLEXT']}"
end
end
namespace :lisp do |lisp|
lisp.sources = FileList['scripting/lisp/main.c']
CLEAN.include lisp.sources.ext('o')
CLOBBER.include "scripting/#{scripting.file('lisp')}", 'scripting/lisp/include/config.h'
lisp.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} $(ecl-config --cflags) -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "scripting/#{scripting.file('lisp')}" => lisp.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{lisp.sources.ext('o')} -shared -Wl,-soname,#{scripting.file('lisp')} -o scripting/#{scripting.file('lisp')} $(ecl-config --ldflags)"
end
desc 'Check for Common LISP requirements'
task :requirements => 'scripting/lisp/include/config.h'
file 'scripting/lisp/include/config.h' do
find_executable('ecl-config') or fail 'ecl-config not found'
create_config 'scripting/lisp/include/config.h'
end
desc 'Build Common LISP scripting'
task :build => [:requirements, "scripting/#{scripting.file('lisp')}"]
end
namespace :javascript do |javascript|
javascript.cflags = '-DXP_UNIX'
javascript.sources = FileList['scripting/javascript/main.c', 'scripting/javascript/src/**.c']
CLEAN.include javascript.sources.ext('o')
CLOBBER.include "scripting/#{scripting.file('javascript')}", 'scripting/javascript/include/config.h'
javascript.sources.each {|f|
file f.ext('o') => c_file(f) do
sh "#{CC} #{CFLAGS} #{javascript.cflags} $(js-config --cflags) -Iinclude -o #{f.ext('o')} -c #{f}"
end
}
file "scripting/#{scripting.file('javascript')}" => javascript.sources.ext('o') do
sh "#{CC} #{CFLAGS} #{javascript.sources.ext('o')} -shared -Wl,-soname,#{scripting.file('javascript')} -o scripting/#{scripting.file('javascript')} $(js-config --libs)"
end
desc 'Check for JavaScript requirements'
task :requirements => 'scripting/javascript/include/config.h'
file 'scripting/javascript/include/config.h' do
find_executable('js-config') or fail 'js-config not found'
have_const 'JS_HAS_CTYPES', 'js-config.h', `js-config --cflags`.strip
create_config 'scripting/javascript/include/config.h'
end
desc 'Build JavaScript scripting'
task :build => [:requirements, "scripting/#{scripting.file('javascript')}"]
end
end