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