diff options
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-multilib-config.inc')
-rw-r--r-- | meta/recipes-devtools/gcc/gcc-multilib-config.inc | 191 |
1 files changed, 191 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..005aa6b814 --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc | |||
@@ -0,0 +1,191 @@ | |||
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 | |||
17 | python 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 | } | ||
113 | |||
114 | gcc_header_config_files = { | ||
115 | 'x86_64' : ['gcc/config/i386/linux64.h'], | ||
116 | 'i586' : ['gcc/config/i386/linux64.h'], | ||
117 | 'mips' : ['gcc/config/mips/linux64.h'], | ||
118 | 'powerpc' : ['gcc/config/rs6000/linux64.h'], | ||
119 | } | ||
120 | |||
121 | target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL', True) if mlprefix | ||
122 | else d.getVar('TARGET_ARCH', True)) | ||
123 | if target_arch not in gcc_target_config_files: | ||
124 | bb.warn('gcc multilib setup is not supported for TARGET_ARCH=' + target_arch) | ||
125 | return | ||
126 | |||
127 | libdir32 = 'SYSTEMLIBS_DIR' | ||
128 | libdir64 = 'SYSTEMLIBS_DIR' | ||
129 | libdirx32 = 'SYSTEMLIBS_DIR' | ||
130 | libdirn32 = 'SYSTEMLIBS_DIR' | ||
131 | |||
132 | target_config_files = gcc_target_config_files[target_arch] | ||
133 | header_config_files = gcc_header_config_files[target_arch] | ||
134 | |||
135 | ml_list = ['DEFAULTTUNE_MULTILIB_ORIGINAL' if mlprefix else 'DEFAULTTUNE'] | ||
136 | mltunes = [('DEFAULTTUNE_virtclass-multilib-%s' % ml) for ml in multilibs] | ||
137 | if mlprefix: | ||
138 | mlindex = 0 | ||
139 | for ml in multilibs: | ||
140 | if mlprefix.startswith(ml): | ||
141 | break | ||
142 | mlindex += 1 | ||
143 | |||
144 | ml_list.extend(mltunes[:mlindex] + ['DEFAULTTUNE'] + mltunes[(mlindex + 1):]) | ||
145 | else: | ||
146 | ml_list.extend(mltunes) | ||
147 | |||
148 | options = [] | ||
149 | dirnames = [] | ||
150 | osdirnames = [] | ||
151 | |||
152 | for ml in ml_list: | ||
153 | tune = d.getVar(ml, True) | ||
154 | if not tune: | ||
155 | bb.warn("%s doesn't have a corresponding tune. Skipping..." % ml) | ||
156 | continue | ||
157 | tune_parameters = get_tune_parameters(tune, d) | ||
158 | |||
159 | tune_baselib = tune_parameters['baselib'] | ||
160 | if not tune_baselib: | ||
161 | bb.warn("Tune %s doesn't have a baselib set. Skipping..." % tune) | ||
162 | continue | ||
163 | |||
164 | if tune_baselib == 'lib64': | ||
165 | libdir64 = tune_baselib | ||
166 | elif tune_baselib == 'libx32': | ||
167 | libdirx32 = tune_baselib | ||
168 | elif tune_baselib == 'lib32': | ||
169 | libdirn32 = tune_baselib | ||
170 | elif tune_baselib == 'lib': | ||
171 | libdir32 = tune_baselib | ||
172 | else: | ||
173 | bb.error('Unknown libdir (%s) of the tune : %s' % (tune_baselib, tune)) | ||
174 | |||
175 | # take out '-' and march='s from parameters | ||
176 | options.append(re.sub(r'march=[^ ]+ *', '', | ||
177 | re.sub(r' +\-+', ' ', | ||
178 | re.sub(r'^ *\-+', '', tune_parameters['ccargs'])))) | ||
179 | if tune_baselib == 'lib': | ||
180 | dirnames.append('32') # /lib => 32bit lib | ||
181 | else: | ||
182 | dirnames.append(tune_baselib.replace('lib', '')) | ||
183 | osdirnames.append('../' + tune_baselib) | ||
184 | |||
185 | write_config(builddir, target_config_files, options, dirnames, osdirnames) | ||
186 | write_headers(builddir, header_config_files, libdir32, libdir64, libdirx32, libdirn32) | ||
187 | } | ||
188 | |||
189 | gcc_multilib_setup[cleandirs] = "${B}/gcc/config" | ||
190 | |||
191 | EXTRACONFFUNCS += "gcc_multilib_setup" | ||