-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
88 lines (73 loc) · 2.32 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
unless File.exists?('config.yaml') && File.exists?('config.h')
STDERR.puts "Please run 'ruby configure' first"
abort
end
require 'rbconfig'
require 'rake/clean'
root = File.expand_path File.dirname(__FILE__)
begin
require 'psych'
rescue LoadError
ensure
require 'yaml'
end
begin
config = YAML.load_file File.join(root, 'config.yaml')
rescue ::Exception
abort 'Unable to parse config.yaml, exiting...'
end
# load rake helper tasks
Dir.glob("#{root}/rakelib/**/*.rake").sort.each do |lib|
puts "Loading #{File.basename(lib)}" if Rake.application.options.trace
load lib
end
def windows?
$windows ||= RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
end
def dev_null
windows? ? 'NUL' : '/dev/null'
end
def ext(fn, newext)
fn.sub(/\.[^.]+$/, newext)
end
SRCFILES = Rake::FileList['src/*.c']
OBJFILES = SRCFILES.map { |f| File.basename ext(f, '.o') }
# FIXME why isn't config.yaml being deleted?
CLEAN.concat OBJFILES
CLOBBER.include('config.h', 'config.yaml', config[:APPNAME])
OBJFILES.each do |obj|
src = File.join('src', ext(obj, '.c'))
file obj => src do |t|
cmd = %[#{config[:shell]} "#{config[:cc]} ]
cmd << %[#{$opts[:defines]} ]
cmd << %[-Wall #{$opts[:optflags]} #{$opts[:debugflags]} ]
cmd << %[-I. #{$opts[:inc_dirs]} -c -o #{t.name} #{t.prerequisites.join}"]
sh cmd
end
end
task :settings => ['config.yaml'] do |t|
$opts = {
:inc_dirs => config[:include_dirs].map { |i| "-I#{i}" }.join(' '),
:lib_dirs => config[:library_dirs].map { |i| "-L#{i}" }.join(' '),
}
$opts[:defines] = config[:defines].map { |i| "-D#{i}" }.join(' ') if config[:defines]
$opts[:optflags] = config[:optflags].map { |i| "-#{i}" }.join(' ') if config[:optflags]
$opts[:debugflags] = config[:debugflags].map { |i| "-#{i}" }.join(' ') if config[:debugflags]
end
file config[:APPNAME] => OBJFILES do |t|
cmd = %[#{config[:shell]} "#{config[:cc]} ]
cmd << %[-Wall #{$opts[:optflags]} #{$opts[:debugflags]} ]
cmd << %[#{$opts[:lib_dirs]} ]
cmd << %[#{config[:strip_all]} -o #{t.name} #{t.prerequisites.join(' ')} ]
cmd << %[#{config[:libs]}"]
sh cmd
end
desc "Build #{config[:APPNAME]} v#{config[:VERSION]}"
task :build => [:settings, config[:APPNAME]] do |t|
unless ENV['NOUPX']
if system("upx -h > #{dev_null} 2>&1")
system("upx -9 #{config[:APPNAME]}")
end
end
end
task :default => [:build]