bc5d70
# -*- coding:utf-8 -*-
bc5d70
#
bc5d70
# Copyright (C) 2017 Björn Esser <besser82@fedoraproject.org>
bc5d70
#
bc5d70
# based on cmake.prov, which is
bc5d70
# Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
bc5d70
# Copyright (C) 2017 Daniel Vrátil <dvratil@fedoraproject.org>
bc5d70
#
bc5d70
#
bc5d70
# This program is free software; you can redistribute it and/or modify
bc5d70
# it under the terms of the GNU Library General Public License as
bc5d70
# published by the Free Software Foundation; either version 2 of the
bc5d70
# License, or (at your option) any later version.
bc5d70
#
bc5d70
# This program is distributed in the hope that it will be useful,
bc5d70
# but WITHOUT ANY WARRANTY; without even the implied warranty of
bc5d70
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
bc5d70
# GNU General Public License for more details.
bc5d70
#
bc5d70
# You should have received a copy of the GNU Library General Public
bc5d70
# License along with this program; if not, write to the
bc5d70
# Free Software Foundation, Inc.,
bc5d70
# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
bc5d70
#
bc5d70
bc5d70
import sys
bc5d70
import re
bc5d70
import subprocess
bc5d70
bc5d70
class CMakeParser:
bc5d70
    def __init__(self, filelist = None):
bc5d70
        if filelist == None:
bc5d70
            filelist = sys.stdin
bc5d70
bc5d70
        has_module = False
bc5d70
        is_arched = False
bc5d70
bc5d70
        isa_suf = subprocess.check_output(["/usr/bin/rpm", "-E %{?_isa}"]).decode().strip()
bc5d70
bc5d70
        paths = map(lambda x: x.rstrip(), filelist.readlines())
bc5d70
        for path in paths:
bc5d70
            modulePath, cmakeModule, lowercase = self.parseCmakeModuleConfig(path)
bc5d70
            if modulePath and cmakeModule:
bc5d70
                has_module = True
bc5d70
                if re.match(".*/usr/lib(64)?/cmake/.*", modulePath):
bc5d70
                    is_arched = True
bc5d70
bc5d70
        if has_module:
bc5d70
            if is_arched:
bc5d70
                print("cmake-filesystem%s" % isa_suf)
bc5d70
            else:
bc5d70
                print("cmake-filesystem")
bc5d70
bc5d70
bc5d70
    def parseCmakeModuleConfig(self, configFile):
bc5d70
        paths = configFile.rsplit("/", 3)
bc5d70
bc5d70
        modulePath = "%s/cmake/%s" % (paths[0], paths[2])
bc5d70
        cfgFile = paths[3]
bc5d70
        if cfgFile.endswith("Config.cmake"):
bc5d70
           return (modulePath, cfgFile[0:-len("Config.cmake")], False)
bc5d70
        elif cfgFile.endswith("-config.cmake"):
bc5d70
           return (modulePath, cfgFile[0:-len("-config.cmake")], True)
bc5d70
        else:
bc5d70
            return (None, None, False)
bc5d70
bc5d70
bc5d70
if __name__ == "__main__":
bc5d70
    parser = CMakeParser()