forked from rubinius/rubinius
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·2270 lines (1862 loc) · 59.9 KB
/
configure
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env ruby
require 'rubygems'
require 'bundler/setup'
require './rakelib/configure'
require './rakelib/release'
require './rakelib/build_signature'
require 'rbconfig'
require 'tempfile'
require 'fileutils'
require 'stringio'
require 'date'
require 'digest/md5'
require 'net/http'
require 'gems'
require 'redcard'
module Rubinius
BUILD_CONFIG = {}
end
root = File.expand_path File.dirname(__FILE__)
require File.join(root, "kernel", "delta", "options")
class Configure
# Default settings only. All code that may depend on user-selected options
# must run after options are processed.
def initialize(root)
@log = Logger.new "configure.log"
@command_line = ARGV.dup
@log.log "Command line: #{@command_line.join(" ").inspect}"
@features = {}
@defines = []
@config = File.join(root, "config.rb")
@config_in = File.join(root, "config.rb.in")
# Platform settings
@host = `sh -c ./rakelib/config.guess`.chomp
@cpu = nil
@vendor = nil
@os = nil
@windows = nil
@darwin = nil
@bsd = nil
@linux = nil
@little_endian = false
@sizeof = {}
# Build tools
@cc = nil
@cxx = nil
@make = nil
@rake = nil
@tar = nil
@perl = nil
@gem = nil
# LLVM settings
@use_llvm = true
@llvm = :no
@llvm_path = nil
@llvm_configure = nil
@llvm_skip_system = false
@llvm_skip_prebuilt = false
@llvm_prebuilt_name = nil
@llvm_system_name = get_system_name
@llvm_shared = false
@llvm_version = "3.2"
@llvm_api_version = 302
@llvm_source = "llvm-3.2.tgz"
@llvm_source_dir = "llvm-3.2.src"
@llvm_source_url = "http://llvm.org/releases/3.2/llvm-3.2.src.tar.gz"
@llvm_asset_path = "http://asset.rubini.us/prebuilt"
@llvm_source_build = false
@llvm_generic_prebuilt = nil
@need_update_prebuilt = false
@llvm_parent_path = File.join(root, "vendor")
@llvm_default = File.join(@llvm_parent_path, "llvm")
@llvm_prebuilt_path = File.join(@llvm_parent_path, "prebuilt")
@llvm_include_path = File.join(@llvm_default, "include")
# System settings
@libc = nil
@x86_32 = false
@x86_64 = false
@fibers = false
@dtrace = false
@have_lchmod = false
@have_lchown = false
@include_dirs = []
@lib_dirs = []
# File system paths
@sourcedir = root
@prefixdir = nil
@bindir = nil
@appdir = nil
@libdir = nil
@encdir = nil
@runtimedir = nil
@kerneldir = nil
@sitedir = nil
@vendordir = nil
@mandir = nil
@gemsdir = nil
@includedir = nil
@stagingdir = nil
@build_prefix = nil
@capi_includedir = "#{@sourcedir}/vm/include/capi"
@runtime_gems_dir = nil
@bootstrap_gems_dir = nil
@vm_release_h = root + "/vm/gen/release.h"
@preserve_prefix = false
@program_name = "rbx"
@bin_links = ["rbx", "ruby", "rake", "gem", "irb", "rdoc", "ri", "erb"]
@use_bin_links = true
# Gems
#
# Rubinius build tools
@build_tool_gems = [
[ "rubinius-ast", "2.0" ],
[ "rubinius-compiler", "2.0" ],
[ "rubinius-melbourne", "2.0" ],
[ "rubinius-processor", "2.0" ],
[ "rubinius-toolset", "0.1" ],
]
# Standard library gems for building gem C-extensions
@build_c_ext_gems = [
[ "ffi2-generators", "0.1" ],
[ "rubysl-etc", "2.0" ],
[ "rubysl-fileutils", "2.0" ],
[ "rubysl-mkmf", "2.0" ],
[ "rubysl-shellwords", "2.0" ]
]
# Standard library gems to bootstrap rubygems and Bundler
@bootstrap_gems = [
[ "rubysl-date", "2.0" ],
[ "rubysl-delegate", "2.0" ],
[ "rubysl-digest", "2.0" ],
[ "rubysl-etc", "2.0" ],
[ "rubysl-fcntl", "2.0" ],
[ "rubysl-fileutils", "2.0" ],
[ "rubysl-monitor", "2.0" ],
[ "rubysl-openssl", "2.0" ],
[ "rubysl-optparse", "2.0" ],
[ "rubysl-stringio", "2.0" ],
[ "rubysl-strscan", "2.0" ],
[ "rubysl-tempfile", "2.0" ],
[ "rubysl-thread", "2.0" ],
[ "rubysl-tmpdir", "2.0" ],
[ "rubysl-uri", "2.0" ],
[ "rubysl-yaml", "2.0" ],
[ "rubysl-zlib", "2.0" ]
]
# Preinstalled runtime gems
@runtime_gems = [
[ "json", "1.8" ],
[ "rake", "10.1" ],
[ "rdoc", "4.0" ],
[ "ffi2-generators", "0.1" ],
[ "rubinius-profiler", "2.0" ],
[ "rubinius-coverage", "2.0" ],
[ "rubinius-debugger", "2.0" ],
]
@gems_cache = File.expand_path "../vendor/cache", __FILE__
FileUtils.mkdir_p @gems_cache
# Vendored library settings
@vendored_libdir = root + "/vendor"
# Essential settings (modify these for creating releases)
@ruby_version = "2.1.0"
@libversion = "2.2"
@patch_version = "5"
@release_date = nil
# Configure settings
@release_build = !git_directory
@release_config = false
end
# Set up system commands to run in cmd.exe on Windows. Either Windows
# or MRI on Windows has issues with subprocesses where the invocation
# of the subprocess will return before the subprocess has finished.
# This manifests in configure when uncompressing LLVM source returns
# but attempting to move the directory fails sporadically with an access
# exception. Adding the, essentially no-op, 'sleep 0' resolves this.
def msys_system(cmd)
old_system %[cmd.exe /C "#{cmd} && sleep 0"]
end
def msys_backquote(cmd)
old_backquote %[cmd.exe /C "#{cmd}"]
end
def expand(path)
File.expand_path(path)
end
def expand_install_dir(dir)
dir = expand dir
if !@preserve_prefix and File.directory?(dir) and dir !~ /(rubinius|rbx).*\/?$/
original = dir
dir += "/rubinius/#{@libversion}"
@log.write "The directory #{original} already exists, installing to #{dir}"
end
dir
end
def set_host
/([^-]+)-([^-]+)-(.*)/ =~ @host
@cpu, @vendor, @os = $1, $2, $3
# TODO: For better cross-compiling support, it may be necessary to
# use the feature facility to check for a define in the compiler.
@windows = (@host =~ /mingw|mswin/) != nil
@darwin = (@host =~ /darwin/) != nil
@bsd = (@host =~ /bsd/) != nil
@linux = (@host =~ /linux/) != nil
end
def set_system_commands
# Set up system commands to run in cmd.exe on Windows.
if @windows
alias :old_system :system
alias :old_backquote :`
alias :system :msys_system
alias :` :msys_backquote
end
end
def set_filesystem_paths
@prefixdir = @prefixdir ? expand_install_dir(@prefixdir) : @sourcedir
if @appdir
dir = expand_install_dir @appdir
@libdir = dir + "/library"
@runtimedir = dir + "/runtime"
@kerneldir = dir + "/kernel"
@sitedir = dir + "/site"
@vendordir = dir + "/vendor"
end
@bindir = @prefixdir + "/bin" unless @bindir
@libdir = @prefixdir + "/library" unless @libdir
@runtimedir = @prefixdir + "/runtime" unless @runtimedir
@kerneldir = @prefixdir + "/kernel" unless @kerneldir
@sitedir = @prefixdir + "/site" unless @sitedir
@vendordir = @prefixdir + "/vendor" unless @vendordir
@mandir = @prefixdir + "/man" unless @mandir
@gemsdir = @prefixdir + "/gems" unless @gemsdir
@includedir = @prefixdir + "/vm/include/capi" unless @includedir
@encdir = @libdir + "/encoding/converter"
dirs = [@bindir, @libdir, @runtimedir, @kerneldir, @sitedir, @vendordir,
@mandir, @gemsdir, @includedir, @encdir]
parts = dirs.map { |d| d.split "/" }
i = 0
total = parts[0].size
prefix = []
while i < total
part = parts[0][i]
break unless parts.all? { |p| p[i] == part }
prefix << part
i += 1
end
@prefixdir = prefix.join "/"
size = @prefixdir.size
dirs.each { |d| d.replace d[size..-1] }
unless @prefixdir == @sourcedir
@stagingdir ||= "#{@sourcedir}/staging"
FileUtils.rm_rf @stagingdir
@stagingdir = File.join @stagingdir, @prefixdir if @preserve_prefix
FileUtils.mkdir_p @stagingdir
end
@build_prefix = @stagingdir || @sourcedir
@bootstrap_gems_dir ||= "#{@sourcedir}/bootstrap/gems"
@runtime_gems_dir ||= "#{@build_prefix}#{@runtimedir}/gems"
end
def options
@options = Rubinius::Options.new "Usage: configure [options]", 30
o = @options
o.left_align
o.doc " Configure settings"
o.on "--log-file", "NAME", "Write log to file NAME" do |name|
old_log = @log.path
@log = Logger.new name, false
@log.replace old_log
end
o.on "--make", "NAME", "Use NAME as 'make' during build" do |name|
@make = name
end
o.on "--rake", "NAME", "Use NAME as 'rake' during build" do |name|
@rake = name
end
o.on "--tar", "NAME", "Use NAME as 'tar'" do |name|
@tar = name
end
o.on "--perl", "NAME", "Use NAME as 'perl' during build" do |name|
@perl = name
end
o.on "--gem", "NAME", "Use NAME as 'gem' during build" do |name|
@gem = name
end
o.on "--release-build", "Build from local files instead of accessing the network" do
@release_build = true
end
o.on "--release-config", "Write configuration settings for release builds" do
@release_config = true
end
o.doc "\n Compiler settings"
o.on "--cc", "COMPILER", "Compiler to use for C code (eg gcc, clang)" do |cc|
@cc = cc
end
o.on "--cxx", "COMPILER", "Compiler to use for C++ code (eg g++, clang++)" do |cxx|
@cxx = cxx
end
o.doc "\n LLVM settings"
o.on "--disable-llvm", "Don't build with LLVM" do
@use_llvm = false
end
o.on "--enable-llvm", "Enable llvm (default)" do
@use_llvm = true
end
o.on "--skip-system", "Don't consider a system LLVM installation" do
@llvm_skip_system = true
end
o.on "--skip-prebuilt", "Don't try to use a prebuilt version of LLVM" do
@llvm_skip_prebuilt = true
end
o.on "--system-name", "NAME", "Name of OS (eg fedora-8, ubuntu-10.04)" do |name|
@llvm_system_name = name
end
o.on "--prebuilt-name", "NAME", "Full name of LLVM prebuilt archive" do |name|
@llvm_prebuilt_name = name
end
o.on "--llvm-path", "PATH", "File system path to the directory containing LLVM" do |dir|
@llvm_path = dir.dup
end
o.on "--llvm-config", "PROGRAM", "File system path to the llvm-config program" do |program|
@llvm_configure = program
end
o.on "--llvm-shared", "Link to shared LLVM library" do
@llvm_shared = true
end
o.on "--update-prebuilt", "Update prebuilt LLVM packages from the internet" do
@need_update_prebuilt = true
end
o.doc "\n System settings"
o.on "--with-include-dir", "DIR", "Add DIR to the default include search paths" do |dir|
dir.split(File::PATH_SEPARATOR).each do |d|
@include_dirs << d
end
end
o.on "--with-lib-dir", "DIR", "Add DIR to the default library search paths" do |dir|
dir.split(File::PATH_SEPARATOR).each do |d|
@lib_dirs << d
end
end
o.on "--with-opt-dir", "DIR", "Add DIR/include and DIR/lib to include and library search paths" do |dir|
dir.split(File::PATH_SEPARATOR).each do |d|
@include_dirs << "#{d}/include"
@lib_dirs << "#{d}/lib" << "#{d}/lib64"
end
end
o.on "--libc", "NAME", "Use NAME as the libc for FFI" do |name|
@libc = name
end
o.on "--host", "HOST", "Override guessed platform with HOST specification" do |host|
@log.write "------------------------------------------------------"
@log.write "\nChanging the platform specification can cause Rubinius"
@log.write "to malfunction. The current platform specification is:"
@log.write "\n#{@host}"
@log.write "\n------------------------------------------------------"
@host = host
end
o.doc "\n Program names"
o.on "--program-name", "NAME", "Build Rubinius executable as NAME" do |name|
@program_name = name
end
o.on "--bin-link", "NAME", "Create NAME as binary symlink to program name" do |name|
@bin_links << name
end
o.on "--no-bin-links", "Do not create any symlinks to program name" do
@use_bin_links = false
end
o.doc "\n File system paths for installing Rubinius"
o.on "-P", "--prefix", "PATH", "Install Rubinius in subdirectories of PATH" do |dir|
warn_prefix dir
@prefixdir = dir.dup
end
o.on "-B", "--bindir", "PATH", "Install Rubinius executable in PATH" do |dir|
@bindir = expand dir
end
o.on "-I", "--includedir", "PATH", "Install Rubinius C-API include files in PATH" do |dir|
@includedir = expand dir
end
o.on "-A", "--appdir", "PATH", "Install Ruby runtime and libraries in PATH" do |dir|
@appdir = dir.dup
end
o.on "-L", "--libdir", "PATH", "Install Rubinius shared library in PATH" do |dir|
@libdir = dir.dup
end
o.on "-M", "--mandir", "PATH", "Install man pages in PATH" do |dir|
@mandir = expand dir
end
o.on "-G", "--gemsdir", "PATH", "Install gems in PATH" do |dir|
@gemsdir = expand dir
end
o.on "--sitedir", "PATH", "Install site-specific Ruby code in PATH" do |dir|
@sitedir = expand dir
end
o.on "--vendordir", "PATH", "Install vendor-specific Ruby code in PATH" do |dir|
@vendordir = expand dir
end
o.on "--preserve-prefix", "Use the configure prefix for staging Rubinius to install" do
@preserve_prefix = true
end
o.on "--stagingdir", "PATH", "Use PATH to build and prepare all files for install" do |dir|
@stagingdir = expand dir
end
o.doc "\n Optional features"
feature "stdlib", true
feature "execinfo", true
feature "vendor-zlib", false
feature "alloc-tracking", false
feature "fibers", true
feature "dtrace", false
feature "rpath", true
o.doc "\n Help!"
o.on "--show", "Print the current configuration and exit" do
print_debug
exit 0
end
o.on "-V", "--verbose", "Print additional info" do
@verbose = true
end
o.help
o.doc ""
end
def feature(name, default_value=true)
@features[name] = ConfigurationToggle.new default_value
@options.on "--with-#{name}", "Enable #{name}" do
@features[name].configured = true
end
@options.on "--without-#{name}", "Disable #{name}" do
@features[name].configured = false
end
end
def parse(ary)
@options.parse ary
end
def version
version = "#{@libversion}.#{@patch_version}"
version += ".n#{Time.now.strftime("%j").to_i}" unless @release_date
version
end
def normalize_version(str)
version = str.gsub(/[^\d]/, "")
unless @supported_versions.include? version
failure <<-EOM
Unsupported language version requested: #{version}. Options are #{@supported_versions.join(", ")}
EOM
end
version
end
def md5_checksum(md5_path, full_path)
return Digest::MD5.file(full_path).hexdigest == File.read(md5_path).strip.split(" ").first
end
def download(url, full_path, follows=0)
begin
dir = File.dirname full_path
Dir.mkdir dir unless File.exist? dir
uri = url.kind_of?(URI) ? url : URI(url)
if ENV['http_proxy']
protocol, userinfo, p_host, p_port = URI::split(ENV['http_proxy'])
p_user, p_pass = userinfo.split(/:/) if userinfo
http = Net::HTTP.new(uri.host, uri.port, p_host, p_port, p_user, p_pass)
else
http = Net::HTTP.new(uri.host, uri.port)
end
http.use_ssl = true if uri.scheme == 'https'
request = Net::HTTP::Get.new(uri.request_uri)
http.request(request) do |res|
case res
when Net::HTTPNotFound
@log.write " #{url} not found."
return false
when Net::HTTPMovedPermanently,
Net::HTTPFound,
Net::HTTPSeeOther,
Net::HTTPTemporaryRedirect
if follows > 3
@log.write " ERROR: too many redirects: #{url}"
return false
end
return download URI.parse(res['Location']), full_path, follows + 1
when Net::HTTPClientError
@log.write " ERROR: #{res.inspect}"
return false
end
size = 0
total = res.header['Content-Length'].to_i
@log.write " Downloading #{File.basename(full_path)}..."
File.open full_path, "wb" do |f|
res.read_body do |chunk|
f << chunk
size += chunk.size
print "\r [ %d%% (%d of %d) ]" % [(size * 100) / total, size, total]
end
end
@log.write ": done!"
end
rescue Interrupt
File.unlink full_path if File.exist?(full_path)
raise
rescue StandardError => e
File.unlink full_path if File.exist?(full_path)
@log.write " ERROR: #{e.message}"
return false
end
return true
end
# Downloads a pre-built LLVM library for a platform if the file exists. If
# an MD5 checksum file exists for the library, the checksum of the library
# is compared and the update fails if it does not match. If no MD5 checksum
# file exists, the library is used without check.
def update_prebuilt(file, warn)
full_path = File.join @llvm_prebuilt_path, file
md5_path = "#{full_path}.md5"
dir = File.dirname full_path
Dir.mkdir dir unless File.exist? dir
url = File.join @llvm_asset_path, file
unless File.exist? full_path
download url, full_path
unless File.exist? full_path
@log.write "ERROR. No #{file} available on server." if warn
return false
end
end
md5_url = "#{url}.md5"
download md5_url, md5_path
if File.exist? md5_path
unless md5_checksum md5_path, full_path
@log.write "ERROR. #{file} was corrupted or MD5 checksum is outdated."
return false
else
@log.write " MD5 checksum for prebuilt LLVM verified."
end
else
@log.write " No MD5 checksum for #{file} available on server."
@log.write " Using LLVM library without checksum validation."
end
@log.write " Prebuilt packages updated."
end
def verify_llvm_source
return false unless File.exist? @llvm_default
if File.exist?(@llvm_include_path)
@llvm = :svn
@llvm_configure = llvm_config_cmd "#{@llvm_default}/Release/bin/llvm-config"
return true
else
@log.write " Code doesn't appear to be proper LLVM tree!"
return false
end
end
def setup_source
@log.print " Checking for existing LLVM source tree:"
# Check if source already exists
if verify_llvm_source
@log.write " found!"
return true
else
@log.write " not found."
end
url = @llvm_source_url
path = File.join @llvm_prebuilt_path, @llvm_source
unless File.exist?(path)
@log.write " Downloading #{url}..."
return false unless download(url, path)
end
if File.exist?(path)
@log.print " Unpacking LLVM source: "
Dir.chdir @llvm_parent_path do
succeeded = system "#{@tar} xzf #{path}"
unless succeeded
@log.write "Error failed unpacking: #{path}"
return false
end
FileUtils.mv @llvm_source_dir, "llvm"
end
@log.write "done!"
if verify_llvm_source
@log.write " Code appears to be a proper tree."
@llvm_source_build = true
return true
end
end
end
def prebuilt_files
files = [@llvm_generic_prebuilt]
# If we have a system name, try to find a prebuilt specifically
# for this system first.
if @llvm_system_name
files.unshift "llvm-#{@llvm_version}-#{@host}-#{@llvm_system_name}.tar.bz2"
end
# Try one for just the darwin major version (which increases for each
# minor OS X version. ie. 10.5 == 9.x.x, 10.6 == 10.x.x)
if m = /darwin(\d+)\.(\d+)\.(\d+)/.match(@os)
# Try this last
files.push "llvm-#{@llvm_version}-#{@cpu}-#{@vendor}-darwin#{m[1]}.tar.bz2"
end
# If the user specified a name, try that before anything.
files.unshift @llvm_prebuilt_name if @llvm_prebuilt_name
files
end
def setup_prebuilt
@log.write " Checking for prebuilt LLVM package..."
prebuilt_files.each do |file|
path = File.join @llvm_prebuilt_path, file
update_prebuilt file, false unless File.exist?(path)
if File.exist?(path)
@log.print " Unpacking prebuilt LLVM: #{file}: "
dir = File.join @llvm_parent_path, "llvm"
FileUtils.mkdir_p dir
Dir.chdir dir do
system "#{@tar} xjf #{path}"
end
@log.write "done!"
@llvm = :prebuilt
@llvm_configure = llvm_config_cmd "#{dir}/Release/bin/llvm-config"
return true
end
end
@log.write " Unable to download any LLVM prebuilt"
return false
end
def setup_path
@log.print " Checking for '#{@llvm_path}': "
if File.directory? @llvm_path
["Release", "Debug", ""].each do |which|
sub = File.join(@llvm_path, which, "bin")
if File.directory? sub
config = File.join(@llvm_path, which, "bin", "llvm-config")
version = `#{config} --version`.strip
parts = version.sub(/svn$/, "").split(".").map { |i| i.to_i }
api_version = ("%d%02d" % parts[0..1]).to_i
if version >= "3.0"
@log.write "found!"
@llvm = :config
@llvm_version = version
@llvm_api_version = api_version
@llvm_configure = llvm_config_cmd config
return true
else
@log.write "outdated (version #{version})"
return false
end
end
end
@log.write "ERROR. Doesn't appear to be built already!"
return false
end
@log.write "ERROR. Path doesn't exist."
return false
end
def remove_default
if File.exist?(File.join(@llvm_default, "Makefile.common"))
failure "ABORT: Unwilling to override custom LLVM tree, please update it manually."
else
@log.write " Removing outdated tree..."
FileUtils.rm_rf(@llvm_default)
end
end
def llvm_options_exist?
!@llvm_skip_system and @llvm_configure
end
def setup_auto
update_prebuilt @llvm_generic_prebuilt, true if @need_update_prebuilt
@log.print " Checking for existing LLVM library tree: "
if File.directory?("#{@llvm_default}/Release") and
not llvm_options_exist?
config = llvm_config_cmd "#{@llvm_default}/Release/bin/llvm-config"
version = `#{config} --version`.strip
parts = version.sub(/svn$/, "").split(".").map { |i| i.to_i }
api_version = ("%d%02d" % parts[0..1]).to_i
if version >= "3.0"
@log.write "found!"
if File.exist?(File.join(@llvm_default, "Makefile.common"))
@llvm = :svn
else
@llvm = :prebuilt
end
@llvm_version = version
@llvm_api_version = api_version
@llvm_configure = config
return
else
@log.write "outdated (version #{version})"
remove_default
end
else
if llvm_options_exist?
@log.write "skipping due to explicit LLVM options."
else
@log.write "not found."
end
end
# If they explicitly said where LLVM is, use that and fail hard.
if @llvm_path
unless setup_path
failure "ABORT: Path '#{@llvm_path}' not a proper LLVM path."
end
return
end
return if !@llvm_skip_system && setup_config
return if !@llvm_skip_prebuilt && setup_prebuilt
return if setup_source
@log.write "WARNING: Unable to configure for LLVM, disabling support."
@use_llvm = false
end
def setup_config
@log.print " Checking for 'llvm-config': "
config = @llvm_configure
if !config
which = ENV['PATH'].split(":").find do |path|
File.exist? File.join(path, "llvm-config")
end
if which
config = File.join(which, "llvm-config")
end
end
if config
config_cmd = llvm_config_cmd config
begin
version = `#{config_cmd} --version`.strip
# Ruby 1.8 returns an empty string
failed = true if version.empty?
rescue Errno::ENOENT
# Ruby 1.9 raises this error
failed = true
end
if failed
@log.write "Executing #{config_cmd.inspect} failed"
return false
end
parts = version.sub(/svn$/, "").split(".").map { |i| i.to_i }
api_version = ("%d%02d" % parts[0..1]).to_i
if api_version < 300
@log.write "only LLVM 3.x is supported"
else
@log.write "found! (version #{version} - api: #{api_version})"
@llvm = :config
@llvm_configure = config_cmd
@llvm_version = version
@llvm_api_version = api_version
return true
end
else
@log.write "not found"
end
false
end
def env(which)
ENV[which] || ""
end
def default_link_libs
libs = []
unless @host =~ /haiku/
libs << "m"
end
libs
end
def failure(message=nil)
@log.error message if message
STDERR.puts "\nRunning 'configure' failed. Please check configure.log for more details."
exit 1
end
def check_tools
@cc ||= ENV['CC'] || 'gcc'
@cxx ||= ENV['CXX'] || 'g++'
check_tool_version @cc, '-dumpversion', [4, 1]
check_tool_version @cxx, '-dumpversion', [4, 1]
check_tool_version 'bison', '--version', [2, 3]
@make ||= ENV['MAKE'] || 'make'
@rake ||= ENV['RAKE'] || 'rake'
@tar ||= ENV['TAR'] || (@windows ? 'bsdtar' : 'tar')
@perl ||= ENV['PERL'] || 'perl'
@gem ||= ENV['GEM'] || 'gem'
@gcc_major = `#{@cc} -dumpversion`.strip.split(".")[0,2].join(".")
if @host == "i686-pc-linux-gnu" || @host == "x86_64-unknown-linux-gnu"
@llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}-#{@gcc_major}.tar.bz2"
else
@llvm_generic_prebuilt = "llvm-#{@llvm_version}-#{@host}.tar.bz2"
end
@system_cflags = ""
@system_cxxflags = ""
@system_cppflags = ""
@system_ldflags = ""
@user_cflags = ENV['CFLAGS']
@user_cxxflags = ENV['CXXFLAGS']
@user_cppflags = ENV['CPPFLAGS']
@user_ldflags = ENV['LDFLAGS']
setup_platform
end
def setup_platform
@ldsharedxx = "#{@cxx} -shared"
@ldshared = "#{@cc} -shared"
@include_dirs.each do |d|
@system_cflags << "-I#{d} "
end
@lib_dirs.each do |d|
@system_ldflags << "-L#{d} "
end
case RUBY_PLATFORM
when /mswin/i, /mingw/i, /bccwin32/i
# TODO: discovery helpers
#check_heads(%w[windows.h winsock.h], true)
#check_libs(%w[kernel32 rpcrt4 gdi32], true)
unless RUBY_PLATFORM =~ /mingw/
@system_cflags << "-EHs -GR"
end
@system_ldflags << "-lws2_32"
@features["rpath"].configured = false
when /solaris/i
# GNU CHAIN only supported
@ldsharedxx = "#{@cxx} -shared -G -fPIC -lstdc++"
@ldshared = "#{@cc} -shared -G -fPIC"
@system_cflags << "-fPIC -Wno-strict-aliasing"
@system_ldflags << "-lsocket -lnsl -fPIC"
@features["rpath"].configured = false
@make = "gmake"
when /freebsd/i
@ldsharedxx = "#{@cxx} -shared -fPIC"
@ldshared = "#{@cc} -shared -fPIC"
@system_cflags << "-fPIC"
@system_ldflags << "-lcrypt -pthread -rdynamic"
@make = "gmake"
when /openbsd/i
# OpenBSD branch contributed by Guillaume Sellier.
# on Unix we need a g++ link, not gcc. On OpenBSD, linking against
# libstdc++ have to be explicitly done for shared libs
@ldsharedxx = "#{@cxx} -shared -lstdc++ -fPIC"
@ldshared = "#{@cc} -shared -fPIC"
@system_cflags << "-fPIC"
@system_ldflags << "-pthread -rdynamic -Wl,--export-dynamic"