-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
67 lines (48 loc) · 1.23 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
require 'rake'
require 'rake/clean'
require 'tmpdir'
CFLAGS = "-Wall -Werror-implicit-function-declaration -std=c11 -Iinclude #{ENV['CFLAGS']}"
SOURCES = FileList['sources/*.c']
OBJECTS = SOURCES.ext('o')
CLEAN.include(OBJECTS)
CLOBBER.include('hash.a', 'hash.h')
task :default => :build
task :build, :mode do |t, args|
mode = (args[:mode] || :debug).to_sym
if mode == :debug
CFLAGS << ' -O0 -g3'
else
CFLAGS << ' -g0 -O3 -funroll-loops -finline-functions -DNDEBUG'
end
Rake::Task['build:hash'].invoke
end
namespace :build do
task :hash => ['hash.a', 'hash.h']
file 'hash.a' => OBJECTS do
sh "ar rcs hash.a #{OBJECTS}"
end
file 'hash.h' => FileList['include/*.h'] do
header = File.read('include/common.h')
%w[siphash crapwow murmur3].each {|name|
header << File.read("include/#{name}.h").sub(/\A.*\*\/\n/m, '')
}
File.open('hash.h', 'w') {|f|
f.puts(header)
}
end
end
task :test => 'test:run'
namespace :test do
task :build => 'test/run'
task :run => 'test:build' do
sh 'test/run'
end
file 'test/run' => ['run.c', 'hash.a', 'hash.h'] do
sh "clang #{CFLAGS} -I. -o test/run test/run.c hash.a"
end
file 'run.c'
end
rule '.o' => '.c' do |t|
sh "clang #{CFLAGS} -o #{t.name} -c #{t.source}"
end
rule '.h'