| 
 | 1 | +from __future__ import print_function  | 
 | 2 | +import os, sys, subprocess  | 
 | 3 | + | 
 | 4 | +MYHOME = os.path.dirname(__file__)  | 
 | 5 | + | 
 | 6 | +def main():  | 
 | 7 | +    if len(sys.argv) == 2:  | 
 | 8 | +        options = sys.argv[1]  | 
 | 9 | + | 
 | 10 | +        if options == '--cmake':  | 
 | 11 | +            print(os.path.join(MYHOME, "cmake"))  | 
 | 12 | +            return 0  | 
 | 13 | + | 
 | 14 | +        if options == '--cppflags':  | 
 | 15 | +            options = '--cflags'  | 
 | 16 | + | 
 | 17 | +        if options != '--help':  | 
 | 18 | +            rcfg = os.path.join(MYHOME, 'bin', 'root-config')  | 
 | 19 | +            try:  | 
 | 20 | +                cli_arg = subprocess.check_output(  | 
 | 21 | +                    [os.path.join(MYHOME, 'bin', 'root-config'), options],  | 
 | 22 | +                    stderr=subprocess.STDOUT)  | 
 | 23 | +                out = cli_arg.decode("utf-8").strip()  | 
 | 24 | +                if 'flags' in options and 'STDCXX' in os.environ and '-std=' in out:  | 
 | 25 | +                    req = os.environ['STDCXX']  | 
 | 26 | +                    true_flags = None  | 
 | 27 | +                    if req == '17':  | 
 | 28 | +                        true_flags = '-std=c++1z'  | 
 | 29 | +                    elif req == '20':  | 
 | 30 | +                        true_flags = '-std=c++2a'  | 
 | 31 | +                    else:  | 
 | 32 | +                        true_flags = '-std=c++'+req  | 
 | 33 | +                    if true_flags:  | 
 | 34 | +                        pos = out.find('std=')  | 
 | 35 | +                        out = out[:pos] + true_flags + out[pos+9:]  | 
 | 36 | +                print(out)  | 
 | 37 | +                return 0  | 
 | 38 | +            except OSError:  | 
 | 39 | +                if not os.path.exists(rcfg) or not 'win32' in sys.platform:  | 
 | 40 | +                    raise  | 
 | 41 | + | 
 | 42 | +                # happens on Windows b/c root-config is a bash script; the  | 
 | 43 | +                # following covers the most important options until that  | 
 | 44 | +                # gets fixed upstream  | 
 | 45 | + | 
 | 46 | +                def get_include_dir():  | 
 | 47 | +                    return os.path.join(MYHOME, 'include')  | 
 | 48 | + | 
 | 49 | +                def get_library_dir():  | 
 | 50 | +                    return os.path.join(MYHOME, 'lib')  | 
 | 51 | + | 
 | 52 | +                def get_basic_cppflags():  | 
 | 53 | +                    flags = '-Zc:__cplusplus '  | 
 | 54 | +                    if 'STDCXX' in os.environ:  | 
 | 55 | +                        return flags + '/std:c++'+os.environ['STDCXX']  | 
 | 56 | +                    else:  | 
 | 57 | +                        for line in open(rcfg):  | 
 | 58 | +                            if 'cxxversion' in line:  | 
 | 59 | +                                if '11' in line:  | 
 | 60 | +                                    return flags+'/std:c++11'  | 
 | 61 | +                                elif '14' in line:  | 
 | 62 | +                                    return flags+'/std:c++14'  | 
 | 63 | +                                elif '17' in line:  | 
 | 64 | +                                    return flags+'/std:c++17'  | 
 | 65 | +                                else:  | 
 | 66 | +                                  # includes C++20, which won't get it's own flag until  | 
 | 67 | +                                  # it is feature-complete  | 
 | 68 | +                                    return flags+'/std:c++latest'  | 
 | 69 | +                        raise  | 
 | 70 | + | 
 | 71 | +                if options == '--incdir':  | 
 | 72 | +                    print(get_include_dir())  | 
 | 73 | +                    return 0  | 
 | 74 | + | 
 | 75 | +                elif options == '--libdir':  | 
 | 76 | +                    print(get_library_dir())  | 
 | 77 | +                    return 0  | 
 | 78 | + | 
 | 79 | +                elif options == '--auxcflags':  | 
 | 80 | +                # most important is get the C++ version flag right  | 
 | 81 | +                    print(get_basic_cppflags())  | 
 | 82 | +                    return 0  | 
 | 83 | + | 
 | 84 | +                elif options == '--cflags':  | 
 | 85 | +                # most important are C++ flag and include directory  | 
 | 86 | +                    print(get_basic_cppflags(), '/I'+get_include_dir(), '/FIw32pragma.h')  | 
 | 87 | +                    return 0  | 
 | 88 | + | 
 | 89 | +                elif options == '--ldflags':  | 
 | 90 | +                    print('/LIBPATH:'+get_library_dir(), 'libCoreLegacy.lib', 'libRIOLegacy.lib')  | 
 | 91 | +                    return 0  | 
 | 92 | + | 
 | 93 | +            except subprocess.CalledProcessError:  | 
 | 94 | +                pass  | 
 | 95 | + | 
 | 96 | +    print('Usage: cling-config [--cflags] [--cppflags] [--cmake]')  | 
 | 97 | +    return 1  | 
 | 98 | + | 
 | 99 | +if __name__ == '__main__':  | 
 | 100 | +    sys.exit(main())  | 
0 commit comments