windows: more build fixes
authorScott Graham <sgraham@gmail.com>
Wed, 4 Jan 2012 22:18:17 +0000 (14:18 -0800)
committerEvan Martin <martine@danga.com>
Wed, 4 Jan 2012 22:18:39 +0000 (14:18 -0800)
bootstrap.py
configure.py
src/getopt.c
src/lexer.cc
src/lexer.h
src/lexer.in.cc

index 4d2b4be..6a7d876 100755 (executable)
@@ -43,8 +43,9 @@ except OSError, e:
 
 with open('src/browse.py') as browse_py:
     with open('build/browse_py.h', 'w') as browse_py_h:
-        run(['./src/inline.sh', 'kBrowsePy'],
-            stdin=browse_py, stdout=browse_py_h)
+        hex_str = ''.join([hex(ord(c)) for c in browse_py.read()])
+        src = "const char %s[]=\"\n%s\n\";" % ('kBrowsePy', hex_str)
+        browse_py_h.write(src)
 
 sources = []
 for src in glob.glob('src/*.cc'):
@@ -52,7 +53,7 @@ for src in glob.glob('src/*.cc'):
         continue
 
     if sys.platform.startswith('win32'):
-        if src.endswith('/browse.cc') or src.endswith('/subprocess.cc'):
+        if src.endswith('\\browse.cc') or src.endswith('\\subprocess.cc'):
             continue
     else:
         if src.endswith('-win32.cc'):
@@ -60,15 +61,25 @@ for src in glob.glob('src/*.cc'):
 
     sources.append(src)
 
-args = [os.environ.get('CXX', 'g++'), '-Wno-deprecated',
-        '-DNINJA_PYTHON="' + sys.executable + '"']
+if sys.platform.startswith('win32'):
+    sources.append('src/getopt.c')
+
+vcdir = os.environ.get('VCINSTALLDIR')
+if vcdir:
+    args = [os.path.join(vcdir, 'bin', 'cl.exe'), '/nologo', '/EHsc', '/DWIN32']
+else:
+    args = [os.environ.get('CXX', 'g++'), '-Wno-deprecated',
+            '-DNINJA_PYTHON="' + sys.executable + '"']
 args.extend(cflags)
 args.extend(ldflags)
 binary = 'ninja.bootstrap'
 if sys.platform.startswith('win32'):
     binary = 'ninja.bootstrap.exe'
-args.extend(['-o', binary])
 args.extend(sources)
+if vcdir:
+    args.extend(['/link', '/out:' + binary])
+else:
+    args.extend(['-o', binary])
 run(args)
 
 print 'Building ninja using itself...'
index 4b3579d..48ccae9 100755 (executable)
@@ -140,7 +140,7 @@ n.newline()
 
 if platform == 'windows':
     n.rule('cxx',
-        command='$cxx $cflags -c $in /Fo $out',
+        command='$cxx $cflags -c $in /Fo$out',
         depfile='$out.d',
         description='CXX $out')
 else:
index 0dbe6a5..1e3c09d 100644 (file)
@@ -396,17 +396,17 @@ getopt (int argc, char **argv, char *optstring)
 }
 
 int
-getopt_long (int argc, char **argv, char *shortopts,
-             GETOPT_LONG_OPTION_T * longopts, int *longind)
+getopt_long (int argc, char **argv, const char *shortopts,
+             const GETOPT_LONG_OPTION_T * longopts, int *longind)
 {
-  return getopt_internal (argc, argv, shortopts, longopts, longind, 0);
+  return getopt_internal (argc, argv, (char*)shortopts, (GETOPT_LONG_OPTION_T*)longopts, longind, 0);
 }
 
 int
-getopt_long_only (int argc, char **argv, char *shortopts,
-                  GETOPT_LONG_OPTION_T * longopts, int *longind)
+getopt_long_only (int argc, char **argv, const char *shortopts,
+                  const GETOPT_LONG_OPTION_T * longopts, int *longind)
 {
-  return getopt_internal (argc, argv, shortopts, longopts, longind, 1);
+  return getopt_internal (argc, argv, (char*)shortopts, (GETOPT_LONG_OPTION_T*)longopts, longind, 1);
 }
 
 /* end of file GETOPT.C */
index d3ef43f..75b91e7 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdio.h>
 
 #include "eval_env.h"
+#include "util.h"
 
 bool Lexer::Error(const string& message, string* err) {
   // Compute line/column.
index 40e602a..c872b98 100644 (file)
 
 #include "string_piece.h"
 
+// Windows may #define ERROR.
+#ifdef ERROR
+#undef ERROR
+#endif
+
 struct EvalString;
 
 struct Lexer {
index 4d6d132..c0c197b 100644 (file)
@@ -17,6 +17,7 @@
 #include <stdio.h>
 
 #include "eval_env.h"
+#include "util.h"
 
 bool Lexer::Error(const string& message, string* err) {
   // Compute line/column.