Support for building on OpenBSD.

Change-Id: I89022b5008ba00bd5457c5625f0a87e8393c3d23
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/4160
Reviewed-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Petr Hosek <phosek@google.com>
Commit-Queue: Petr Hosek <phosek@google.com>
diff --git a/build/build_openbsd.ninja.template b/build/build_openbsd.ninja.template
new file mode 100644
index 0000000..f22ccb3
--- /dev/null
+++ b/build/build_openbsd.ninja.template
@@ -0,0 +1,19 @@
+rule cc
+  command = $cc -MMD -MF $out.d $defines $includes $cflags $cflags_c -c $in -o $out
+  description = CC $out
+  depfile = $out.d
+  deps = gcc
+
+rule cxx
+  command = $cxx -MMD -MF $out.d $defines $includes $cflags $cflags_cc -c $in -o $out
+  description = CXX $out
+  depfile = $out.d
+  deps = gcc
+
+rule alink_thin
+  command = rm -f $out && $ar rcs $out $in
+  description = AR $out
+
+rule link
+  command = $ld $ldflags -o $out -Wl,--start-group $in $libs -Wl,--end-group $solibs
+  description = LINK $out
diff --git a/build/gen.py b/build/gen.py
index 3edefa7..d547a8f 100755
--- a/build/gen.py
+++ b/build/gen.py
@@ -41,10 +41,12 @@
       self._platform = 'fuchsia'
     elif self._platform.startswith('freebsd'):
       self._platform = 'freebsd'
+    elif self._platform.startswith('openbsd'):
+      self._platform = 'openbsd'
 
   @staticmethod
   def known_platforms():
-    return ['linux', 'darwin', 'msvc', 'aix', 'fuchsia']
+    return ['linux', 'darwin', 'msvc', 'aix', 'fuchsia', 'openbsd']
 
   def platform(self):
     return self._platform
@@ -68,7 +70,7 @@
     return self._platform == 'aix'
 
   def is_posix(self):
-    return self._platform in ['linux', 'freebsd', 'darwin', 'aix']
+    return self._platform in ['linux', 'freebsd', 'darwin', 'aix', 'openbsd']
 
 
 def main(argv):
@@ -173,6 +175,7 @@
       'linux': 'build_linux.ninja.template',
       'freebsd': 'build_linux.ninja.template',
       'aix': 'build_aix.ninja.template',
+      'openbsd': 'build_openbsd.ninja.template',
   }[platform.platform()])
 
   with open(template_filename) as f:
diff --git a/tools/gn/args.cc b/tools/gn/args.cc
index 5889c8f..d1d7611 100644
--- a/tools/gn/args.cc
+++ b/tools/gn/args.cc
@@ -298,6 +298,8 @@
   os = "freebsd";
 #elif defined(OS_AIX)
   os = "aix";
+#elif defined(OS_OPENBSD)
+  os = "openbsd";
 #else
 #error Unknown OS type.
 #endif