This repository was archived by the owner on Jun 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
267 lines (232 loc) · 6.74 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
require 'rake'
require 'rake/clean'
require 'rbconfig'
require 'digest/md5'
require 'fileutils'
include RbConfig
include FileUtils
module FileUtils
def fu_output_message(msg)
puts msg if $verbose
end
end
module OS
def OS.windows?
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
end
def OS.mac?
(/darwin/ =~ RUBY_PLATFORM) != nil
end
def OS.unix?
!OS.windows?
end
def OS.linux?
OS.unix? and not OS.mac?
end
end
RakeFileUtils.verbose_flag = false
OBJ_DIR = 'obj'
SO_DIR = 'lib/sfml'
DOC_DIR = 'doc'
EXT_DIR = './ext'
INST_DIR = File.join(CONFIG['sitearchdir'], "sfml")
SFML_INC = ENV['SFML_INCLUDE']
SFML_LIB = ENV['SFML_LIB']
GLEW_INC = ENV['GLEW_INCLUDE']
GLEW_LIB = ENV['GLEW_LIB']
RUBY_INC = CONFIG['rubyhdrdir']
RUBY_LIB = CONFIG['libdir']
RUBY_LINK = CONFIG['SOLIBS'] + (CONFIG['ENABLE_SHARED'] == 'yes' ? CONFIG['LIBRUBYARG_SHARED'] : CONFIG['LIBRUBYARG_STATIC'])
CXX = CONFIG['CXX']
CXXFLAGS = "-std=c++11 #{SFML_INC ? "-I#{SFML_INC}" : ''} #{GLEW_INC ? "-I#{GLEW_INC}" : ''} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -DGLEW_BUILD"
LINK = CONFIG['LDSHAREDXX'].sub("$(if $(filter-out -g -g0,#{CONFIG['debugflags']}),,-s)", "")
LINK_FLAGS = "#{CONFIG['DLDFLAGS']} #{CONFIG['LDFLAGS']} #{SFML_LIB ? "-L#{SFML_LIB}" : ''} #{GLEW_LIB ? "-L#{GLEW_LIB}" : ''} -L#{RUBY_LIB} #{RUBY_LINK}".sub("$(DEFFILE)", "")
SRCS = {:rbsfml => FileList.new("#{EXT_DIR}/rbsfml/*.cpp")}
SHARED = []
LIBS = []
OBJS = {}
SRCS.each_key {|file| LIBS << "#{SO_DIR}/#{file}.#{CONFIG['DLEXT']}"}
CLEAN.include(OBJ_DIR)
CLOBBER.include(SO_DIR)
CLOBBER.include(DOC_DIR)
desc "Turn on verbose mode."
task :verbose do
$verbose = true
CXXFLAGS << " -Wall -Wextra "
puts RUBY_DESCRIPTION
puts ""
puts "OBJ_DIR = #{OBJ_DIR.inspect}"
puts "SO_DIR = #{SO_DIR.inspect}"
puts "DOC_DIR = #{DOC_DIR.inspect}"
puts "EXT_DIR = #{EXT_DIR.inspect}"
puts "INST_DIR = #{INST_DIR.inspect} (#{"not " unless File.exist?(INST_DIR)}found)"
puts ""
puts "SFML_INC = #{SFML_INC.inspect} (#{"not " unless File.exist?(SFML_INC)}found)"
puts "SFML_LIB = #{SFML_LIB.inspect} (#{"not " unless File.exist?(SFML_LIB)}found)"
puts ""
puts "GLEW_INC = #{GLEW_INC.inspect} (#{"not " unless File.exist?(GLEW_INC)}found)"
puts "GLEW_LIB = #{GLEW_LIB.inspect} (#{"not " unless File.exist?(GLEW_LIB)}found)"
puts ""
puts "RUBY_INC = #{RUBY_INC.inspect} (#{"not " unless File.exist?(RUBY_INC)}found)"
puts "RUBY_LIB = #{RUBY_LIB.inspect} (#{"not " unless File.exist?(RUBY_LIB)}found)"
puts "RUBY_LINK = #{RUBY_LINK.inspect}"
puts ""
puts "CXX = #{CXX.inspect}"
puts "CXXFLAGS = #{CXXFLAGS.inspect}"
puts ""
puts "LINK = #{LINK.inspect}"
puts "LINK_FLAGS = #{LINK_FLAGS.inspect}"
puts ""
end
def calc_md5(src)
list = SRCS[src]
OBJS[src] = []
list.each do |file|
code = File.read(file)
digest = Digest::MD5.hexdigest(code)
s = ".s" if ARGV.include? "static"
OBJS[src] << "#{OBJ_DIR}/#{File.basename(file)}.#{digest}#{s}.o"
end
#if src == :sfml
# OBJS[:sfml] += OBJS[:audio] + OBJS[:graphics] + OBJS[:window] + OBJS[:system]
#end
end
def compile_o(src)
calc_md5(src)
mkdir_p OBJ_DIR
defines = []
defines << "SFML_STATIC" if ARGV.include? "static"
#if ARGV.include? "sfml"
# defines << "RBSFML_SYSTEM"
# defines << "RBSFML_WINDOW"
# defines << "RBSFML_GRAPHICS"
# defines << "RBSFML_AUDIO"
# defines << "RBSFML_SFML"
#else
# defines << "RBSFML_#{src.to_s.upcase}"
#end
d = defines.map{|m|"-D#{m}"}.join(" ")
SRCS[src].each_with_index do |file, i|
obj = OBJS[src][i]
next if File.exist?(obj)
puts "Compiling #{file}"
sh "#{CXX} #{CXXFLAGS} -c #{file} -o #{obj} #{d}"
end
end
def create_so(src)
so = "#{SO_DIR}/#{src}.#{CONFIG['DLEXT']}"
mkdir_p SO_DIR
puts "Creating #{so}"
objs = OBJS[src].join(" ")
s = "-s" if ARGV.include? "static"
sfml_link = case src
# when :audio; "-lsfml-audio#{s} -lsfml-system#{s}"
# when :graphics; "-lsfml-graphics#{s} -lsfml-window#{s} -lsfml-system#{s}"
# when :window; "-lsfml-window#{s} -lsfml-system#{s}"
# when :system; "-lsfml-system#{s}"
# when :sfml; "-lsfml-audio#{s} -lsfml-graphics#{s} -lsfml-window#{s} -lsfml-system#{s}"
when :rbsfml; "-lsfml-audio#{s} -lsfml-graphics#{s} -lsfml-window#{s} -lsfml-system#{s}"
end
if ARGV.include? "static"
external_link = "-lfreetype -ljpeg "
external_link += "-lglew -lGL -lopenal" unless OS.windows?
external_link += "-lglew32 -lgdi32 -lopengl32 -lopenal32 -lwinmm" if OS.windows?
end
sh "#{LINK} #{objs} -o #{so} #{LINK_FLAGS} #{sfml_link} #{external_link}"
end
task :default => [:rbsfml]
desc "Link statically against SFML."
task :static do
unless ARGV.any? {|arg| ["rbsfml"].include? arg }
ARGV << "rbsfml"
Rake::Task["rbsfml"].invoke
end
end
#desc "Build all modules."
#task :all => [:system, :window, :graphics, :audio, :extra] do
# compile_o(:all)
# create_so(:all)
#end
#desc "Build audio module (audio.#{CONFIG['DLEXT']})."
#task :audio => [:system] do
# SRCS[:audio] += SHARED
# compile_o(:audio)
# create_so(:audio)
#end
#desc "Build graphics module (graphics.#{CONFIG['DLEXT']})."
#task :graphics => [:system, :window] do
# SRCS[:graphics] += SHARED
# compile_o(:graphics)
# create_so(:graphics)
#end
#desc "Build window module (window.#{CONFIG['DLEXT']})."
#task :window => [:system] do
# SRCS[:window] += SHARED
# compile_o(:window)
# create_so(:window)
#end
#desc "Build system module (system.#{CONFIG['DLEXT']})."
#task :system do
# SRCS[:system] += SHARED
# compile_o(:system)
# create_so(:system)
#end
#desc "Build all modules as a single file (sfml.#{CONFIG['DLEXT']})."
#task :sfml do
# SRCS[:sfml] += SHARED
# compile_o(:system)
# compile_o(:window)
# compile_o(:graphics)
# compile_o(:audio)
# compile_o(:sfml)
# create_so(:sfml)
#end
desc "Build all modules as a single file (rbsfml.#{CONFIG['DLEXT']})."
task :rbsfml do
SRCS[:rbsfml] += SHARED
compile_o(:rbsfml)
create_so(:rbsfml)
end
desc "Install rbSFML."
task :install => [:uninstall] do
mkdir_p SO_DIR
list = FileList.new("#{SO_DIR}/*.#{CONFIG['DLEXT']}")
if list.size == 0
puts "Nothing to install."
else
mkdir_p INST_DIR
puts "Installing library to #{INST_DIR}"
list.each do |file|
puts "Installing #{file}..."
copy_file(file, File.join(INST_DIR, File.basename(file)))
end
end
end
desc "Uninstall rbSFML."
task :uninstall do
if !File.exist?(INST_DIR)
puts "Nothing to uninstall."
else
puts "Uninstalling library from #{INST_DIR}"
remove_dir(INST_DIR, true)
end
end
desc "Run tests."
task :test do
ARGV.replace []
if $verbose
ARGV << "-v"
end
sh "rspec spec"
end
desc "Run samples."
task :samples do
cd "samples"
Dir.entries(".").select{|e| e =~ /\.rb$/ }.each do |sample|
ruby("#{sample}", verbose: true) { }
end
end
desc "Build Ruby Gem."
task :gem => [:rbsfml] do
sh 'gem build rbsfml.gemspec'
end