Tom Stellard | 55d3746 | 2014-02-12 14:54:17 +0000 | [diff] [blame] | 1 | #!/usr/bin/python |
Jan Vesely | a4a20cd | 2017-08-02 15:00:59 +0000 | [diff] [blame] | 2 | from __future__ import print_function |
| 3 | |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 4 | def c_compiler_rule(b, name, description, compiler, flags): |
| 5 | command = "%s -MMD -MF $out.d %s -c -o $out $in" % (compiler, flags) |
| 6 | b.rule(name, command, description + " $out", depfile="$out.d") |
| 7 | |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 8 | version_major = 0; |
Jeroen Ketema | d915739 | 2015-08-07 08:31:37 +0000 | [diff] [blame] | 9 | version_minor = 2; |
Tom Stellard | 1d77071 | 2014-12-31 15:27:53 +0000 | [diff] [blame] | 10 | version_patch = 0; |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 11 | |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 12 | from optparse import OptionParser |
| 13 | import os |
Aaron Watry | b38037f | 2013-12-29 16:39:53 +0000 | [diff] [blame] | 14 | import string |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 15 | from subprocess import * |
| 16 | import sys |
| 17 | |
| 18 | srcdir = os.path.dirname(sys.argv[0]) |
| 19 | |
| 20 | sys.path.insert(0, os.path.join(srcdir, 'build')) |
| 21 | import metabuild |
| 22 | |
| 23 | p = OptionParser() |
| 24 | p.add_option('--with-llvm-config', metavar='PATH', |
| 25 | help='use given llvm-config script') |
Tom Stellard | 9f48bb3 | 2013-10-23 02:49:27 +0000 | [diff] [blame] | 26 | p.add_option('--with-cxx-compiler', metavar='PATH', |
| 27 | help='use given C++ compiler') |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 28 | p.add_option('--prefix', metavar='PATH', |
| 29 | help='install to given prefix') |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 30 | p.add_option('--libexecdir', metavar='PATH', |
| 31 | help='install *.bc to given dir') |
| 32 | p.add_option('--includedir', metavar='PATH', |
| 33 | help='install include files to given dir') |
| 34 | p.add_option('--pkgconfigdir', metavar='PATH', |
| 35 | help='install clc.pc to given dir') |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 36 | p.add_option('-g', metavar='GENERATOR', default='make', |
| 37 | help='use given generator (default: make)') |
Tom Stellard | d9ca1f1 | 2015-04-20 18:49:50 +0000 | [diff] [blame] | 38 | p.add_option('--enable-runtime-subnormal', action="store_true", default=False, |
| 39 | help='Allow runtimes to choose subnormal support') |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 40 | (options, args) = p.parse_args() |
| 41 | |
| 42 | llvm_config_exe = options.with_llvm_config or "llvm-config" |
| 43 | |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 44 | prefix = options.prefix |
| 45 | if not prefix: |
| 46 | prefix = '/usr/local' |
| 47 | |
| 48 | libexecdir = options.libexecdir |
| 49 | if not libexecdir: |
| 50 | libexecdir = os.path.join(prefix, 'lib/clc') |
| 51 | |
| 52 | includedir = options.includedir |
| 53 | if not includedir: |
| 54 | includedir = os.path.join(prefix, 'include') |
| 55 | |
| 56 | pkgconfigdir = options.pkgconfigdir |
| 57 | if not pkgconfigdir: |
Tom Stellard | 93d674f | 2013-09-05 23:27:58 +0000 | [diff] [blame] | 58 | pkgconfigdir = os.path.join(prefix, 'share/pkgconfig') |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 59 | |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 60 | def llvm_config(args): |
| 61 | try: |
Jan Vesely | a4a20cd | 2017-08-02 15:00:59 +0000 | [diff] [blame] | 62 | # Universal newlines translate different newline formats to '\n' |
| 63 | # it also force the input to be string instead of bytes in python 3 |
| 64 | proc = Popen([llvm_config_exe] + args, stdout=PIPE, universal_newlines=True) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 65 | return proc.communicate()[0].rstrip().replace('\n', ' ') |
| 66 | except OSError: |
Jan Vesely | a4a20cd | 2017-08-02 15:00:59 +0000 | [diff] [blame] | 67 | print("Error executing llvm-config.") |
| 68 | print("Please ensure that llvm-config is in your $PATH, or use --with-llvm-config.") |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 69 | sys.exit(1) |
| 70 | |
Jan Vesely | a4a20cd | 2017-08-02 15:00:59 +0000 | [diff] [blame] | 71 | llvm_version = llvm_config(['--version']).replace('svn', '').split('.') |
Jeroen Ketema | d915739 | 2015-08-07 08:31:37 +0000 | [diff] [blame] | 72 | llvm_int_version = int(llvm_version[0]) * 100 + int(llvm_version[1]) * 10 |
Jan Vesely | b9dbaae | 2017-09-08 23:58:53 +0000 | [diff] [blame] | 73 | llvm_string_version = llvm_version[0] + '.' + llvm_version[1] |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 74 | |
Jan Vesely | ce29e8c | 2017-09-29 19:06:41 +0000 | [diff] [blame] | 75 | if llvm_int_version < 390: |
| 76 | print("libclc requires LLVM >= 3.9") |
Jeroen Ketema | d915739 | 2015-08-07 08:31:37 +0000 | [diff] [blame] | 77 | sys.exit(1) |
| 78 | |
Tom Stellard | 1d77071 | 2014-12-31 15:27:53 +0000 | [diff] [blame] | 79 | llvm_system_libs = llvm_config(['--system-libs']) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 80 | llvm_bindir = llvm_config(['--bindir']) |
Peter Collingbourne | db47eac | 2012-12-05 07:39:02 +0000 | [diff] [blame] | 81 | llvm_core_libs = llvm_config(['--libs', 'core', 'bitreader', 'bitwriter']) + ' ' + \ |
Aaron Watry | b38037f | 2013-12-29 16:39:53 +0000 | [diff] [blame] | 82 | llvm_system_libs + ' ' + \ |
Peter Collingbourne | db47eac | 2012-12-05 07:39:02 +0000 | [diff] [blame] | 83 | llvm_config(['--ldflags']) |
Jan Vesely | 3bb50f6 | 2017-09-26 23:15:54 +0000 | [diff] [blame] | 84 | llvm_cxxflags = llvm_config(['--cxxflags']) + ' -fno-exceptions -fno-rtti ' + \ |
| 85 | '-DHAVE_LLVM=0x{:0=4}'.format(llvm_int_version) |
Jan Vesely | 6249614 | 2014-09-02 17:54:59 +0000 | [diff] [blame] | 86 | llvm_libdir = llvm_config(['--libdir']) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 87 | |
| 88 | llvm_clang = os.path.join(llvm_bindir, 'clang') |
| 89 | llvm_link = os.path.join(llvm_bindir, 'llvm-link') |
| 90 | llvm_opt = os.path.join(llvm_bindir, 'opt') |
| 91 | |
Tom Stellard | 9f48bb3 | 2013-10-23 02:49:27 +0000 | [diff] [blame] | 92 | cxx_compiler = options.with_cxx_compiler |
| 93 | if not cxx_compiler: |
| 94 | cxx_compiler = os.path.join(llvm_bindir, 'clang++') |
| 95 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 96 | available_targets = { |
| 97 | 'r600--' : { 'devices' : |
Jan Vesely | e97deff | 2016-06-17 20:30:50 +0000 | [diff] [blame] | 98 | [{'gpu' : 'cedar', 'aliases' : ['palm', 'sumo', 'sumo2', 'redwood', 'juniper']}, |
| 99 | {'gpu' : 'cypress', 'aliases' : ['hemlock'] }, |
| 100 | {'gpu' : 'barts', 'aliases' : ['turks', 'caicos'] }, |
| 101 | {'gpu' : 'cayman', 'aliases' : ['aruba']} ]}, |
Tom Stellard | 0f39721 | 2015-01-06 20:42:12 +0000 | [diff] [blame] | 102 | 'amdgcn--': { 'devices' : |
Jan Vesely | 70c5f9d | 2018-09-15 22:02:01 +0000 | [diff] [blame] | 103 | [{'gpu' : 'tahiti', 'aliases' : ['pitcairn', 'verde', 'oland', 'hainan', 'bonaire', 'kabini', 'kaveri', 'hawaii', 'mullins', 'tonga', 'iceland', 'carrizo', 'fiji', 'stoney', 'polaris10', 'polaris11']} ]}, |
Konstantin Zhuravlyov | f8a81f8 | 2016-04-07 19:54:19 +0000 | [diff] [blame] | 104 | 'amdgcn--amdhsa': { 'devices' : |
Jan Vesely | 70c5f9d | 2018-09-15 22:02:01 +0000 | [diff] [blame] | 105 | [{'gpu' : '', 'aliases' : ['bonaire', 'kabini', 'kaveri', 'hawaii', 'mullins', 'tonga', 'iceland', 'carrizo', 'fiji', 'stoney', 'polaris10', 'polaris11']} ]}, |
Jan Vesely | e97deff | 2016-06-17 20:30:50 +0000 | [diff] [blame] | 106 | 'nvptx--' : { 'devices' : [{'gpu' : '', 'aliases' : []} ]}, |
| 107 | 'nvptx64--' : { 'devices' : [{'gpu' : '', 'aliases' : []} ]}, |
| 108 | 'nvptx--nvidiacl' : { 'devices' : [{'gpu' : '', 'aliases' : []} ]}, |
| 109 | 'nvptx64--nvidiacl' : { 'devices' : [{'gpu' : '', 'aliases' : []} ]}, |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Jan Vesely | 70c5f9d | 2018-09-15 22:02:01 +0000 | [diff] [blame] | 112 | # Support for gfx9 was added in LLVM 5 (r295554) |
| 113 | if llvm_int_version >= 500: |
| 114 | available_targets['amdgcn--']['devices'][0]['aliases'] += ['gfx900', 'gfx902'] |
| 115 | available_targets['amdgcn--amdhsa']['devices'][0]['aliases'] += ['gfx900', 'gfx902'] |
| 116 | |
| 117 | # Support for Vega12 and Vega20 was added in LLVM 7 (r331215) |
| 118 | if llvm_int_version >= 700: |
| 119 | available_targets['amdgcn--']['devices'][0]['aliases'] += ['gfx904', 'gfx906'] |
| 120 | available_targets['amdgcn--amdhsa']['devices'][0]['aliases'] += ['gfx904', 'gfx906'] |
| 121 | |
Tom Stellard | 6b195ec | 2016-09-16 22:43:33 +0000 | [diff] [blame] | 122 | |
Jan Vesely | ce29e8c | 2017-09-29 19:06:41 +0000 | [diff] [blame] | 123 | default_targets = ['nvptx--nvidiacl', 'nvptx64--nvidiacl', 'r600--', 'amdgcn--', 'amdgcn--amdhsa'] |
| 124 | |
| 125 | #mesa is using amdgcn-mesa-mesa3d since llvm-4.0 |
| 126 | if llvm_int_version > 390: |
| 127 | available_targets['amdgcn-mesa-mesa3d'] = available_targets['amdgcn--'] |
| 128 | default_targets.append('amdgcn-mesa-mesa3d') |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 129 | |
| 130 | targets = args |
| 131 | if not targets: |
| 132 | targets = default_targets |
| 133 | |
| 134 | b = metabuild.from_name(options.g) |
| 135 | |
| 136 | b.rule("LLVM_AS", "%s -o $out $in" % os.path.join(llvm_bindir, "llvm-as"), |
| 137 | 'LLVM-AS $out') |
| 138 | b.rule("LLVM_LINK", command = llvm_link + " -o $out $in", |
| 139 | description = 'LLVM-LINK $out') |
| 140 | b.rule("OPT", command = llvm_opt + " -O3 -o $out $in", |
| 141 | description = 'OPT $out') |
| 142 | |
Tom Stellard | 9f48bb3 | 2013-10-23 02:49:27 +0000 | [diff] [blame] | 143 | c_compiler_rule(b, "LLVM_TOOL_CXX", 'CXX', cxx_compiler, llvm_cxxflags) |
Jan Vesely | 6249614 | 2014-09-02 17:54:59 +0000 | [diff] [blame] | 144 | b.rule("LLVM_TOOL_LINK", cxx_compiler + " -o $out $in %s" % llvm_core_libs + " -Wl,-rpath %s" % llvm_libdir, 'LINK $out') |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 145 | |
| 146 | prepare_builtins = os.path.join('utils', 'prepare-builtins') |
| 147 | b.build(os.path.join('utils', 'prepare-builtins.o'), "LLVM_TOOL_CXX", |
| 148 | os.path.join(srcdir, 'utils', 'prepare-builtins.cpp')) |
| 149 | b.build(prepare_builtins, "LLVM_TOOL_LINK", |
| 150 | os.path.join('utils', 'prepare-builtins.o')) |
| 151 | |
| 152 | b.rule("PREPARE_BUILTINS", "%s -o $out $in" % prepare_builtins, |
| 153 | 'PREPARE-BUILTINS $out') |
Tom Stellard | f21e3ea | 2013-10-10 19:09:01 +0000 | [diff] [blame] | 154 | b.rule("PYTHON_GEN", "python < $in > $out", "PYTHON_GEN $out") |
| 155 | b.build('generic/lib/convert.cl', "PYTHON_GEN", ['generic/lib/gen_convert.py']) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 156 | |
| 157 | manifest_deps = set([sys.argv[0], os.path.join(srcdir, 'build', 'metabuild.py'), |
| 158 | os.path.join(srcdir, 'build', 'ninja_syntax.py')]) |
| 159 | |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 160 | install_files_bc = [] |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 161 | install_deps = [] |
| 162 | |
Tom Stellard | d9ca1f1 | 2015-04-20 18:49:50 +0000 | [diff] [blame] | 163 | # Create rules for subnormal helper objects |
| 164 | for src in ['subnormal_disable.ll', 'subnormal_use_default.ll']: |
| 165 | obj_name = src[:-2] + 'bc' |
| 166 | obj = os.path.join('generic--', 'lib', obj_name) |
| 167 | src_file = os.path.join('generic', 'lib', src) |
| 168 | b.build(obj, 'LLVM_AS', src_file) |
| 169 | b.default(obj) |
| 170 | install_files_bc.append((obj, obj)) |
| 171 | install_deps.append(obj) |
| 172 | |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 173 | # Create libclc.pc |
| 174 | clc = open('libclc.pc', 'w') |
| 175 | clc.write('includedir=%(inc)s\nlibexecdir=%(lib)s\n\nName: libclc\nDescription: Library requirements of the OpenCL C programming language\nVersion: %(maj)s.%(min)s.%(pat)s\nCflags: -I${includedir}\nLibs: -L${libexecdir}' % |
| 176 | {'inc': includedir, 'lib': libexecdir, 'maj': version_major, 'min': version_minor, 'pat': version_patch}) |
| 177 | clc.close() |
| 178 | |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 179 | for target in targets: |
| 180 | (t_arch, t_vendor, t_os) = target.split('-') |
| 181 | archs = [t_arch] |
Peter Collingbourne | a3fc645 | 2012-05-28 20:42:15 +0000 | [diff] [blame] | 182 | if t_arch == 'nvptx' or t_arch == 'nvptx64': |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 183 | archs.append('ptx') |
| 184 | archs.append('generic') |
| 185 | |
| 186 | subdirs = [] |
| 187 | for arch in archs: |
| 188 | subdirs.append("%s-%s-%s" % (arch, t_vendor, t_os)) |
| 189 | subdirs.append("%s-%s" % (arch, t_os)) |
| 190 | subdirs.append(arch) |
Matt Arsenault | a48e15c | 2016-02-13 01:01:59 +0000 | [diff] [blame] | 191 | if arch == 'amdgcn' or arch == 'r600': |
| 192 | subdirs.append('amdgpu') |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 193 | |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 194 | incdirs = filter(os.path.isdir, |
| 195 | [os.path.join(srcdir, subdir, 'include') for subdir in subdirs]) |
Jan Vesely | 3913056 | 2017-10-05 20:16:28 +0000 | [diff] [blame] | 196 | libdirs = filter(lambda d: os.path.isfile(os.path.join(d, 'SOURCES')) or |
| 197 | os.path.isfile(os.path.join(d, 'SOURCES_' + llvm_string_version)), |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 198 | [os.path.join(srcdir, subdir, 'lib') for subdir in subdirs]) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 199 | |
Jan Vesely | a4a20cd | 2017-08-02 15:00:59 +0000 | [diff] [blame] | 200 | # The above are iterables in python3 but we might use them multiple times |
| 201 | # if more then one device is supported. |
| 202 | incdirs = list(incdirs) |
| 203 | libdirs = list(libdirs) |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 204 | clang_cl_includes = ' '.join(["-I%s" % incdir for incdir in incdirs]) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 205 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 206 | for device in available_targets[target]['devices']: |
| 207 | # The rule for building a .bc file for the specified architecture using clang. |
| 208 | clang_bc_flags = "-target %s -I`dirname $in` %s " \ |
Aaron Watry | 8ef48d0 | 2013-12-29 16:39:55 +0000 | [diff] [blame] | 209 | "-fno-builtin " \ |
Tom Stellard | 6c7b86c | 2013-10-10 19:08:51 +0000 | [diff] [blame] | 210 | "-D__CLC_INTERNAL " \ |
Jan Vesely | e97deff | 2016-06-17 20:30:50 +0000 | [diff] [blame] | 211 | "-emit-llvm" % (target, clang_cl_includes) |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 212 | if device['gpu'] != '': |
| 213 | clang_bc_flags += ' -mcpu=' + device['gpu'] |
Tom Stellard | 8a3770a | 2014-01-29 20:03:27 +0000 | [diff] [blame] | 214 | clang_bc_rule = "CLANG_CL_BC_" + target + "_" + device['gpu'] |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 215 | c_compiler_rule(b, clang_bc_rule, "LLVM-CC", llvm_clang, clang_bc_flags) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 216 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 217 | objects = [] |
| 218 | sources_seen = set() |
Jan Vesely | b9dbaae | 2017-09-08 23:58:53 +0000 | [diff] [blame] | 219 | compats = [] |
Tom Stellard | d54f6ba | 2013-06-26 18:20:05 +0000 | [diff] [blame] | 220 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 221 | if device['gpu'] == '': |
| 222 | full_target_name = target |
| 223 | obj_suffix = '' |
| 224 | else: |
| 225 | full_target_name = device['gpu'] + '-' + target |
| 226 | obj_suffix = '.' + device['gpu'] |
Tom Stellard | d54f6ba | 2013-06-26 18:20:05 +0000 | [diff] [blame] | 227 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 228 | for libdir in libdirs: |
| 229 | subdir_list_file = os.path.join(libdir, 'SOURCES') |
Jan Vesely | 3913056 | 2017-10-05 20:16:28 +0000 | [diff] [blame] | 230 | if os.path.exists(subdir_list_file): |
| 231 | manifest_deps.add(subdir_list_file) |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 232 | override_list_file = os.path.join(libdir, 'OVERRIDES') |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 233 | compat_list_file = os.path.join(libdir, |
| 234 | 'SOURCES_' + llvm_string_version) |
Jan Vesely | ce29e8c | 2017-09-29 19:06:41 +0000 | [diff] [blame] | 235 | compat_list_override = os.path.join(libdir, |
| 236 | 'OVERRIDES_' + llvm_string_version) |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 237 | |
| 238 | # Build compat list |
| 239 | if os.path.exists(compat_list_file): |
Jan Vesely | 3913056 | 2017-10-05 20:16:28 +0000 | [diff] [blame] | 240 | manifest_deps.add(compat_list_file) |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 241 | for compat in open(compat_list_file).readlines(): |
| 242 | compat = compat.rstrip() |
Jan Vesely | b9dbaae | 2017-09-08 23:58:53 +0000 | [diff] [blame] | 243 | compats.append(compat) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 244 | |
Jan Vesely | ce29e8c | 2017-09-29 19:06:41 +0000 | [diff] [blame] | 245 | # Add target compat overrides |
| 246 | if os.path.exists(compat_list_override): |
| 247 | for override in open(compat_list_override).readlines(): |
| 248 | override = override.rstrip() |
| 249 | sources_seen.add(override) |
| 250 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 251 | # Add target overrides |
| 252 | if os.path.exists(override_list_file): |
| 253 | for override in open(override_list_file).readlines(): |
| 254 | override = override.rstrip() |
| 255 | sources_seen.add(override) |
| 256 | |
Jan Vesely | 3913056 | 2017-10-05 20:16:28 +0000 | [diff] [blame] | 257 | files = open(subdir_list_file).readlines() if os.path.exists(subdir_list_file) else [] |
| 258 | for src in files + compats: |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 259 | src = src.rstrip() |
| 260 | if src not in sources_seen: |
| 261 | sources_seen.add(src) |
| 262 | obj = os.path.join(target, 'lib', src + obj_suffix + '.bc') |
| 263 | objects.append(obj) |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 264 | src_path = libdir |
Tom Stellard | ba742f5 | 2015-04-29 15:37:06 +0000 | [diff] [blame] | 265 | src_file = os.path.join(src_path, src) |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 266 | ext = os.path.splitext(src)[1] |
| 267 | if ext == '.ll': |
| 268 | b.build(obj, 'LLVM_AS', src_file) |
| 269 | else: |
| 270 | b.build(obj, clang_bc_rule, src_file) |
| 271 | |
Tom Stellard | d9ca1f1 | 2015-04-20 18:49:50 +0000 | [diff] [blame] | 272 | obj = os.path.join('generic--', 'lib', 'subnormal_use_default.bc') |
| 273 | if not options.enable_runtime_subnormal: |
| 274 | objects.append(obj) |
| 275 | |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 276 | builtins_link_bc = os.path.join(target, 'lib', 'builtins.link' + obj_suffix + '.bc') |
| 277 | builtins_opt_bc = os.path.join(target, 'lib', 'builtins.opt' + obj_suffix + '.bc') |
| 278 | builtins_bc = os.path.join('built_libs', full_target_name + '.bc') |
| 279 | b.build(builtins_link_bc, "LLVM_LINK", objects) |
| 280 | b.build(builtins_opt_bc, "OPT", builtins_link_bc) |
| 281 | b.build(builtins_bc, "PREPARE_BUILTINS", builtins_opt_bc, prepare_builtins) |
| 282 | install_files_bc.append((builtins_bc, builtins_bc)) |
| 283 | install_deps.append(builtins_bc) |
| 284 | for alias in device['aliases']: |
Tom Stellard | 8a3770a | 2014-01-29 20:03:27 +0000 | [diff] [blame] | 285 | # Ninja cannot have multiple rules with same name so append suffix |
| 286 | ruleName = "CREATE_ALIAS_{0}_for_{1}".format(alias, device['gpu']) |
| 287 | b.rule(ruleName, "ln -fs %s $out" % os.path.basename(builtins_bc) |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 288 | ,"CREATE-ALIAS $out") |
| 289 | |
| 290 | alias_file = os.path.join('built_libs', alias + '-' + target + '.bc') |
Tom Stellard | 8a3770a | 2014-01-29 20:03:27 +0000 | [diff] [blame] | 291 | b.build(alias_file, ruleName, builtins_bc) |
Tom Stellard | 30f554b | 2013-06-26 18:20:38 +0000 | [diff] [blame] | 292 | install_files_bc.append((alias_file, alias_file)) |
| 293 | install_deps.append(alias_file) |
| 294 | b.default(builtins_bc) |
Peter Collingbourne | bae6833 | 2012-06-01 17:29:59 +0000 | [diff] [blame] | 295 | |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 296 | |
Tom Stellard | 91d51db | 2014-01-29 20:03:26 +0000 | [diff] [blame] | 297 | install_cmd = ' && '.join(['mkdir -p ${DESTDIR}/%(dst)s && cp -r %(src)s ${DESTDIR}/%(dst)s' % |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 298 | {'src': file, |
| 299 | 'dst': libexecdir} |
| 300 | for (file, dest) in install_files_bc]) |
Tom Stellard | 91d51db | 2014-01-29 20:03:26 +0000 | [diff] [blame] | 301 | install_cmd = ' && '.join(['%(old)s && mkdir -p ${DESTDIR}/%(dst)s && cp -r %(srcdir)s/generic/include/clc ${DESTDIR}/%(dst)s' % |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 302 | {'old': install_cmd, |
Tom Stellard | 5668ea2 | 2013-06-26 18:20:35 +0000 | [diff] [blame] | 303 | 'dst': includedir, |
| 304 | 'srcdir': srcdir}]) |
Tom Stellard | 91d51db | 2014-01-29 20:03:26 +0000 | [diff] [blame] | 305 | install_cmd = ' && '.join(['%(old)s && mkdir -p ${DESTDIR}/%(dst)s && cp -r libclc.pc ${DESTDIR}/%(dst)s' % |
Tom Stellard | 1de7761 | 2013-06-26 18:20:03 +0000 | [diff] [blame] | 306 | {'old': install_cmd, |
| 307 | 'dst': pkgconfigdir}]) |
| 308 | |
| 309 | b.rule('install', command = install_cmd, description = 'INSTALL') |
| 310 | b.build('install', 'install', install_deps) |
Peter Collingbourne | d5395fb | 2012-01-08 22:09:58 +0000 | [diff] [blame] | 311 | |
| 312 | b.rule("configure", command = ' '.join(sys.argv), description = 'CONFIGURE', |
| 313 | generator = True) |
| 314 | b.build(b.output_filename(), 'configure', list(manifest_deps)) |
| 315 | |
| 316 | b.finish() |