-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
95 lines (67 loc) · 2.01 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
require 'rake'
require 'rake/clean'
require 'rspec/core/rake_task'
CC = "clang"
CFLAGS = "-std=c99 -ggdb -Wall -fpic"
LDFLAGS = "-lm"
TARGET = "libstrcmp.so"
SOURCE_DIR = "src"
OBJECT_DIR = "build"
LIBRARY_DIR = "lib"
INCLUDE_DIR = "include"
SOURCE_FILES = FileList.new("#{SOURCE_DIR}/**/*.c") do |fl|
fl.exclude(/metaphone/)
end
desc "Default task builds project"
task :default => :build
desc "Use bundler to install necessary gems"
task :bundle => "Gemfile" do
sh "bundle install"
end
CLOBBER.include("Gemfile.lock")
desc "Compile and link source files into a shared object file"
task :build => :link do
# grab relavent header
header = File.join(SOURCE_DIR, "strcmp.h")
# create include dir
mkdir_p INCLUDE_DIR
# copy headers into include dir
cp(header, INCLUDE_DIR)
end
CLOBBER.include(INCLUDE_DIR)
desc "Compile source files to object files"
task :compile
SOURCE_FILES.each do |source|
# replace source dir with object dir
object = source.gsub(/^#{SOURCE_DIR}/, "#{OBJECT_DIR}")
object = object.sub(/\.c$/, '.o')
# create file task for each source
file object => source do
# create directory
mkdir_p object.pathmap("%d").strip
# compile source
sh "#{CC} #{CFLAGS} -I./#{SOURCE_DIR} -c -o #{object} #{source}"
end
# add file task to :objects
task :compile => object
end
CLEAN.include('**/*.o', 'build')
desc "Link compiled object files to a shared object file (library)"
task :link => :compile do
# find all object files in build
objects = FileList["#{OBJECT_DIR}/**/*.o"].join(' ')
# create lib
mkdir_p LIBRARY_DIR
# link
output = File.join(LIBRARY_DIR, TARGET)
sh "#{CC} #{LDFLAGS} #{objects} -shared -o #{output}"
end
CLOBBER.include(LIBRARY_DIR)
desc "Runs the RSpec test suite"
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
desc "Installs library and related documentation"
task :install
desc "Uninstalls library and related documentation"
task :uninstall