forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.rb
98 lines (82 loc) · 2.5 KB
/
c.rb
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
# C related tasks
require "rake-tasks/files.rb"
def dll(args)
deps = build_deps_(args[:deps])
Array(args[:out]).each do |result|
out = "build/#{result}"
file out => build_deps_(args[:src]) + deps do
if (out =~ /\.dll$/)
msbuild_legacy(args[:solution], out, args[:prebuilt])
elsif (out =~ /\.so$/)
is_32_bit = "amd64" != args[:arch]
gcc(args[:src], out, args[:args], args[:link_args], is_32_bit, args[:prebuilt])
else
puts "Cannot compile #{args[:out]}"
exit -1
end
end
# TODO(simon): Yuck. Not Good Enough
task "#{args[:name]}" => out
task args[:out] => out
Rake::Task[args[:name]].out = "#{out}"
end
end
def msbuild_legacy(solution, out, prebuilt)
if msbuild_installed?
if (!File.exists? out) then
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=x64", :verbose => false
sh "MSBuild.exe #{solution} /verbosity:q /target:Rebuild /property:Configuration=Release /property:Platform=Win32", :verbose => false
copy_to_prebuilt(out, prebuilt)
end
else
copy_prebuilt(prebuilt, out)
end
end
def gcc(srcs, out, args, link_args, is_32_bit, prebuilt)
if !gcc?
copy_prebuilt(prebuilt, out)
return
end
obj_dir = "#{out}_temp/obj" + (is_32_bit ? "32" : "64")
mkdir_p obj_dir
is_cpp_code = false
srcs.each do |src|
ok = gccbuild_c(src, obj_dir, args, is_32_bit)
if (!ok)
copy_prebuilt(prebuilt, out)
return
end
if (src =~ /\.cpp$/)
is_cpp_code = true
end
end
flags = "-Wall -shared -fPIC -Os -fshort-wchar "
flags += (is_32_bit ? "-m32 " : "-m64 ")
flags += " " + link_args + " " if link_args
# if we've made it this far, try to link. If link fails,
# copy from prebuilt.
linker = is_cpp_code ? "g++" : "gcc"
linker_cmd = "#{linker} -o #{out} #{obj_dir}/*.o #{flags}"
sh linker_cmd do |link_ok, res|
if (!link_ok)
copy_prebuilt(prebuilt, out)
return
end
end
copy_to_prebuilt(out, prebuilt)
rm_rf "#{out}_temp"
end
def gccbuild_c(src_file, obj_dir, args, is_32_bit)
compiler = src_file =~ /\.c$/ ? "gcc" : "g++"
objname = src_file.split('/')[-1].sub(/\.c[p{2}]*?$/, ".o")
cmd = "#{compiler} #{src_file} -Wall -c -fshort-wchar -fPIC -o #{obj_dir}/#{objname} "
cmd += (is_32_bit ? " -m32" : " -m64")
cmd += args if args
sh cmd do |ok, res|
if !ok
puts "Unable to build. Aborting compilation"
return false
end
end
true
end