Description: Add Appstream metadata listing supported hardware

http://people.skolelinux.org/pere/blog/Using_appstream_with_isenkram_to_install_hardware_related_packages_in_Debian.html
https://www.freedesktop.org/software/appstream/docs/chap-Metadata.html#sect-Metadata-GenericComponent

Upstream agreed in
https://lists.freedesktop.org/archives/beignet/2017-February/008597.html
that this metadata (including parts automatically extracted from
src/cl_device_data.h) can be MIT licensed.

Author: Rebecca N. Palmer <rebecca_palmer@zoho.com>, Yang Rong
Forwarded: accepted https://cgit.freedesktop.org/beignet/commit/?id=033464f4b8045a49dbcc1a84cde5c05986ca11c2

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -339,6 +339,10 @@ IF(BUILD_EXAMPLES)
 ADD_SUBDIRECTORY(examples)
 ENDIF(BUILD_EXAMPLES)
 
+add_custom_target(metainfo ALL
+                  COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/update_metainfo_xml.py "${LIBCL_DRIVER_VERSION_MAJOR}.${LIBCL_DRIVER_VERSION_MINOR}.${LIBCL_DRIVER_VERSION_PATCH}" ${CMAKE_CURRENT_BINARY_DIR})
+install (FILES ${CMAKE_CURRENT_BINARY_DIR}/com.intel.beignet.metainfo.xml DESTINATION /usr/share/metainfo)
+
 SET(CPACK_SET_DESTDIR ON)
 SET(CPACK_PACKAGE_VERSION_MAJOR "${LIBCL_DRIVER_VERSION_MAJOR}")
 SET(CPACK_PACKAGE_VERSION_MINOR "${LIBCL_DRIVER_VERSION_MINOR}")
--- /dev/null
+++ b/com.intel.beignet.metainfo.xml.in
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<component type="driver">
+<id>com.intel.beignet</id>
+<name>Beignet</name>
+<summary>OpenCL (GPU compute) driver for Intel GPUs</summary>
+<description>This allows using Intel integrated GPUs for general computation, speeding up some applications.</description>
+<provides>
+@modalias_list@
+</provides>
+<metadata_license>MIT</metadata_license>
+<project_license>LGPL-2.1+</project_license>
+<url type="homepage">https://www.freedesktop.org/wiki/Software/Beignet/</url>
+<developer_name>Intel</developer_name>
+<releases>
+<release version="@version@"></release>
+</releases>
+</component>
--- /dev/null
+++ b/update_metainfo_xml.py
@@ -0,0 +1,33 @@
+#!/usr/bin/python3
+
+import re
+import sys
+import os.path
+from io import open
+
+if len(sys.argv)!=3:
+    raise TypeError("requires version_string and output_directory")
+version_string=sys.argv[1]
+output_directory=sys.argv[2]
+source_directory=os.path.dirname(sys.argv[0])
+source_file=open(os.path.join(source_directory,"src/cl_device_data.h"),"r",encoding='utf-8')
+device_ids=[]
+supported=False#first few devices in the file aren't supported
+for line in source_file:
+    device_id=re.match(r"#define\s+PCI_CHIP_([A-Za-z0-9_]+)\s+0x([0-9A-Fa-f]+)",line)
+    if device_id is None:
+        continue
+    if "IVYBRIDGE" in device_id.group(1):
+        supported=True#start of supported devices
+    if supported:
+        device_ids.append(device_id.group(2).upper())
+source_file.close()
+modalias_list_string="\n".join("<modalias>pci:v00008086d0000{}*</modalias>".format(device_id) for device_id in sorted(device_ids))
+metadata_file_in=open(os.path.join(source_directory,"com.intel.beignet.metainfo.xml.in"),"r",encoding='utf-8')
+metadata_string=metadata_file_in.read()
+metadata_file_in.close()
+metadata_string=metadata_string.replace("@modalias_list@",modalias_list_string).replace("@version@",version_string)
+metadata_file_out=open(os.path.join(output_directory,"com.intel.beignet.metainfo.xml"),"w",encoding='utf-8')
+metadata_file_out.write(metadata_string)
+metadata_file_out.close()
+
