summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xgen-build-file.py78
1 files changed, 52 insertions, 26 deletions
diff --git a/gen-build-file.py b/gen-build-file.py
index fb83b20..c0f58c7 100755
--- a/gen-build-file.py
+++ b/gen-build-file.py
@@ -25,6 +25,16 @@ sys.path.insert(0, 'misc')
import ninja
+platform = os.environ.get('NINJA_PLATFORM', sys.platform)
+if platform.startswith('linux'):
+ platform = 'linux'
+elif platform.startswith('freebsd'):
+ platform = 'freebsd'
+elif platform.startswith('mingw'):
+ platform = 'mingw'
+elif platform.startswith('win'):
+ platform = 'windows'
+
n = ninja.Writer(sys.stdout)
n.comment('This file is used to build ninja itself.')
n.comment('It is generated by ' + os.path.basename(__file__) + '.')
@@ -38,12 +48,20 @@ def cxx(name, **kwargs):
return n.build(built(name + '.o'), 'cxx', src(name + '.cc'), **kwargs)
n.variable('builddir', 'build')
-n.variable('cxx', os.environ.get('CC', 'g++'))
-cflags = ('-O2 -g -Wall -Wno-deprecated -fno-exceptions -fvisibility=hidden '
- '-pipe')
+
+cflags = ['-O2', '-g', '-Wall', '-Wno-deprecated', '-fno-exceptions',
+ '-fvisibility=hidden', '-pipe']
+if platform == 'mingw':
+ n.variable('cxx', 'i586-mingw32msvc-c++')
+ # "warning: visibility attribute not supported in this
+ # configuration; ignored"
+ cflags.remove('-fvisibility=hidden')
+else:
+ n.variable('cxx', os.environ.get('CC', 'g++'))
if 'CFLAGS' in os.environ:
- cflags += ' ' + os.environ['CFLAGS']
-n.variable('cflags', cflags)
+ cflags.append(os.environ['CFLAGS'])
+n.variable('cflags', ' '.join(cflags))
+
n.variable('ldflags', os.environ.get('LDFLAGS', ''))
n.newline()
@@ -53,43 +71,51 @@ n.rule('cxx',
description='CC $out')
n.newline()
+ar = 'ar'
+if platform == 'mingw':
+ ar = 'i586-mingw32msvc-ar'
n.rule('ar',
- command='ar crs $out $in',
+ command=ar + ' crs $out $in',
description='AR $out')
n.newline()
n.rule('link',
- command='$cxx $ldflags -o $out $in',
+ command='$cxx $ldflags -o $out $in $libs',
description='LINK $out')
n.newline()
-n.comment('browse_py.h is used to inline browse.py.')
-n.rule('inline',
- command='src/inline.sh $varname < $in > $out',
- description='INLINE $out')
-n.build(built('browse_py.h'), 'inline', src('browse.py'),
- variables=[('varname', 'kBrowsePy')])
-n.newline()
-
objs = []
-n.comment("TODO: this shouldn't need to depend on inline.sh.")
-objs += cxx('browse',
- implicit='src/inline.sh',
- order_only=built('browse_py.h'))
-n.newline()
+if platform not in ('mingw'):
+ n.comment('browse_py.h is used to inline browse.py.')
+ n.rule('inline',
+ command='src/inline.sh $varname < $in > $out',
+ description='INLINE $out')
+ n.build(built('browse_py.h'), 'inline', src('browse.py'),
+ variables=[('varname', 'kBrowsePy')])
+ n.newline()
+
+ n.comment("TODO: this shouldn't need to depend on inline.sh.")
+ objs += cxx('browse',
+ implicit='src/inline.sh',
+ order_only=built('browse_py.h'))
+ n.newline()
n.comment('Core source files all build into ninja library.')
for name in ['build', 'build_log', 'clean', 'eval_env', 'graph', 'graphviz',
- 'parsers', 'subprocess', 'util',
+ 'parsers', 'util', 'subprocess',
'ninja_jumble']:
+ if platform == 'mingw' and name == 'subprocess':
+ # TODO: merge subprocess port
+ continue
objs += cxx(name)
-ninja_lib = n.build(built('ninja.a'), 'ar', objs)
+ninja_lib = n.build(built('libninja.a'), 'ar', objs)
n.newline()
n.comment('Main executable is library plus main() function.')
objs = cxx('ninja')
-n.build('ninja', 'link', objs + ninja_lib)
+n.build('ninja', 'link', objs, implicit=ninja_lib, order_only=ninja_lib,
+ variables=[('libs', '-L$builddir -lninja')])
n.comment('Tests all build into ninja_test executable.')
objs = []
@@ -100,9 +126,9 @@ for name in ['build_test', 'build_log_test', 'graph_test', 'ninja_test',
ldflags = '-lgtest -lgtest_main -lpthread'
if 'LDFLAGS' in os.environ:
ldflags += ' ' + os.environ.get('LDFLAGS')
-n.build('ninja_test', 'link',
- objs + ninja_lib,
- variables=[('ldflags', ldflags)])
+n.build('ninja_test', 'link', objs, implicit=ninja_lib, order_only=ninja_lib,
+ variables=[('libs', '-L$builddir -lninja'),
+ ('ldflags', ldflags)])
n.newline()
n.comment('Generate a graph using the "graph" tool.')