'Some packages ship with an older config.guess and need to have
this updated when installed on a newer architecture. In particular,
config.guess fails for PPC64LE for version prior to a 2013-06-10
build date (automake 1.13.4).'

@run_after('autoreconf')
def _do_patch_config_guess(self):

    if ((not self.patch_config_guess) or (not self.spec.satisfies('arch=linux-rhel7-ppc64le'))):
        return
    my_config_guess = None
    config_guess = None
    if os.path.exists('config.guess'):
        my_config_guess = 'config.guess'
    else:
        d = '.'
        dirs = [os.path.join(d, o) for o in os.listdir(d) if os.path.isdir(os.path.join(d, o))]
        for dirname in dirs:
            path = os.path.join(dirname, 'config.guess')
            if os.path.exists(path):
                my_config_guess = path
    if (my_config_guess is not None):
        try:
            check_call([my_config_guess], stdout=PIPE, stderr=PIPE)
            return
        except Exception:
            pass
    else:
        return
    if ('automake' in self.spec):
        automake_path = os.path.join(self.spec['automake'].prefix, 'share', ('automake-' + str(self.spec['automake'].version)))
        path = os.path.join(automake_path, 'config.guess')
        if os.path.exists(path):
            config_guess = path
    if ((config_guess is None) and os.path.exists('/usr/share')):
        automake_dir = [s for s in os.listdir('/usr/share') if ('automake' in s)]
        if automake_dir:
            automake_path = os.path.join('/usr/share', automake_dir[0])
            path = os.path.join(automake_path, 'config.guess')
            if os.path.exists(path):
                config_guess = path
    if (config_guess is not None):
        try:
            check_call([config_guess], stdout=PIPE, stderr=PIPE)
            mod = ((stat(my_config_guess).st_mode & 511) | S_IWUSR)
            os.chmod(my_config_guess, mod)
            shutil.copyfile(config_guess, my_config_guess)
            return
        except Exception:
            pass
    raise RuntimeError('Failed    to    find    suitable    config.guess')
