build/gen.py: Add --no-strip option.

This option is useful to build a release executable that can be
used with profiling tools like valgrind / callgrind, in order
to analyze and improve GN's performance.

R=thakis@chromium.org, juliehokett@google.com

Bug: NONE
Change-Id: I302f027284b8f500772270092137957eaa0942f5
Reviewed-on: https://gn-review.googlesource.com/c/3660
Reviewed-by: Scott Graham <scottmg@google.com>
Reviewed-by: Scott Graham <scottmg@chromium.org>
Commit-Queue: Scott Graham <scottmg@chromium.org>
diff --git a/build/gen.py b/build/gen.py
index 7a53a80..0ee66e2 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -89,6 +89,8 @@
                     help='Do not generate last_commit_position.h.')
   parser.add_option('--out-path',
                     help='The path to generate the build files in.')
+  parser.add_option('--no-strip', action='store_true',
+                    help='Don\'t strip release build. Useful for profiling.')
   options, args = parser.parse_args(argv)
 
   if args:
@@ -275,6 +277,8 @@
     else:
       cflags.append('-DNDEBUG')
       cflags.append('-O3')
+      if options.no_strip:
+        cflags.append('-g')
       ldflags.append('-O3')
       # Use -fdata-sections and -ffunction-sections to place each function
       # or data item into its own section so --gc-sections can eliminate any
@@ -288,12 +292,13 @@
         ldflags.append('-Wl,--gc-sections')
 
       # Omit all symbol information from the output file.
-      if platform.is_darwin():
-        ldflags.append('-Wl,-S')
-      elif platform.is_aix():
-        ldflags.append('-Wl,-s')
-      else:
-        ldflags.append('-Wl,-strip-all')
+      if options.no_strip is None:
+        if platform.is_darwin():
+          ldflags.append('-Wl,-S')
+        elif platform.is_aix():
+          ldflags.append('-Wl,-s')
+        else:
+          ldflags.append('-Wl,-strip-all')
 
       # Enable identical code-folding.
       if options.use_icf: