updated architecture detection for MRI 2.0
[voodoo-lang.git] / lib / voodoo / config.rb.in
blob672bc2013272b9759ff2d886ecf1211ef6755599
1 #! /usr/bin/env ruby
3 # Ruby program to generate config.rb
5 default_architecture = ENV['DEFAULT_ARCHITECTURE']
6 default_format = ENV['DEFAULT_FORMAT']
7 gas_command = ENV['GAS'] || 'as'
8 nasm_command = ENV['NASM'] || ENV['YASM'] || 'nasm'
9 version = open(File.join(File.dirname(__FILE__), '..', '..', 'VERSION')) { |f|
10 f.read }
12 print <<EOT
13 module Voodoo
14 # Methods to get and set configuration parameters
15 module Config
16 IMPLEMENTATION_NAME = 'Voodoo Compiler'
17 IMPLEMENTATION_VERSION = '#{version.chop}'
19 # Class that holds configuration parameters
20 class Configuration
21 def initialize
22 @default_architecture = #{default_architecture.to_sym.inspect}
23 @default_format = #{default_format.to_sym.inspect}
24 @gas_command = #{gas_command.inspect}
25 @nasm_command = #{nasm_command.inspect}
26 end
28 attr_accessor :default_format,
29 :gas_command,
30 :nasm_command
32 attr_writer :default_architecture
34 # Returns the default architecture for this compiler
35 def default_architecture
36 if @default_architecture == :auto
37 # If @default_architecture has been set to :auto,
38 # return the host architecture, falling back to :i386
39 # if the host architecture cannot be determined
40 host_architecture || :i386
41 else
42 @default_architecture
43 end
44 end
46 # Returns the architecture of the machine running the program,
47 # or nil if that architecture cannot be determined
48 def host_architecture
49 arch, = RUBY_PLATFORM.split '-'
50 case arch
51 when 'x86_64', 'amd64'
52 :amd64
53 when /^arm/
54 :arm
55 when 'i386', 'i686'
56 :i386
57 when 'mips'
58 :mips
59 when 'mipsel'
60 :mipsel
61 else
62 nil
63 end
64 end
65 end
67 DEFAULT_CONFIGURATION = Configuration.new
69 module_function
71 EOT
73 [:default_architecture,
74 :default_format,
75 :gas_command,
76 :nasm_command
77 ].each do |symbol|
78 print <<EOT
79 def #{symbol}
80 DEFAULT_CONFIGURATION.#{symbol}
81 end
83 def #{symbol}= value
84 DEFAULT_CONFIGURATION.#{symbol} = value
85 end
86 EOT
87 end
89 print <<EOT
90 end
91 end
92 EOT