-
Notifications
You must be signed in to change notification settings - Fork 0
/
extconf.rb
259 lines (210 loc) · 7.21 KB
/
extconf.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
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
# utf-8
# frozen-string-literal: false
require_relative '../../lib/ruuuby/version'
require 'mkmf'
if ::RbConfig::CONFIG['host_os'].include?('darwin')
os_compile_target = 'mac'
else
os_compile_target = 'linux'
end
env_f00 = ENV['RUUUBY_F00']
flags_f00 = [false, false]
unless env_f00.nil?
if env_f00.include?('b04')
flags_f00[0] = true
elsif env_f00.include?('b05')
flags_f00[1] = true
end
end
env_f06 = ENV['RUUUBY_F06']
flag_f06_b08 = false
flag_f06_b09 = false
unless env_f06.nil?
if env_f06.include?('b08')
flag_f06_b08 = true
end
if env_f06.include?('b09')
flag_f06_b09 = true
end
end
env_f22 = ENV['RUUUBY_F22']
if env_f22.nil?
flag_f22_b01 = false
flag_f22_b05 = false
flag_f22_b06 = false
flag_f22_b07 = false
else
flag_f22_b01 = env_f22.include?('b01')
flag_f22_b05 = env_f22.include?('b05')
flag_f22_b06 = env_f22.include?('b06')
flag_f22_b07 = env_f22.include?('b07')
end
env_f28 = ENV['RUUUBY_F28']
if env_f28.nil?
flag_f28_b09 = false
else
flag_f28_b09 = env_f28.include?('b09')
end
env_f38 = ENV['RUUUBY_F38']
flag_f38 = false
unless env_f38.nil?
flag_f38 = true
end
env_f92 = ENV['RUUUBY_F92']
flag_f92_b00 = false
flag_f92_b01 = false
flag_f92_b02 = false
flag_f92_b03 = false
unless env_f92.nil?
if env_f92.include?('b00')
flag_f92_b00 = true
end
if env_f92.include?('b01')
flag_f92_b01 = true
end
if env_f92.include?('b02')
flag_f92_b02 = true
end
if env_f92.include?('b02')
flag_f92_b03 = true
end
end
env_f43 = ENV['RUUUBY_F43']
flag_f43 = !env_f43.nil?
env_f93 = ENV['RUUUBY_F93']
if env_f93.nil?
flag_f93 = false
else
flag_f93 = true
end
env_f98 = ENV['RUUUBY_F98']
if env_f98.nil?
env_f98 = 0
else
begin
env_f98 = env_f98.to_i
if env_f98 >= 0 && env_f98 <= 63
flag_debug = env_f98 != 0
flag_timer = env_f98.odd?
flag_memory = (env_f98 & 2) != 0
#flag_ = (env_f98 & 4) != 0
flag_compiler = (env_f98 & 8) != 0
else
raise "not compiling w/ valid ENV{RUUUBY_F98}, expected int between val{0-15}, got{#{env_f98.to_s}}"
end
rescue
raise "not compiling w/ valid ENV{RUUUBY_F98}, expected int between val{0-15}, got{#{env_f98.to_s}}"
end
end
#puts "compiling ruuuby-extensions{#{::Ruuuby::VERSION}} w/ env_f98{#{env_f98.to_s}}"
$VERBOSE = true
$DEBUG = true
the_flags = []
# optimization
the_flags += %w(O3 fgnu89-inline fstrict-enums flto ftree-vectorize fvectorize fzvector)
# etc
the_flags += %w(Wall Wformat fexceptions pipe)
# compiler GNU extensions standard (note: `gnu11` is intentionally used over `c17`)
the_flags += %w(std=gnu11)
# x86_64
the_flags += %w(fPIC malign-double)
path_overlap_ruby = 'rbenv/versions/3.0.0-preview1/include/ruby-3.0.0'
#path_overlap_ruby = 'rbenv/versions/2.7.1/include/2.7.0'
# flags for MacOS only
if os_compile_target == 'mac'
the_flags += %w(fdeclspec)
append_cflags("-include ~/.#{path_overlap_ruby}/x86_64-darwin19/rb_mjit_min_header-3.0.0.h")
append_cflags("-include ~/.#{path_overlap_ruby}/ruby/internal/core/rbasic.h")
append_cflags("-include ~/.#{path_overlap_ruby}/ruby/internal/intern/sprintf.h")
append_cflags("-include ~/.#{path_overlap_ruby}/ruby/internal/core/rdata.h")
the_flags += %w(fapinotes fapple-pragma-pack fblocks ftarget-variant-availability-checks fmacro-backtrace-limit=0 fconstexpr-backtrace-limit=0 nostdinc++ fforce-emit-vtables fwhole-program-vtables mpie-copy-relocations)
else
append_cflags("-include /usr/local/#{path_overlap_ruby}/x86_64-linux-musl/rb_mjit_min_header-3.0.0.h")
append_cflags("-include /usr/local/#{path_overlap_ruby}/ruby/internal/intern/sprintf.h")
end
# utf-8
the_flags += %w(fextended-identifiers finput-charset=UTF-8)
# extra_checks
the_flags += %w(funroll-loops)
the_flags += ["DRUUUBY_F98_DEBUG=#{env_f98.to_s}"] if flag_debug
the_flags += %w(DRUUUBY_F98_TIMER) if flag_timer
if flag_memory
the_flags += %w(DRUUUBY_F98_MEMORY)
the_flags += %w(DRUUUBY_F22_B00)
end
the_flags += %w(DRUUUBY_F98_COMPILER) if flag_compiler
the_flags += %w(DRUUUBY_F00_B04) if flags_f00[0]
the_flags += %w(DRUUUBY_F00_B05) if flags_f00[1]
the_flags += %w(DRUUUBY_F06_B08) if flag_f06_b08
the_flags += %w(DRUUUBY_F06_B09) if flag_f06_b09
the_flags += %w(DRUUUBY_F22_B01) if flag_f22_b01
the_flags += %w(DRUUUBY_F22_B05) if flag_f22_b05
the_flags += %w(DRUUUBY_F22_B06) if flag_f22_b06
the_flags += %w(DRUUUBY_F28_B09) if flag_f28_b09
the_flags += %w(DRUUUBY_F38) if flag_f38
the_flags += %w(DRUUUBY_F43) if flag_f43
the_flags += %w(DRUUUBY_F92_B00) if flag_f92_b00
the_flags += %w(DRUUUBY_F92_B01) if flag_f92_b01
the_flags += %w(DRUUUBY_F92_B02) if flag_f92_b02
the_flags += %w(DRUUUBY_F92_B03) if flag_f92_b03
the_flags += %w(DRUUUBY_F93) if flag_f93
if env_f98 >= 11
the_flags += %w(DRUUUBY_DEBUGGING)
end
# warnings
# Wbad-function-cast
the_flags += %w(Werror Wshadow Wdouble-promotion Wfloat-conversion Wundef fno-common g3
Wmissing-declarations Wmissing-prototypes Wold-style-definition Wdeclaration-after-statement
Wpointer-sign Wparentheses Winit-self Wmissing-include-dirs Wno-switch-bool Wswitch-default Wstrict-aliasing Winit-self)
append_cflags(the_flags.map!{|f| " -#{f}"})
dir_config('ruby_class_mods', [::RbConfig::CONFIG['includedir']], [::RbConfig::CONFIG['libdir']])
headers = []
# for ruby
headers += %w(ruby ruby/assert ruby/debug ruby/defines ruby/encoding ruby/intern ruby/version ruby/missing)
# for ruuuby
headers += %w(00_constants 01_typed_checks 02_extension_memory 03_macro_utilities 04_theta_angle 05_feature_macros 06_time_series_data 07_graphs ruby_class_mods)
# for c
headers += %w(stdio stdlib sys/types string float math tgmath inttypes locale sys/resource) # includes {math, complex}
if flag_timer
headers += %w(time sys/time)
end
if env_f98 >= 11
headers += %w(optional_00_debugging)
headers += %w(optional_01_universal_math_funcs)
headers += %w(optional_02_stats_funcs)
end
headers.each{|header_file| abort("Unable to find header{#{header_file}.h}") unless find_header("#{header_file}.h")}
#if env_f98 != 0
if env_f98 >= 15
({
char: 1,
'unsigned char': 1,
short: 2,
'unsigned short': 2,
int: 4,
'unsigned int': 4,
float: 4,
size_t: 8,
long: 8,
'unsigned long': 8,
'long long': 8,
double: 8,
'long double': 16
}).each do |type, size|
abort("expected sizeof(#{type.to_s}) to be{#{size.to_s}}") unless check_sizeof(type.to_s) == size
end
abort("expected sizeof(ID) to be{8}") unless check_sizeof('ID') == 8
(1..9).each do |n|
abort("Unable to find const{#{n}} in header{c0_constants.h}") unless have_const("ℤ#{n.to_s}", 'c0_constants.h')
abort("Unable to find const{#{n}} in header{c0_constants.h}") unless have_const("ℤn#{n.to_s}", 'c0_constants.h')
end
abort("Unable to find const{ℤ0} in header{c0_constants.h}") unless have_const("ℤ0", 'c0_constants.h')
end
abort("missing macro{M_SQRT2}") unless have_macro('M_SQRT2')
abort unless have_macro('RBIMPL_COMPILER_IS_CLANG_H')
abort unless have_macro('RBIMPL_COMPILER_IS_APPLE_H')
abort unless have_macro('RBIMPL_COMPILER_IS_MSVC_H')
abort unless have_macro('RBIMPL_COMPILER_IS_SUNPRO_H')
abort unless have_macro('RBIMPL_COMPILER_IS_INTEL_H')
abort unless have_macro('RBIMPL_COMPILER_IS_GCC_H')
create_makefile('ruby_class_mods')