Add license and license header.

Apache 2.0! There's a dumb script to help with adding headers and
catching files that are missing headers.

Change-Id: Ic4db85b617aa82e5e201ae4bd2e5aff6a029b1b3
diff --git a/build/license.py b/build/license.py
new file mode 100644
index 0000000..bce6f34
--- /dev/null
+++ b/build/license.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#
+# Copyright 2018 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Add license header to source files.
+
+If the file doesn't have the license header, add it with the appropriate comment
+style.
+"""
+
+import argparse
+import sys
+
+
+apache2 = """{comment} Copyright 2018 Google LLC
+{comment}
+{comment} Licensed under the Apache License, Version 2.0 (the "License");
+{comment} you may not use this file except in compliance with the License.
+{comment} You may obtain a copy of the License at
+{comment}
+{comment}     https://www.apache.org/licenses/LICENSE-2.0
+{comment}
+{comment} Unless required by applicable law or agreed to in writing, software
+{comment} distributed under the License is distributed on an "AS IS" BASIS,
+{comment} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+{comment} See the License for the specific language governing permissions and
+{comment} limitations under the License."""
+
+def Main():
+    parser = argparse.ArgumentParser()
+    parser.add_argument("file")
+    parser.add_argument("--style", choices=["c", "hash"], required=True)
+    args = parser.parse_args()
+    header = "/*\n" if args.style == "c" else ""
+    header += apache2.format(comment=" *" if args.style == "c" else "#")
+    header += "\n */" if args.style == "c" else ""
+    header += "\n\n"
+    with open(args.file, "r") as f:
+        contents = f.read()
+        if header in contents:
+            return
+    with open(args.file, "w") as f:
+        f.write(header)
+        f.write(contents)
+
+if __name__ == "__main__":
+    sys.exit(Main())