configure: respect the --dest-os flag consistently
authorNathan Rajlich <nathan@tootallnate.net>
Tue, 21 May 2013 16:26:42 +0000 (09:26 -0700)
committerNathan Rajlich <nathan@tootallnate.net>
Wed, 22 May 2013 01:38:11 +0000 (18:38 -0700)
Consider a user on his Mac, who wants to cross-compile for his Linux ARM device:

    ./configure --dest-cpu=arm --dest-os=linux

Before this patch, for example, DTrace probes would incorrectly attempt to be
enabled because the configure script is running on a MacOS machine, even though
we're trying to compile a binary for `linux`.

With this patch, the `--dest-os` flag is respected throughout the configure
script, thus leaving DTrace probes disabled in this cross-compiling scenario.

configure

index 09f3c40..4747dd2 100755 (executable)
--- a/configure
+++ b/configure
@@ -10,7 +10,8 @@ import sys
 CC = os.environ.get('CC', 'cc')
 
 root_dir = os.path.dirname(__file__)
-sys.path.insert(0, os.path.join(root_dir, 'deps', 'v8', 'tools'))
+sys.path.insert(0, os.path.join(root_dir, 'tools', 'gyp', 'pylib'))
+from gyp.common import GetFlavor
 
 # parse our options
 parser = optparse.OptionParser()
@@ -236,7 +237,7 @@ parser.add_option("--dest-os",
     action="store",
     dest="dest_os",
     help="Operating system to build for. Valid values are: "
-         "win, mac, solaris, freebsd, linux")
+         "win, mac, solaris, freebsd, openbsd, linux")
 
 parser.add_option("--no-ifaddrs",
     action="store_true",
@@ -468,16 +469,16 @@ def configure_node(o):
   # By default, enable DTrace on SunOS systems. Don't allow it on other
   # systems, since it won't work.  (The MacOS build process is different than
   # SunOS, and we haven't implemented it.)
-  if sys.platform.startswith('sunos') or sys.platform.startswith('darwin'):
+  if flavor in ('solaris', 'mac'):
     o['variables']['node_use_dtrace'] = b(not options.without_dtrace)
-  elif sys.platform.startswith('linux'):
+  elif flavor == 'linux':
     o['variables']['node_use_dtrace'] = 'false'
     o['variables']['node_use_systemtap'] = b(options.with_dtrace)
     if options.systemtap_includes:
       o['include_dirs'] += [options.systemtap_includes]
   elif options.with_dtrace:
     raise Exception(
-       'DTrace is currently only supported on SunOS or Linux systems.')
+       'DTrace is currently only supported on SunOS, MacOS or Linux systems.')
   else:
     o['variables']['node_use_dtrace'] = 'false'
     o['variables']['node_use_systemtap'] = 'false'
@@ -486,7 +487,7 @@ def configure_node(o):
     o['defines'] += ['SUNOS_NO_IFADDRS']
 
   # By default, enable ETW on Windows.
-  if sys.platform.startswith('win32'):
+  if flavor == 'win':
     o['variables']['node_use_etw'] = b(not options.without_etw);
   elif options.with_etw:
     raise Exception('ETW is only supported on Windows.')
@@ -494,7 +495,7 @@ def configure_node(o):
     o['variables']['node_use_etw'] = 'false'
 
   # By default, enable Performance counters on Windows.
-  if sys.platform.startswith('win32'):
+  if flavor == 'win':
     o['variables']['node_use_perfctr'] = b(not options.without_perfctr);
   elif options.with_perfctr:
     raise Exception('Performance counter is only supported on Windows.')
@@ -607,7 +608,7 @@ def configure_openssl(o):
 
 
 def configure_winsdk(o):
-  if not sys.platform.startswith('win32'):
+  if flavor != 'win':
     return
 
   winsdk_dir = os.environ.get("WindowsSdkDir")
@@ -620,6 +621,13 @@ def configure_winsdk(o):
   print "ctrpp not found in WinSDK path--using pre-gen files from tools/msvs/genfiles."
 
 
+# determine the "flavor" (operating system) we're building for,
+# leveraging gyp's GetFlavor function
+flavor_params = {};
+if (options.dest_os):
+  flavor_params['flavor'] = options.dest_os;
+flavor = GetFlavor(flavor_params);
+
 output = {
   'variables': { 'python': sys.executable },
   'include_dirs': [],
@@ -668,14 +676,12 @@ write('config.mk',
       '# Do not edit. Generated by the configure script.\n' + config)
 
 if options.use_ninja:
-  gyp_args = ['-f', 'ninja']
+  gyp_args = ['-f', 'ninja-' + flavor]
 elif options.use_xcode:
   gyp_args = ['-f', 'xcode']
-elif os.name == 'nt':
+elif flavor == 'win':
   gyp_args = ['-f', 'msvs', '-G', 'msvs_version=auto']
-elif options.dest_os:
-  gyp_args = ['-f', 'make-' + options.dest_os]
 else:
-  gyp_args = ['-f', 'make']
+  gyp_args = ['-f', 'make-' + flavor]
 
 subprocess.call([sys.executable, 'tools/gyp_node'] + gyp_args)