From 7ae52ad5a1e558789e680d81c7ba8001115ee07d Mon Sep 17 00:00:00 2001
From: Arun Raghavan <arun@arunraghavan.net>
Date: Thu, 18 May 2017 15:06:41 +0530
Subject: [PATCH] build: Add support for Amazon Linux

This seems to be a RedHat variant based on RHEL/CentOS 6. Users of this
will need EPEL 6 to get pulseaudio-libs-devel, gdk-pixbuf, and
glib-networking.
---
 cerbero/bootstrap/build_tools.py |  3 ++-
 cerbero/enums.py                 |  2 ++
 cerbero/utils/__init__.py        |  6 ++++++
 recipes/glib.recipe              | 19 +++----------------
 4 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/cerbero/bootstrap/build_tools.py b/cerbero/bootstrap/build_tools.py
index 2f22653..261494b 100644
--- a/cerbero/bootstrap/build_tools.py
+++ b/cerbero/bootstrap/build_tools.py
@@ -56,7 +56,8 @@ class BuildTools (BootstrapperBase):
                 self.config.distro_version == DistroVersion.DEBIAN_WHEEZY:
                 # x264 requires yasm >= 1.2
                 self.BUILD_TOOLS.append('yasm')
-            if self.config.distro_version in [DistroVersion.REDHAT_6]:
+            if self.config.distro_version in [DistroVersion.REDHAT_6,
+                                              DistroVersion.AMAZON_LINUX]:
                 self.BUILD_TOOLS.append('cmake')
         if self.config.target_platform == Platform.IOS:
             self.BUILD_TOOLS.append('gas-preprocessor')
diff --git a/cerbero/enums.py b/cerbero/enums.py
index 17b67f9..3a1582b 100644
--- a/cerbero/enums.py
+++ b/cerbero/enums.py
@@ -92,6 +92,8 @@ class DistroVersion:
     FEDORA_26 = 'fedora_26'
     REDHAT_6 = 'redhat_6'
     REDHAT_7 = 'redhat_7'
+    # Amazon Linux seems to be RedHat/CentOS-based
+    AMAZON_LINUX = 'amazon_linux'
     ARCH_ROLLING = 'rolling'
     GENTOO_VERSION = 'gentoo-version'
     OPENSUSE_12_1 = 'opensuse_12_1'
diff --git a/cerbero/utils/__init__.py b/cerbero/utils/__init__.py
index 51ad316..40c0ef7 100644
--- a/cerbero/utils/__init__.py
+++ b/cerbero/utils/__init__.py
@@ -159,6 +159,10 @@ def system_info():
                 # FIXME: the python2.7 platform module does not support Arch Linux.
                 # Mimic python3.4 platform.linux_distribution() output.
                 d = ('arch', 'Arch', 'Linux')
+            elif os.path.exists('/etc/os-release'):
+                with open('/etc/os-release', 'r') as f:
+                    if 'ID="amzn"\n' in f.readlines():
+                        d = ('RedHat', 'amazon', '')
 
         if d[0] in ['Ubuntu', 'debian', 'LinuxMint']:
             distro = Distro.DEBIAN
@@ -226,6 +230,8 @@ def system_info():
                 distro_version = DistroVersion.REDHAT_6
             elif d[1].startswith('7.'):
                 distro_version = DistroVersion.REDHAT_7
+            elif d[1] == 'amazon':
+                distro_version = DistroVersion.AMAZON_LINUX
             else:
                 # FIXME Fill this
                 raise FatalError("Distribution '%s' not supported" % str(d))
diff --git a/recipes/glib.recipe b/recipes/glib.recipe
index f231d6d..905f162 100644
--- a/recipes/glib.recipe
+++ b/recipes/glib.recipe
@@ -168,22 +168,9 @@ class Recipe(recipe.Recipe):
                 elif self.config.target_arch == Architecture.X86_64:
                     path1 = '/usr/lib/x86_64-linux-gnu/gio/modules'
             # RedHat
-            elif self.config.target_distro_version in [DistroVersion.FEDORA_16,
-                                                       DistroVersion.FEDORA_17,
-                                                       DistroVersion.FEDORA_18,
-                                                       DistroVersion.FEDORA_19,
-                                                       DistroVersion.FEDORA_20,
-                                                       DistroVersion.FEDORA_21,
-                                                       DistroVersion.FEDORA_22,
-                                                       DistroVersion.FEDORA_23,
-                                                       DistroVersion.FEDORA_24,
-                                                       DistroVersion.FEDORA_25,
-                                                       DistroVersion.FEDORA_26,
-                                                       DistroVersion.REDHAT_6,
-                                                       DistroVersion.REDHAT_7,
-                                                       ]:
-                    if self.config.target_arch == Architecture.X86_64:
-                        path1 = '/usr/lib64/gio/modules/'
+            elif self.config.target_distro == Distro.REDHAT:
+                if self.config.target_arch == Architecture.X86_64:
+                    path1 = '/usr/lib64/gio/modules/'
             # Suse
             elif self.config.target_distro == Distro.SUSE:
                 if self.config.target_arch == Architecture.X86_64:
-- 
2.9.4

