Gentoo Archives: gentoo-commits

From: "Peter Alfredsen (loki_val)" <loki_val@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-util/lafilefixer/files: lafilefixer-0.5
Date: Wed, 22 Apr 2009 22:23:04
Message-Id: E1LwkqL-0004cD-Jc@stork.gentoo.org
1 loki_val 09/04/22 22:23:01
2
3 Added: lafilefixer-0.5
4 Log:
5 Drop dependency on grep, sed and coreutils to stop the forkbomb. Use find to parse inputs and find .la files. Each file is now opened only twice. Once to read, once to write. Add --license, --justfixit and --help options.
6 (Portage version: 2.2_rc28/cvs/Linux x86_64)
7
8 Revision Changes Path
9 1.1 dev-util/lafilefixer/files/lafilefixer-0.5
10
11 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-util/lafilefixer/files/lafilefixer-0.5?rev=1.1&view=markup
12 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/dev-util/lafilefixer/files/lafilefixer-0.5?rev=1.1&content-type=text/plain
13
14 Index: lafilefixer-0.5
15 ===================================================================
16 #!/bin/bash
17
18 # Libtool does not support spaces in dependency_libs entries so we won't worry
19 # overly about them either.
20
21 NEWLINE="
22 "
23
24 has() {
25 [[ " ${*:2} " == *" $1 "* ]]
26 }
27
28 fix_la_files() {
29 local lafile
30 for lafile in "${@:2}"
31 do
32 local has_inh_link_flags="no"
33 local new_inh_link_flags=""
34 local dependency_libs=""
35 local inh_link_flags=""
36 local has_dep_libs="no"
37 local new_dep_libs=""
38 local remove_lib=""
39 local contents="$(<"${lafile}")"
40 local libladir=""
41 local librpath=""
42 local dep_libs=""
43 local line=""
44 local lib=""
45
46
47 save_IFS="${IFS}"
48 IFS="$NEWLINE"
49 for line in $contents
50 do
51 if [[ "${line#dependency_libs=\'}" != "${line}" ]]
52 then
53 [[ "$has_dep_libs" == "no" ]] || { echo "dependency_libs= assigned more than once in $lafile" && return 1 ; }
54 line="${line#dependency_libs=\'}"
55 dep_libs="${line%\'}"
56 has_dep_libs="yes"
57
58 elif [[ "${line#inherited_linker_flags=\'}" != "${line}" ]]
59 then
60
61 [[ "$has_inh_link_flags" == "no" ]] || { echo "inherited_linker_flags= assigned more than once in $lafile" && return 1 ; }
62 line="${line#inherited_linker_flags=\'}"
63 inh_link_flags="${line%\'}"
64 new_inh_link_flags="${inh_link_flags}"
65 has_inh_link_flags="yes"
66 fi
67 done
68 IFS="$save_IFS"
69
70 if [[ "$has_dep_libs" == "no" ]]
71 then
72 printf '%s\n' "$lafile is not a .la file. Skipping."
73 continue
74 fi
75
76 for entry in $dep_libs
77 do
78 case $entry in
79 -l*)
80 has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}"
81 ;;
82 *.la)
83
84 if [[ "${entry##*\/lib}" == "${entry}" ]]
85 then
86 has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}"
87 else
88 lib="${entry##*\/lib}"
89 lib="${lib%.la}"
90 lib="-l${lib}"
91 has ${lib} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${lib}"
92 has -L${entry%/*.la} ${libladir} || libladir="${libladir} -L${entry%/*.la}"
93 fi
94 ;;
95 -L*)
96 [[ ${entry/X11R6\/lib} != ${entry} ]] && entry="${entry/X11R6\/}"
97 [[ ${entry/local\/lib} != ${entry} ]] && entry="${entry/local\/}"
98 [[ ${entry/usr\/lib*\/pkgconfig\/..\/..} != ${entry} ]] && entry="${entry/\/lib*\/pkgconfig\/..\/..}"
99 [[ ${entry/usr\/lib*\/pkgconfig\/..} != ${entry} ]] && entry="${entry/\/pkgconfig\/..}"
100 has ${entry} ${libladir} || libladir="${libladir} ${entry}"
101 ;;
102 -R*)
103 has ${entry} ${librpath} || librpath="${librpath} ${entry}"
104 ;;
105 -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe|-threads)
106 if [[ "${has_inh_link_flags}" == "yes" ]]
107 then
108 has ${entry} ${new_inh_link_flags} || new_inh_link_flags="${new_inh_link_flags} ${entry}"
109 else
110 has ${entry} ${new_dep_libs} || new_dep_libs="${new_dep_libs} ${entry}"
111 fi
112 ;;
113 *)
114 echo "Debug information:"
115 echo $lafile
116 echo "${entry}"
117 echo "Holy Moley, Dorothy, we ain't in Kansas and Luke, I'm not your father"
118 return 1
119 ;;
120 esac
121 done
122
123 [[ "${dep_libs}" == "${librpath}${libladir}${new_dep_libs}" && "${new_inh_link_flags}" == "${inh_link_flags}" ]] && { echo "$lafile already clean, skipping update."; continue; }
124 echo "${lafile}: Updating..."
125 contents="${contents/${NEWLINE}dependency_libs=\'${dep_libs}\'${NEWLINE}/${NEWLINE}dependency_libs='${librpath}${libladir}${new_dep_libs}'${NEWLINE}}"
126 [[ "${has_inh_link_flags}" == "yes" ]] && \
127 contents="${contents/${NEWLINE}inherited_linker_flags=\'${inh_link_flags}\'${NEWLINE}/${NEWLINE}inherited_linker_flags='${new_inh_link_flags}'${NEWLINE}}"
128
129 printf '%s' "$contents" > "${lafile}"
130 done
131 }
132
133 case "$1" in
134 -h|--help)
135 cat <<- EOF
136 lafilefixer (C) 2009 Peter Alfredsen <loki_val@g.o>
137 Released under the MIT/X11 license.
138
139 Usage: lafilefixer [OPTION] [FILE|DIR]...
140 Fix .la libtool archives to list libraries, not .la files in dependency_libs and
141 do some minor fixups, moving -pthread to inherited_linker_flags if available and
142 eliminating duplicate library listings.
143
144 By default, lafilefixer is recursive, fixing all .la files in all subdirectories
145 so if you want to fix only a single file, it must be specified in full.
146
147 Options:
148 -h, --help Display this text and exit.
149 --justfixit Choose some reasonable dirs, such as /usr/lib*, etc. ,
150 find all .la files and fix them to not use .la files
151 for linking
152 --license Display the license and exit.
153 EOF
154 ;;
155 --justfixit)
156 declare dirlist=""
157 declare files=()
158 for dir in {/usr/lib,/usr/qt/3/lib,/usr/kde/3.5/lib,/opt/lib,/lib}{,32,64}
159 do
160 [[ -d "${dir}" ]] && dirlist="${dirlist} ${dir}"
161 done
162
163 while read -r line
164 do
165 files+=( "$line" )
166 done< <( find ${dirlist} -name '*.la' -type f )
167
168 fix_la_files --cleanup "${files[@]}"
169 ;;
170 --license)
171 cat <<- EOF
172 Copyright (c) 2009 Peter Alfredsen <loki_val@g.o>
173
174 Permission is hereby granted, free of charge, to any person obtaining a copy of
175 this software and associated documentation files (the "Software"), to deal in
176 the Software without restriction, including without limitation the rights to
177 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
178 of the Software, and to permit persons to whom the Software is furnished to
179 do so, subject to the following conditions:
180
181 The above copyright notice and this permission notice shall be included in all
182 copies or substantial portions of the Software.
183
184 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
185 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
186 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
187 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
188 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
189 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
190 EOF
191 ;;
192 *)
193 declare arglist=()
194 declare files=()
195 declare arg=""
196
197 for arg in "${@}"
198 do
199 if [[ -d "${arg}" || -f "${arg}" ]]
200 then
201 arglist+=( "${arg}" )
202 else
203 printf '%s\n' "${arg} is not a valid directory or file, skipping."
204 fi
205 done
206
207 while read -r line
208 do
209 files+=( "$line" )
210 done< <( find "${arglist[@]}" -name '*.la' -type f )
211
212 fix_la_files --cleanup "${files[@]}"
213 ;;
214 esac