Index: pylib/gyp/generator/ninja.py |
=================================================================== |
--- pylib/gyp/generator/ninja.py (revision 1197) |
+++ pylib/gyp/generator/ninja.py (working copy) |
@@ -42,6 +42,15 @@ |
'RULE_INPUT_NAME': '${name}', |
} |
+# TODO(scottmg): This seems wrong, should be based on flavor. How do we push |
+# these back in later? |
Evan Martin
2012/02/14 19:07:29
See make.py:
def CalculateVariables(default_varia
Nico
2012/02/14 19:14:10
See also the same function in ninja.py :-)
|
+if sys.platform == 'win32': |
+ generator_default_variables['EXECUTABLE_SUFFIX'] = '.exe' |
+ generator_default_variables['STATIC_LIB_PREFIX'] = '' |
+ generator_default_variables['STATIC_LIB_SUFFIX'] = '.lib' |
+ generator_default_variables['SHARED_LIB_PREFIX'] = '' |
+ generator_default_variables['SHARED_LIB_SUFFIX'] = '.dll' |
+ |
# TODO: enable cross compiling once we figure out: |
# - how to not build extra host objects in the non-cross-compile case. |
# - how to decide what the host compiler is (should not just be $cc). |
@@ -76,7 +85,7 @@ |
return path |
# Only need to handle relative paths into subdirectories for now. |
assert '..' not in path, path |
- depth = len(path.split('/')) |
+ depth = len(path.split(os.path.sep)) |
scottmg
2012/02/14 18:58:48
This was *sneaky*! Paths were ../blah instead of .
Evan Martin
2012/02/14 19:07:29
Is there value in allowing us to generate files ac
|
return '/'.join(['..'] * depth) |
@@ -180,6 +189,7 @@ |
self.ninja = ninja_syntax.Writer(output_file) |
self.flavor = flavor |
self.abs_build_dir = abs_build_dir |
+ self.obj_ext = '.obj' if flavor == 'win' else '.o' |
# Relative path from build output dir to base dir. |
self.build_to_base = os.path.join(InvertRelativePath(build_dir), base_dir) |
@@ -348,7 +358,8 @@ |
self.xcode_settings, self.GypPathToNinja, |
lambda path, lang: self.GypPathToUniqueOutput(path + '-' + lang))) |
# Some actions/rules output 'sources' that are already object files. |
- link_deps += [self.GypPathToNinja(f) for f in sources if f.endswith('.o')] |
+ link_deps += [self.GypPathToNinja(f) |
+ for f in sources if f.endswith(self.obj_ext)] |
# Write out a link step, if needed. |
output = None |
@@ -627,7 +638,7 @@ |
# TODO: should we assert here on unexpected extensions? |
continue |
input = self.GypPathToNinja(source) |
- output = self.GypPathToUniqueOutput(filename + '.o') |
+ output = self.GypPathToUniqueOutput(filename + self.obj_ext) |
implicit = precompiled_header.GetObjDependencies([input], [output]) |
self.ninja.build(output, command, input, |
implicit=[gch for _, _, gch in implicit], |
@@ -1004,7 +1015,10 @@ |
gyp.common.CopyTool(flavor, os.path.join(options.toplevel_dir, build_dir)) |
# Grab make settings for CC/CXX. |
- cc, cxx = 'gcc', 'g++' |
+ if flavor == 'win': |
+ cc = cxx = 'cl' |
+ else: |
+ cc, cxx = 'gcc', 'g++' |
build_file, _, _ = gyp.common.ParseQualifiedTarget(target_list[0]) |
make_global_settings = data[build_file].get('make_global_settings', []) |
build_to_root = InvertRelativePath(build_dir) |
@@ -1017,27 +1031,46 @@ |
flock = './gyp-mac-tool flock' |
master_ninja.variable('cc', os.environ.get('CC', cc)) |
master_ninja.variable('cxx', os.environ.get('CXX', cxx)) |
- master_ninja.variable('ld', flock + ' linker.lock $cxx') |
+ if flavor == 'win': |
+ master_ninja.variable('ld', 'link') |
+ else: |
+ master_ninja.variable('ld', flock + ' linker.lock $cxx') |
master_ninja.variable('cc_host', '$cc') |
master_ninja.variable('cxx_host', '$cxx') |
if flavor == 'mac': |
master_ninja.variable('mac_tool', os.path.join('.', 'gyp-mac-tool')) |
master_ninja.newline() |
- master_ninja.rule( |
- 'cc', |
- description='CC $out', |
- command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
- '$cflags_pch_c -c $in -o $out'), |
- depfile='$out.d') |
- master_ninja.rule( |
- 'cxx', |
- description='CXX $out', |
- command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc ' |
- '$cflags_pch_cc -c $in -o $out'), |
- depfile='$out.d') |
- if flavor != 'mac': |
+ if flavor != 'win': |
master_ninja.rule( |
+ 'cc', |
+ description='CC $out', |
+ command=('$cc -MMD -MF $out.d $defines $includes $cflags $cflags_c ' |
+ '$cflags_pch_c -c $in -o $out'), |
+ depfile='$out.d') |
+ master_ninja.rule( |
+ 'cxx', |
+ description='CXX $out', |
+ command=('$cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc ' |
+ '$cflags_pch_cc -c $in -o $out'), |
+ depfile='$out.d') |
+ else: |
+ # TODO(scottmg): Decide how /showIncludes handling should work in ninja. |
+ master_ninja.rule( |
+ 'cc', |
+ description='CC $out', |
+ command=('$cc /nologo $defines $includes $cflags $cflags_c ' |
+ '$cflags_pch_c /c $in /Fo$out'), |
+ depfile='$out.d') |
+ master_ninja.rule( |
+ 'cxx', |
+ description='CXX $out', |
+ command=('$cxx /nologo $defines $includes $cflags $cflags_cc ' |
+ '$cflags_pch_cc /c $in /Fo$out'), |
+ depfile='$out.d') |
+ |
+ if flavor != 'mac' and flavor != 'win': |
+ master_ninja.rule( |
'alink', |
description='AR $out', |
command='rm -f $out && ar rcsT $out $in') |
@@ -1056,6 +1089,23 @@ |
description='LINK $out', |
command=('$ld $ldflags -o $out -Wl,-rpath=\$$ORIGIN/lib ' |
'-Wl,--start-group $in -Wl,--end-group $libs')) |
+ elif flavor == 'win': |
+ master_ninja.rule( |
+ 'alink', |
+ description='AR $out', |
+ command='lib /nologo /OUT:$out.lib $in') |
+ master_ninja.rule( |
+ 'solink', |
+ description='SOLINK $out', |
+ command=('$ld /nologo /DLL $ldflags /OUT:$out.dll $in $libs')) |
+ master_ninja.rule( |
+ 'solink_module', |
+ description='SOLINK(module) $out', |
+ command=('$ld /nologo /DLL $ldflags /OUT:$out.dll $in $libs')) |
+ master_ninja.rule( |
+ 'link', |
+ description='LINK $out', |
+ command=('$ld /nologo $ldflags /OUT:$out.exe $in $libs')) |
else: |
master_ninja.rule( |
'objc', |
@@ -1110,10 +1160,17 @@ |
'stamp', |
description='STAMP $out', |
command='${postbuilds}touch $out') |
- master_ninja.rule( |
- 'copy', |
- description='COPY $in $out', |
- command='ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)') |
+ if flavor == 'win': |
+ # TODO(scottmg): Copy fallback? |
+ master_ninja.rule( |
+ 'copy', |
+ description='COPY $in $out', |
+ command='mklink /h $out $in >nul') |
+ else: |
+ master_ninja.rule( |
+ 'copy', |
+ description='COPY $in $out', |
+ command='ln -f $in $out 2>/dev/null || (rm -rf $out && cp -af $in $out)') |
master_ninja.newline() |
all_targets = set() |