Gentoo Archives: gentoo-alt

From: "Eduardo Mendonça" <eduardomendoncapt@×××××.com>
To: gentoo-alt@l.g.o
Subject: [gentoo-alt] [prefix] fix_libtools_files.sh
Date: Tue, 29 May 2007 22:24:35
Message-Id: 465CA808.2000902@gmail.com
1 After I compiled gcc 4.2 I got:
2
3 $ fix_libtool_files.sh 4.0.1
4 /Gentoo/sbin/fix_libtool_files.sh: line 42: /etc/init.d/functions.sh: No
5 such file or directory
6
7
8 I don't know if it is of any help, but I think I manage to make
9 fix_libtools_files.sh script working.
10 First I had problems with the tags: @GENTOO_PORTAGE_EPREFIX@. This
11 didn't work for me. So I changed them for the actual EPREFIX... I know
12 this is not a god way to go, anyone has any comments or ideas on what
13 might be the good change?
14
15 Also, begin prefix portage, I removed the root restrictions... of course
16 this seems a bad way to go a simple if-then-else could have solve it in
17 a nicer way. Comments?
18
19 After, I had to change awk fixlafiles script. I wrote it down if anyone
20 needs it. I'm not 100% sure that this is ok, but it worked for me.
21
22 Best regards,
23 Eduardo Mendonça
24
25 ===== fixlafiles.awk =====
26
27
28 $ cat ${EPREFIX}/lib/rcscripts/awk/fixlafiles.awk
29 # Copyright 1999-2005 Gentoo Foundation
30 # Distributed under the terms of the GNU General Public License v2
31 # $Header:
32 /var/cvsroot/gentoo-x86/sys-devel/gcc/files/awk/fixlafiles.awk-no_gcc_la,v
33 1.2 2006/05/15 00:17:46 vapier Exp $
34
35 #
36 # Helper functions
37 #
38 function printn(string) {
39 system("echo -n \"" string "\"")
40 }
41 function einfo(string) {
42 system("echo -e \" \\e[32;01m*\\e[0m " string "\"")
43 }
44 function einfon(string) {
45 system("echo -ne \" \\e[32;01m*\\e[0m " string "\"")
46 }
47 function ewarn(string) {
48 system("echo -e \" \\e[33;01m*\\e[0m " string "\"")
49 }
50 function ewarnn(string) {
51 system("echo -ne \" \\e[33;01m*\\e[0m " string "\"")
52 }
53 function eerror(string) {
54 system("echo -e \" \\e[31;01m*\\e[0m " string "\"")
55 }
56
57 #
58 # assert(condition, errmsg)
59 # assert that a condition is true. Otherwise exit.
60 #
61 function assert(condition, string) {
62 if (! condition) {
63 printf("%s:%d: assertion failed: %s\n",
64 FILENAME, FNR, string) > "/dev/stderr"
65 _assert_exit = 1
66 exit 1
67 }
68 }
69
70 #
71 # system(command, return)
72 # wrapper that normalizes return codes ...
73 #
74 function dosystem(command, ret) {
75 ret = 0
76 ret = system(command)
77 if (ret == 0)
78 return 1
79 else
80 return 0
81 }
82
83 BEGIN {
84 #
85 # Get our variables from environment
86 #
87 OLDVER = ENVIRON["OLDVER"]
88 OLDCHOST = ENVIRON["OLDCHOST"]
89
90 if (OLDVER == "") {
91 eerror("Could not get OLDVER!");
92 exit 1
93 }
94
95 # Setup some sane defaults
96 LIBCOUNT = 2
97 HAVE_GCC34 = 0
98 DIRLIST[1] = "${EPREFIX}/lib"
99 DIRLIST[2] = "${EPREFIX}/usr/lib"
100
101 #
102 # Walk /etc/ld.so.conf to discover all our library paths
103 #
104 pipe = "cat ${EPREFIX}/etc/ld.so.conf | sort 2>/dev/null"
105 while(((pipe) | getline ldsoconf_data) > 0) {
106 if (ldsoconf_data !~ /^[[:space:]]*#/) {
107 if (ldsoconf_data == "") continue
108
109 # Remove any trailing comments
110 sub(/#.*$/, "", ldsoconf_data)
111 # Remove any trailing spaces
112 sub(/[[:space:]]+$/, "", ldsoconf_data)
113
114 # If there's more than one path per line, split
115 # it up as if they were sep lines
116 split(ldsoconf_data, nodes, /[:,[:space:]]/)
117
118 # Now add the rest from ld.so.conf
119 for (x in nodes) {
120 # wtf does this line do ?
121 sub(/=.*/, "", nodes[x])
122 # Prune trailing /
123 sub(/\/$/, "", nodes[x])
124
125 if (nodes[x] == "") continue
126
127 #
128 # Drop the directory if its a child
129 directory of
130 # one that was already added ...
131 # For example, if we have:
132 # /usr/lib /usr/libexec
133 /usr/lib/mozilla /usr/lib/nss
134 # We really just want to save /usr/lib
135 /usr/libexec
136 #
137 CHILD = 0
138 for (y in DIRLIST) {
139 if (nodes[x] ~ "^" DIRLIST[y]
140 "(/|$)") {
141 CHILD = 1
142 break
143 }
144 }
145 if (CHILD) continue
146
147 DIRLIST[++LIBCOUNT] = nodes[x]
148 }
149 }
150 }
151 close(pipe)
152
153 #
154 # Get line from gcc's output containing CHOST
155 #
156 pipe = "gcc -print-file-name=libgcc.a 2>/dev/null"
157 if ((!((pipe) | getline TMP_CHOST)) || (TMP_CHOST == "")) {
158 close(pipe)
159
160 # If we fail to get the CHOST, see if we can get the CHOST
161 # portage thinks we are using ...
162 pipe = "/usr/bin/portageq envvar 'CHOST'"
163 assert(((pipe) | getline CHOST), "(" pipe ") | getline
164 CHOST")
165 } else {
166 # Check pre gcc-3.4.x versions
167 CHOST = gensub("^.+lib/gcc-lib/([^/]+)/[0-9]+.+$",
168 "\\1", 1, TMP_CHOST)
169
170 if (CHOST == TMP_CHOST || CHOST == "") {
171 # Check gcc-3.4.x or later
172 CHOST = gensub("^.+lib/gcc/([^/]+)/[0-9]+.+$",
173 "\\1", 1, TMP_CHOST);
174
175 if (CHOST == TMP_CHOST || CHOST == "")
176 CHOST = ""
177 else
178 HAVE_GCC34 = 1
179 }
180 }
181 close(pipe)
182
183 if (CHOST == "") {
184 eerror("Could not get gcc's CHOST!")
185 exit 1
186 }
187
188 if (OLDCHOST != "")
189 if (OLDCHOST == CHOST)
190 OLDCHOST = ""
191
192 GCCLIBPREFIX_OLD = "${EPREIFX}/usr/lib/gcc-lib/"
193 GCCLIBPREFIX_NEW = "${EPREFIX}/usr/lib/gcc/"
194
195 if (HAVE_GCC34)
196 GCCLIBPREFIX = GCCLIBPREFIX_NEW
197 else
198 GCCLIBPREFIX = GCCLIBPREFIX_OLD
199
200 GCCLIB = GCCLIBPREFIX CHOST
201
202 if (OLDCHOST != "") {
203 OLDGCCLIB1 = GCCLIBPREFIX_OLD OLDCHOST
204 OLDGCCLIB2 = GCCLIBPREFIX_NEW OLDCHOST
205 }
206
207 # Get current gcc's version
208 pipe = "gcc -dumpversion"
209 assert(((pipe) | getline NEWVER), "(" pipe ") | getline NEWVER)")
210 close(pipe)
211
212 if (NEWVER == "") {
213 eerror("Could not get gcc's version!")
214 exit 1
215 }
216
217 # Nothing to do ?
218 # NB: Do not check for (OLDVER == NEWVER) anymore, as we might
219 need to
220 # replace libstdc++.la ....
221 if ((OLDVER == "") && (OLDCHOST == ""))
222 exit 0
223
224 #
225 # Ok, now let's scan for the .la files and actually fix them up
226 #
227 for (x = 1; x <= LIBCOUNT; x++) {
228 # Do nothing if the target dir is gcc's internal library
229 path
230 if (DIRLIST[x] ~ GCCLIBPREFIX_OLD ||
231 DIRLIST[x] ~ GCCLIBPREFIX_NEW)
232 continue
233
234 einfo(" [" x "/" LIBCOUNT "] Scanning " DIRLIST[x] " ...")
235
236 pipe = "find " DIRLIST[x] "/ -name '*.la' 2>/dev/null"
237 while (((pipe) | getline la_files) > 0) {
238
239 # Do nothing if the .la file is located in gcc's
240 internal lib path
241 if (la_files ~ GCCLIBPREFIX_OLD ||
242 la_files ~ GCCLIBPREFIX_NEW)
243 continue
244
245 CHANGED = 0
246 CHOST_CHANGED = 0
247
248 # See if we need to fix the .la file
249 while ((getline la_data < (la_files)) > 0) {
250 if (OLDCHOST != "") {
251 if ((gsub(OLDGCCLIB1
252 "[/[:space:]]+",
253 GCCLIB, la_data) > 0) ||
254 (gsub(OLDGCCLIB2
255 "[/[:space:]]+",
256 GCCLIB, la_data) > 0)) {
257 CHANGED = 1
258 CHOST_CHANGED = 1
259 }
260 }
261 if (OLDVER != NEWVER) {
262 if ((gsub(GCCLIBPREFIX_OLD CHOST
263 "/" OLDVER "[/[:space:]]*",
264 GCCLIB "/" NEWVER,
265 la_data) > 0) ||
266 (gsub(GCCLIBPREFIX_NEW CHOST
267 "/" OLDVER "[/[:space:]]*",
268 GCCLIB "/" NEWVER,
269 la_data) > 0))
270 CHANGED = 1
271 }
272 # We now check if we have libstdc++.la,
273 as we remove the
274 # libtool linker scripts for gcc ...
275 # We do this last, as we only match the
276 new paths
277 if (gsub(GCCLIB "/" NEWVER
278 "/libstdc\\+\\+\\.la",
279 "-lstdc++", la_data) > 0)
280 CHANGED = 1
281 }
282 close(la_files)
283
284 # Do the actual changes in a second loop, as we
285 can then
286 # verify that CHOST_CHANGED among things is
287 correct ...
288 if (CHANGED) {
289 ewarnn(" FIXING: " la_files " ...[")
290
291 # Clear the temp file (removing rather
292 than '>foo' is better
293 # out of a security point of view?)
294 dosystem("rm -f " la_files ".new")
295
296 while ((getline la_data < (la_files)) > 0) {
297 if (OLDCHOST != "") {
298 tmpstr =
299 gensub(OLDGCCLIB1 "([/[:space:]]+)",
300 GCCLIB
301 "\\1", "g", la_data)
302 tmpstr =
303 gensub(OLDGCCLIB2 "([/[:space:]]+)",
304 GCCLIB
305 "\\1", "g", tmpstr)
306
307 if (la_data != tmpstr) {
308 printn("c")
309 la_data = tmpstr
310 }
311
312 if (CHOST_CHANGED > 0) {
313 # We try to be
314 careful about CHOST changes outside
315 # the gcc
316 library path (meaning we cannot match it
317 # via
318 /GCCLIBPREFIX CHOST/) ...
319
320 # Catch:
321 #
322 #
323 dependency_libs=' -L/usr/CHOST/{bin,lib}'
324 #
325 gsub("-L/usr/"
326 OLDCHOST "/",
327 "-L/usr/"
328 CHOST "/", la_data)
329 # Catch:
330 #
331 #
332 dependency_libs=' -L/usr/lib/gcc-lib/CHOST/VER/../../../../CHOST/lib'
333 #
334 la_data =
335 gensub("(" GCCLIB "/[^[:space:]]+)/" OLDCHOST "/",
336
337 "\\1/" CHOST "/", "g", la_data)
338 }
339 }
340
341 if (OLDVER != NEWVER) {
342 # Catch:
343 #
344 # dependency_libs='
345 -L/usr/lib/gcc/CHOST/VER'
346 #
347 tmpstr =
348 gensub(GCCLIBPREFIX_OLD CHOST "/" OLDVER "([/[:space:]]+)",
349 GCCLIB
350 "/" NEWVER "\\1", "g", la_data)
351 tmpstr =
352 gensub(GCCLIBPREFIX_NEW CHOST "/" OLDVER "([/[:space:]]+)",
353 GCCLIB
354 "/" NEWVER "\\1", "g", tmpstr)
355
356 if (la_data != tmpstr) {
357 # Catch:
358 #
359 #
360 dependency_libs=' -L/usr/lib/gcc-lib/../../CHOST/lib'
361 #
362 # in cases where
363 we have gcc34
364 tmpstr =
365 gensub(GCCLIBPREFIX_OLD "(../../" CHOST "/lib)",
366
367 GCCLIBPREFIX "\\1", "g", tmpstr)
368 tmpstr =
369 gensub(GCCLIBPREFIX_NEW "(../../" CHOST "/lib)",
370
371 GCCLIBPREFIX "\\1", "g", tmpstr)
372 printn("v")
373 la_data = tmpstr
374 }
375 }
376
377 # We now check if we have
378 libstdc++.la, as we remove the
379 # libtool linker scripts for gcc
380 and any referencese in any
381 # libtool linker scripts.
382 # We do this last, as we only
383 match the new paths
384 tmpstr = gensub(GCCLIB "/"
385 NEWVER "/libstdc\\+\\+\\.la",
386 "-lstdc++", "g",
387 la_data);
388 if (la_data != tmpstr) {
389 printn("l")
390 la_data = tmpstr
391 }
392
393 print la_data >> (la_files ".new")
394 }
395
396 if (CHANGED)
397 print "]"
398
399 close(la_files)
400 close(la_files ".new")
401
402 assert(dosystem("mv -f " la_files ".new
403 " la_files),
404 "dosystem(\"mv -f " la_files
405 ".new " la_files "\")")
406 }
407 }
408
409 close(pipe)
410 }
411 }
412
413 # vim:ts=4
414 ===== END =====
415 --
416 gentoo-alt@g.o mailing list

Replies

Subject Author
Re: [gentoo-alt] [prefix] fix_libtools_files.sh Fabian Groffen <grobian@g.o>