Skip to content

Commit

Permalink
Add --enable-debug-build option to extconf.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 2, 2021
1 parent 35dec6c commit e0498e6
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ext/fiddle/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@

# :stopdoc:

def gcc?
RbConfig::CONFIG["GCC"] == "yes"
end

def disable_optimization_build_flag(flags)
if gcc?
expanded_flags = RbConfig.expand(flags.dup)
optimization_option_pattern = /(^|\s)?-O\d(\s|$)?/
if optimization_option_pattern.match?(expanded_flags)
expanded_flags.gsub(optimization_option_pattern, '\\1-Og\\2')
else
flags + " -Og"
end
else
flags
end
end

def enable_debug_build_flag(flags)
if gcc?
expanded_flags = RbConfig.expand(flags.dup)
debug_option_pattern = /(^|\s)-g(?:gdb)?\d?(\s|$)/
if debug_option_pattern.match?(expanded_flags)
expanded_flags.gsub(debug_option_pattern, '\\1-ggdb3\\2')
else
flags + " -ggdb3"
end
else
flags
end
end

checking_for(checking_message("--enable-debug-build option")) do
enable_debug_build = enable_config("debug-build", false)
if enable_debug_build
$CFLAGS = disable_optimization_build_flag($CFLAGS)
$CFLAGS = enable_debug_build_flag($CFLAGS)
end
enable_debug_build
end

libffi_version = nil
have_libffi = false
bundle = enable_config('bundled-libffi')
Expand Down

0 comments on commit e0498e6

Please sign in to comment.