summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-multilib-config.inc
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-multilib-config.inc')
-rw-r--r--meta/recipes-devtools/gcc/gcc-multilib-config.inc209
1 files changed, 209 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-multilib-config.inc b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
new file mode 100644
index 0000000000..1eafeb4768
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc
@@ -0,0 +1,209 @@
1# following code modifies these definitions in the gcc config
2# MULTILIB_OPTIONS
3# MULTILIB_DIRNAMES
4# MULTILIB_OSDIRNAMES
5# GLIBC_DYNAMIC_LINKER32
6# GLIBC_DYNAMIC_LINKER64
7# GLIBC_DYNAMIC_LINKERX32
8# GLIBC_DYNAMIC_LINKERN32
9# For more information on use of these variables look at these files in the gcc source code
10# gcc/config/i386/t-linux64
11# gcc/config/mips/t-linux64
12# gcc/config/rs6000/t-linux64
13# gcc/config/i386/linux64.h
14# gcc/config/mips/linux64.h
15# gcc/config/rs6000/linux64.h
16
17python gcc_multilib_setup() {
18 import re
19 import shutil
20 import glob
21
22 srcdir = d.getVar('S', True)
23 builddir = d.getVar('B', True)
24 src_conf_dir = '%s/gcc/config' % srcdir
25 build_conf_dir = '%s/gcc/config' % builddir
26
27 bb.utils.remove(build_conf_dir, True)
28 ml_globs = ('%s/*/t-linux64' % src_conf_dir,
29 '%s/*/linux64.h' % src_conf_dir)
30
31 # copy the target multilib config files to ${B}
32 for ml_glob in ml_globs:
33 for fn in glob.glob(ml_glob):
34 rel_path = os.path.relpath(fn, src_conf_dir)
35 parent_dir = os.path.dirname(rel_path)
36 bb.utils.mkdirhier('%s/%s' % (build_conf_dir, parent_dir))
37 bb.utils.copyfile(fn, '%s/%s' % (build_conf_dir, rel_path))
38
39 multilibs = (d.getVar('MULTILIB_VARIANTS', True) or '').split()
40 if not multilibs:
41 return
42
43 mlprefix = d.getVar('MLPREFIX', True)
44 pn = d.getVar('PN', True)
45 if ('%sgcc' % mlprefix) != pn and (not pn.startswith('gcc-cross-canadian')):
46 return
47
48
49 def write_config(root, files, options, dirnames, osdirnames):
50 for ml_conf_file in files:
51 with open(root + '/' + ml_conf_file, 'r') as f:
52 filelines = f.readlines()
53 # recreate multilib configuration variables
54 substs = [
55 (r'^(\s*(MULTILIB_OPTIONS\s*=).*)$', r'\2 %s' % '/'.join(options)),
56 (r'^(\s*MULTILIB_OPTIONS\s*\+=.*)$', ''),
57 (r'^(\s*(MULTILIB_DIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(dirnames)),
58 (r'^(\s*MULTILIB_DIRNAMES\s*\+=.*)$', ''),
59 (r'^(\s*(MULTILIB_OSDIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(osdirnames)),
60 (r'^(\s*MULTILIB_OSDIRNAMES\s*\+=.*)$', ''),
61 ]
62
63 for (i, line) in enumerate(filelines):
64 for subst in substs:
65 line = re.sub(subst[0], subst[1], line)
66 filelines[i] = line
67
68 with open(root + '/' + ml_conf_file, 'w') as f:
69 f.write(''.join(filelines))
70
71 def write_headers(root, files, libdir32, libdir64, libdirx32, libdirn32):
72 def wrap_libdir(libdir):
73 if libdir.find('SYSTEMLIBS_DIR') != -1:
74 return libdir
75 else:
76 return '"/%s/"' % libdir
77
78 for ml_conf_file in files:
79 with open(root + '/' + ml_conf_file, 'r') as f:
80 filelines = f.readlines()
81
82 # replace lines like
83 # #define GLIBC_DYNAMIC_LINKER32 SYSTEMLIBS_DIR "ld-linux.so.2"
84 # by
85 # #define GLIBC_DYNAMIC_LINKER32 "/lib/" "ld-linux.so.2"
86 # this is needed to put the correct dynamic loader path in the generated binaries
87 substs = [
88 (r'^(#define\s*GLIBC_DYNAMIC_LINKER32\s*)(\S+)(\s*\".*\")$',
89 r'\1' + wrap_libdir(libdir32) + r'\3'),
90 (r'^(#define\s*GLIBC_DYNAMIC_LINKER64\s*)(\S+)(\s*\".*\")$',
91 r'\1' + wrap_libdir(libdir64) + r'\3'),
92 (r'^(#define\s*GLIBC_DYNAMIC_LINKERX32\s*)(\S+)(\s*\".*\")$',
93 r'\1' + wrap_libdir(libdirx32) + r'\3'),
94 (r'^(#define\s*GLIBC_DYNAMIC_LINKERN32\s*)(\S+)(\s*\".*\")$',
95 r'\1' + wrap_libdir(libdirn32) + r'\3'),
96 ]
97
98 for (i, line) in enumerate(filelines):
99 for subst in substs:
100 line = re.sub(subst[0], subst[1], line)
101 filelines[i] = line
102
103 with open(root + '/' + ml_conf_file, 'w') as f:
104 f.write(''.join(filelines))
105
106
107 gcc_target_config_files = {
108 'x86_64' : ['gcc/config/i386/t-linux64'],
109 'i586' : ['gcc/config/i386/t-linux64'],
110 'mips' : ['gcc/config/mips/t-linux64'],
111 'powerpc' : ['gcc/config/rs6000/t-linux64'],
112 'powerpc64' : ['gcc/config/rs6000/t-linux64'],
113 }
114
115 gcc_header_config_files = {
116 'x86_64' : ['gcc/config/i386/linux64.h'],
117 'i586' : ['gcc/config/i386/linux64.h'],
118 'mips' : ['gcc/config/mips/linux64.h'],
119 'powerpc' : ['gcc/config/rs6000/linux64.h'],
120 'powerpc64' : ['gcc/config/rs6000/linux64.h'],
121 }
122
123 target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL', True) if mlprefix
124 else d.getVar('TARGET_ARCH', True))
125 if target_arch not in gcc_target_config_files:
126 bb.warn('gcc multilib setup is not supported for TARGET_ARCH=' + target_arch)
127 return
128
129 libdir32 = 'SYSTEMLIBS_DIR'
130 libdir64 = 'SYSTEMLIBS_DIR'
131 libdirx32 = 'SYSTEMLIBS_DIR'
132 libdirn32 = 'SYSTEMLIBS_DIR'
133
134 target_config_files = gcc_target_config_files[target_arch]
135 header_config_files = gcc_header_config_files[target_arch]
136
137 ml_list = ['DEFAULTTUNE_MULTILIB_ORIGINAL' if mlprefix else 'DEFAULTTUNE']
138 mltunes = [('DEFAULTTUNE_virtclass-multilib-%s' % ml) for ml in multilibs]
139 if mlprefix:
140 mlindex = 0
141 for ml in multilibs:
142 if mlprefix.startswith(ml):
143 break
144 mlindex += 1
145
146 ml_list.extend(mltunes[:mlindex] + ['DEFAULTTUNE'] + mltunes[(mlindex + 1):])
147 else:
148 ml_list.extend(mltunes)
149
150 options = []
151 dirnames = []
152 osdirnames = []
153 optsets = []
154
155 for ml in ml_list:
156 tune = d.getVar(ml, True)
157 if not tune:
158 bb.warn("%s doesn't have a corresponding tune. Skipping..." % ml)
159 continue
160 tune_parameters = get_tune_parameters(tune, d)
161
162 tune_baselib = tune_parameters['baselib']
163 if not tune_baselib:
164 bb.warn("Tune %s doesn't have a baselib set. Skipping..." % tune)
165 continue
166
167 if tune_baselib == 'lib64':
168 libdir64 = tune_baselib
169 elif tune_baselib == 'libx32':
170 libdirx32 = tune_baselib
171 elif tune_baselib == 'lib32':
172 libdirn32 = tune_baselib
173 elif tune_baselib == 'lib':
174 libdir32 = tune_baselib
175 else:
176 bb.error('Unknown libdir (%s) of the tune : %s' % (tune_baselib, tune))
177
178 # take out '-' mcpu='s and march='s from parameters
179 options.append(re.sub(r'mcpu=[^ ]+ *', '',
180 re.sub(r'march=[^ ]+ *', '',
181 re.sub(r' +\-+', ' ',
182 re.sub(r'^ *\-+', '', tune_parameters['ccargs'])))))
183 if tune_baselib == 'lib':
184 dirnames.append('32') # /lib => 32bit lib
185 else:
186 dirnames.append(tune_baselib.replace('lib', ''))
187 osdirnames.append('../' + tune_baselib)
188
189 if len(options) > 1:
190 for optstr in options:
191 optsets.append(optstr.split())
192
193 #get common options present in all the tune parameters
194 common_opt_set = set.intersection(*map(set, optsets))
195
196 #common options will be added at the end of the options string only once
197 if (len(common_opt_set) > 0):
198 rex = re.compile(''.join(['\\b(', '|'.join(common_opt_set), ')\\W']), re.I)
199 options = [rex.sub("", optstr) for optstr in options]
200 options = [optstr.strip() for optstr in options]
201 options[len(options)-1] = ' '.join((options[len(options)-1], ' '.join(common_opt_set)))
202
203 write_config(builddir, target_config_files, options, dirnames, osdirnames)
204 write_headers(builddir, header_config_files, libdir32, libdir64, libdirx32, libdirn32)
205}
206
207gcc_multilib_setup[cleandirs] = "${B}/gcc/config"
208
209EXTRACONFFUNCS += "gcc_multilib_setup"