Skip to content

Commit e0498e6

Browse files
committed
Add --enable-debug-build option to extconf.rb
1 parent 35dec6c commit e0498e6

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

ext/fiddle/extconf.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,47 @@
33

44
# :stopdoc:
55

6+
def gcc?
7+
RbConfig::CONFIG["GCC"] == "yes"
8+
end
9+
10+
def disable_optimization_build_flag(flags)
11+
if gcc?
12+
expanded_flags = RbConfig.expand(flags.dup)
13+
optimization_option_pattern = /(^|\s)?-O\d(\s|$)?/
14+
if optimization_option_pattern.match?(expanded_flags)
15+
expanded_flags.gsub(optimization_option_pattern, '\\1-Og\\2')
16+
else
17+
flags + " -Og"
18+
end
19+
else
20+
flags
21+
end
22+
end
23+
24+
def enable_debug_build_flag(flags)
25+
if gcc?
26+
expanded_flags = RbConfig.expand(flags.dup)
27+
debug_option_pattern = /(^|\s)-g(?:gdb)?\d?(\s|$)/
28+
if debug_option_pattern.match?(expanded_flags)
29+
expanded_flags.gsub(debug_option_pattern, '\\1-ggdb3\\2')
30+
else
31+
flags + " -ggdb3"
32+
end
33+
else
34+
flags
35+
end
36+
end
37+
38+
checking_for(checking_message("--enable-debug-build option")) do
39+
enable_debug_build = enable_config("debug-build", false)
40+
if enable_debug_build
41+
$CFLAGS = disable_optimization_build_flag($CFLAGS)
42+
$CFLAGS = enable_debug_build_flag($CFLAGS)
43+
end
44+
enable_debug_build
45+
end
46+
647
libffi_version = nil
748
have_libffi = false
849
bundle = enable_config('bundled-libffi')

0 commit comments

Comments
 (0)