[前][次][番号順一覧][スレッド一覧]

ruby-changes:66250

From: Sutou <ko1@a...>
Date: Tue, 18 May 2021 12:49:05 +0900 (JST)
Subject: [ruby-changes:66250] 4d1bb460f6 (master): [ruby/fiddle] Add --enable-debug-build option to extconf.rb

https://git.ruby-lang.org/ruby.git/commit/?id=4d1bb460f6

From 4d1bb460f64eafacc2ef8c4116a1bbe7e63e732f Mon Sep 17 00:00:00 2001
From: Sutou Kouhei <kou@c...>
Date: Sun, 3 Jan 2021 06:17:56 +0900
Subject: [ruby/fiddle] Add --enable-debug-build option to extconf.rb

https://github.com/ruby/fiddle/commit/e0498e60ea
---
 ext/fiddle/extconf.rb | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb
index 6d1d510..562b758 100644
--- a/ext/fiddle/extconf.rb
+++ b/ext/fiddle/extconf.rb
@@ -3,6 +3,47 @@ require 'mkmf' https://github.com/ruby/ruby/blob/trunk/ext/fiddle/extconf.rb#L3
 
 # :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')
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]