-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·163 lines (122 loc) · 4.34 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
#!/usr/bin/env ruby
require 'rbconfig'
begin
require 'psych'
rescue LoadError
ensure
require 'yaml'
end
root = File.expand_path File.dirname(__FILE__)
# pull in helper libs
Dir.glob(File.join(root, 'lib', '*.rb')).each do |f|
require f
end
class Configure
BUILD_CONFIG = { :VERSION => '0.2.0', :APPNAME => 'xval' }
def initialize(root)
@config = File.join(root, 'config.yaml')
@config_h = File.join(root, 'config.h')
@defines = [ 'HAVE_CONFIG_H' ]
# TODO add /usr/local/lib and /usr/local/include?
@include_dirs = [
'C:/devlibs/libxml2/include/libxml2',
'C:/devlibs/lua52/include'
]
@library_dirs = [
'C:/devlibs/libxml2/lib',
'C:/devlibs/lua52/lib'
]
@opts = Trollop.options do
banner <<-EOT
usage: ruby configure [options]
libxml2 options:
EOT
opt :with_xml2_include, 'libxml2 header directory', :type => :string, :short => :none
opt :with_xml2_lib, 'libxml2 library directory', :type => :string, :short => :none
banner <<-EOT
liblua options:
EOT
opt :with_lua_include, 'liblua header directory', :type => :string, :short => :none
opt :with_lua_lib, 'liblua library directory', :type => :string, :short => :none
opt :lua_libname, 'libname sans prefix', :short => :none, :default => 'lua52'
banner <<-EOT
compiler toolkit options:
EOT
opt :cc, 'C compiler', :short => :none, :default => 'gcc'
opt :defines, 'preprocessor definitions', :type => :strings, :short => :d
opt :optflags, 'optimization settings', :type => :strings, :short => :o, :default => ['O3']
opt :debugflags, 'debug settings', :type => :strings, :short => :g
banner <<-EOT
general options:
EOT
opt :chatty_build, 'build app with verbose messages', :short => :none
end
end
def process_env
BUILD_CONFIG[:APPNAME] << '.exe' if windows?
@cc = ENV['CC'] || 'gcc'
cpath = normalize_path ENV['CPATH'] if ENV['CPATH']
@include_dirs.unshift(cpath).flatten! if cpath
lib_path = normalize_path ENV['LIBRARY_PATH'] if ENV['LIBRARY_PATH']
@library_dirs.unshift(lib_path).flatten! if lib_path
end
def process_args
@cc = @opts[:cc] if @opts[:cc_given]
@defines << 'NDEBUG' unless @opts[:chatty_build_given]
@defines.concat @opts[:defines] if @opts[:defines_given]
{ :with_xml2_include => :with_xml2_include_given,
:with_lua_include => :with_lua_include_given }.each do |k,v|
cpath = normalize_path @opts[k] if @opts[v]
@include_dirs.unshift(cpath).flatten! if cpath
end
{ :with_xml2_lib => :with_xml2_lib_given,
:with_lua_lib => :with_lua_lib_given }.each do |k,v|
lib_path = normalize_path @opts[k] if @opts[v]
@library_dirs.unshift(lib_path).flatten! if lib_path
end
end
def make_config
BUILD_CONFIG[:shell] = windows? ? 'cmd.exe /c' : 'sh -c'
BUILD_CONFIG[:cc] = @cc
BUILD_CONFIG[:defines] = @defines unless @defines.empty?
BUILD_CONFIG[:optflags] = @opts[:optflags] unless @opts[:optflags].empty?
BUILD_CONFIG[:debugflags] = @opts[:debugflags] if @opts[:debugflags]
BUILD_CONFIG[:strip_all] = '-s' unless @opts[:debugflags]
BUILD_CONFIG[:include_dirs] = @include_dirs
BUILD_CONFIG[:library_dirs] = @library_dirs
BUILD_CONFIG[:libs] = windows? ?
"-Wl,-static -lxml2 -l#{@opts[:lua_libname]} -Wl,-dy,--as-needed -lws2_32" :
"-Wl,-static -lxml2 -l#{@opts[:lua_libname]} -Wl,-dy,--as-needed -ldl -lc -lm -lz"
end
def write_config
File.open(@config, 'wb') do |f|
f.puts BUILD_CONFIG.to_yaml
end
File.open(@config_h, 'wb') do |f|
version_triple = BUILD_CONFIG[:VERSION].split(/\./)
f.puts <<-EOT
/* config.h. Generated from configure. */
#define XVALID_VERSION_MAJOR #{version_triple[0]}
#define XVALID_VERSION_MINOR #{version_triple[1]}
#define XVALID_VERSION_PATCH #{version_triple[2]}
#define XVALID_VERSION_STRING "#{BUILD_CONFIG[:VERSION]}"
EOT
f.puts '#define XVALID_CHATTY_BUILD 1' if @opts[:chatty_build]
end
end
def call
process_env
process_args
make_config
write_config
end
private
def normalize_path(path)
dir_sep = windows? ? /;/ : /:/
path.gsub('\\', File::SEPARATOR).split(dir_sep)
end
def windows?
@windows ||= RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
end
end
Configure.new(root).call