diff options
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-multilib-config.inc')
-rw-r--r-- | meta/recipes-devtools/gcc/gcc-multilib-config.inc | 190 |
1 files changed, 190 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..9403aab0bd --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc-multilib-config.inc | |||
@@ -0,0 +1,190 @@ | |||
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.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 | if ('%sgcc' % mlprefix) != d.getVar('PN', True): | ||
45 | return | ||
46 | |||
47 | |||
48 | def write_config(root, files, options, dirnames, osdirnames): | ||
49 | for ml_conf_file in files: | ||
50 | with open(root + '/' + ml_conf_file, 'r') as f: | ||
51 | filelines = f.readlines() | ||
52 | # recreate multilib configuration variables | ||
53 | substs = [ | ||
54 | (r'^(\s*(MULTILIB_OPTIONS\s*=).*)$', r'\2 %s' % '/'.join(options)), | ||
55 | (r'^(\s*MULTILIB_OPTIONS\s*\+=.*)$', ''), | ||
56 | (r'^(\s*(MULTILIB_DIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(dirnames)), | ||
57 | (r'^(\s*MULTILIB_DIRNAMES\s*\+=.*)$', ''), | ||
58 | (r'^(\s*(MULTILIB_OSDIRNAMES\s*=).*)$', r'\2 %s' % ' '.join(osdirnames)), | ||
59 | (r'^(\s*MULTILIB_OSDIRNAMES\s*\+=.*)$', ''), | ||
60 | ] | ||
61 | |||
62 | for (i, line) in enumerate(filelines): | ||
63 | for subst in substs: | ||
64 | line = re.sub(subst[0], subst[1], line) | ||
65 | filelines[i] = line | ||
66 | |||
67 | with open(root + '/' + ml_conf_file, 'w') as f: | ||
68 | f.write(''.join(filelines)) | ||
69 | |||
70 | def write_headers(root, files, libdir32, libdir64, libdirx32, libdirn32): | ||
71 | def wrap_libdir(libdir): | ||
72 | if libdir.find('SYSTEMLIBS_DIR') != -1: | ||
73 | return libdir | ||
74 | else: | ||
75 | return '"/%s/"' % libdir | ||
76 | |||
77 | for ml_conf_file in files: | ||
78 | with open(root + '/' + ml_conf_file, 'r') as f: | ||
79 | filelines = f.readlines() | ||
80 | |||
81 | # replace lines like | ||
82 | # #define GLIBC_DYNAMIC_LINKER32 SYSTEMLIBS_DIR "ld-linux.so.2" | ||
83 | # by | ||
84 | # #define GLIBC_DYNAMIC_LINKER32 "/lib/" "ld-linux.so.2" | ||
85 | # this is needed to put the correct dynamic loader path in the generated binaries | ||
86 | substs = [ | ||
87 | (r'^(#define\s*GLIBC_DYNAMIC_LINKER32\s*)(\S+)(\s*\".*\")$', | ||
88 | r'\1' + wrap_libdir(libdir32) + r'\3'), | ||
89 | (r'^(#define\s*GLIBC_DYNAMIC_LINKER64\s*)(\S+)(\s*\".*\")$', | ||
90 | r'\1' + wrap_libdir(libdir64) + r'\3'), | ||
91 | (r'^(#define\s*GLIBC_DYNAMIC_LINKERX32\s*)(\S+)(\s*\".*\")$', | ||
92 | r'\1' + wrap_libdir(libdirx32) + r'\3'), | ||
93 | (r'^(#define\s*GLIBC_DYNAMIC_LINKERN32\s*)(\S+)(\s*\".*\")$', | ||
94 | r'\1' + wrap_libdir(libdirn32) + r'\3'), | ||
95 | ] | ||
96 | |||
97 | for (i, line) in enumerate(filelines): | ||
98 | for subst in substs: | ||
99 | line = re.sub(subst[0], subst[1], line) | ||
100 | filelines[i] = line | ||
101 | |||
102 | with open(root + '/' + ml_conf_file, 'w') as f: | ||
103 | f.write(''.join(filelines)) | ||
104 | |||
105 | |||
106 | gcc_target_config_files = { | ||
107 | 'x86_64' : ['gcc/config/i386/t-linux64'], | ||
108 | 'i586' : ['gcc/config/i386/t-linux64'], | ||
109 | 'mips' : ['gcc/config/mips/t-linux64'], | ||
110 | 'powerpc' : ['gcc/config/rs6000/t-linux64'], | ||
111 | } | ||
112 | |||
113 | gcc_header_config_files = { | ||
114 | 'x86_64' : ['gcc/config/i386/linux64.h'], | ||
115 | 'i586' : ['gcc/config/i386/linux64.h'], | ||
116 | 'mips' : ['gcc/config/mips/linux64.h'], | ||
117 | 'powerpc' : ['gcc/config/rs6000/linux64.h'], | ||
118 | } | ||
119 | |||
120 | target_arch = (d.getVar('TARGET_ARCH_MULTILIB_ORIGINAL', True) if mlprefix | ||
121 | else d.getVar('TARGET_ARCH', True)) | ||
122 | if target_arch not in gcc_target_config_files: | ||
123 | bb.warn('gcc multilib setup is not supported for TARGET_ARCH=' + target_arch) | ||
124 | return | ||
125 | |||
126 | libdir32 = 'SYSTEMLIBS_DIR' | ||
127 | libdir64 = 'SYSTEMLIBS_DIR' | ||
128 | libdirx32 = 'SYSTEMLIBS_DIR' | ||
129 | libdirn32 = 'SYSTEMLIBS_DIR' | ||
130 | |||
131 | target_config_files = gcc_target_config_files[target_arch] | ||
132 | header_config_files = gcc_header_config_files[target_arch] | ||
133 | |||
134 | ml_list = ['DEFAULTTUNE_MULTILIB_ORIGINAL' if mlprefix else 'DEFAULTTUNE'] | ||
135 | mltunes = [('DEFAULTTUNE_virtclass-multilib-%s' % ml) for ml in multilibs] | ||
136 | if mlprefix: | ||
137 | mlindex = 0 | ||
138 | for ml in multilibs: | ||
139 | if mlprefix.startswith(ml): | ||
140 | break | ||
141 | mlindex += 1 | ||
142 | |||
143 | ml_list.extend(mltunes[:mlindex] + ['DEFAULTTUNE'] + mltunes[(mlindex + 1):]) | ||
144 | else: | ||
145 | ml_list.extend(mltunes) | ||
146 | |||
147 | options = [] | ||
148 | dirnames = [] | ||
149 | osdirnames = [] | ||
150 | |||
151 | for ml in ml_list: | ||
152 | tune = d.getVar(ml, True) | ||
153 | if not tune: | ||
154 | bb.warn("%s doesn't have a corresponding tune. Skipping..." % ml) | ||
155 | continue | ||
156 | tune_parameters = get_tune_parameters(tune, d) | ||
157 | |||
158 | tune_baselib = tune_parameters['baselib'] | ||
159 | if not tune_baselib: | ||
160 | bb.warn("Tune %s doesn't have a baselib set. Skipping..." % tune) | ||
161 | continue | ||
162 | |||
163 | if tune_baselib == 'lib64': | ||
164 | libdir64 = tune_baselib | ||
165 | elif tune_baselib == 'libx32': | ||
166 | libdirx32 = tune_baselib | ||
167 | elif tune_baselib == 'lib32': | ||
168 | libdirn32 = tune_baselib | ||
169 | elif tune_baselib == 'lib': | ||
170 | libdir32 = tune_baselib | ||
171 | else: | ||
172 | bb.error('Unknown libdir (%s) of the tune : %s' % (tune_baselib, tune)) | ||
173 | |||
174 | # take out '-' and march='s from parameters | ||
175 | options.append(re.sub(r'march=[^ ]+ *', '', | ||
176 | re.sub(r' +\-+', ' ', | ||
177 | re.sub(r'^ *\-+', '', tune_parameters['ccargs'])))) | ||
178 | if tune_baselib == 'lib': | ||
179 | dirnames.append('32') # /lib => 32bit lib | ||
180 | else: | ||
181 | dirnames.append(tune_baselib.replace('lib', '')) | ||
182 | osdirnames.append('../' + tune_baselib) | ||
183 | |||
184 | write_config(builddir, target_config_files, options, dirnames, osdirnames) | ||
185 | write_headers(builddir, header_config_files, libdir32, libdir64, libdirx32, libdirn32) | ||
186 | } | ||
187 | |||
188 | gcc_multilib_setup[cleandirs] = "${B}/gcc/config" | ||
189 | |||
190 | EXTRACONFFUNCS += "gcc_multilib_setup" | ||