/[gentoo-alt]/trunk/prefix/eclass/ccc.eclass
Gentoo

Contents of /trunk/prefix/eclass/ccc.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 982 - (show annotations) (download)
Thu Feb 2 04:20:17 2006 UTC (13 years, 2 months ago) by kito
File size: 7535 byte(s)
Initial eclass import from gentoo-x86
1 # Copyright 1999-2004 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/ccc.eclass,v 1.18 2005/07/11 15:08:06 swegener Exp $
4 #
5 # Authors: Tavis Ormandy <taviso@gentoo.org>
6 # Aron Griffis <agriffis@gentoo.org>
7 #
8 # functions to make ebuilds more ccc friendly.
9 #
10 # 16/6/2003 - Added otsify()
11 # 18/6/2003 - regex tweaks.
12 # 22/7/2003 - newdepend
13
14 inherit flag-o-matic
15
16
17 # define this to make this eclass noisy.
18 #DEBUG_CCC_ECLASS=1
19
20 #
21 #### hide-restrict-arr ####
22 # Scan for and replace __restrict_arr with a ccc
23 # supported equivalent.
24 #
25 # you might see an error like this if you need this:
26 #
27 # cc: Error: regexec.c, line 209: In the definition of the function "regexec",
28 # the promoted type of pmatch is incompatible with the type of the corresponding
29 # parameter in a prior declaration. (promotmatch)
30 # regmatch_t pmatch[];
31 # ---------------^
32 #
33 #### replace-cc-hardcode ####
34 # Look for common cc hardcodes in Makefiles.
35 #
36 #### replace-cxx-hardcode ####
37 # Look for common cxx hardcodes in Makefiles.
38 #
39 #### is-ccc ####
40 # Returns success if dec compiler is being used.
41 #
42 # example:
43 #
44 # is-ccc && hide-restrict-arr
45 #
46 #### is-cxx ####
47 # Returns success if dec c++ compiler is being used.
48 #
49 #### replace-ccc-g ####
50 # Try to replace -g with -g3
51 #
52 #### ccc-elf-check </path/to/binary> ####
53 # Return success if binary was compiled with ccc
54 #
55 # example:
56 # if ! is-ccc; then
57 # ccc-elf-check /usr/lib/libglib.a && \
58 # append-ldflags -lots
59 # fi
60 #
61 # NOTE: i think the binary and shared library detection
62 # is pretty safe, but the archive detection may not
63 # be as reliable.
64 #### create-so </usr/lib/library.a> <library.so> ####
65 # Make the shared library (.so) specified from the archive (.a)
66 # specified. LDFLAGS will be honoured. if you need a different
67 # `soname` (DT_SONAME) from the shared lib filename, you will have
68 # to do it manually ;)
69 #
70 # example:
71 # is-ccc && \
72 # create-so /usr/lib/libcoolstuff.a libcoolstuff.so.${PV}
73 # dosym /usr/lib/libcoolstuff.so.${PV} /usr/lib/libcoolstuff.so
74 #
75 # NOTE: -lots will be used by default, this is ccc.eclass after all :)
76 # NOTE: .${PV} is optional, of course.
77 # NOTE: dolib.so will manage installation
78 #### append-ldflags <flag> ####
79 #### is-ldflag <flag> ####
80 #### filter-ldflags <flag> ####
81 # flag-o-matic doesnt provide LDFLAGS utilities.
82 # Some replacements for ccc porting. These functions
83 # mimic the flag-o-matic equivalents, look in there for
84 # documentation.
85 #
86 #### otsify <archive> ####
87 # Add the functions from libots to <archive>, this means
88 # that if you use gcc to build an application that links with
89 # <archive>, you wont need -lots.
90 # Use this on libraries that you want maximum performance from,
91 # but might not be using ccc when linking against it (eg zlib, openssl, etc)
92 #
93 # example:
94 # is-ccc && otsify ${S}/libz.a
95 #
96 ####
97 #
98
99 ccc-fixup()
100 {
101 # helper function to fixup files
102 # and show differences when debugging
103 #
104 # store the backup suffix.
105 local files list suffix=ccc-fixup-${$}
106
107 while read files
108 do
109 sed --in-place=.${suffix} ${1} ${files} || return 1
110 list="${list} ${files}"
111 done
112
113 [ ! "$DEBUG_CCC_ECLASS" ] && return 0
114 # if theres a backup, diff it.
115 for i in ${list}
116 do
117 einfo "Checking for changes to `basename ${i}` ..."
118 if [ -e "${i}.${suffix}" ]; then
119 diff -u ${i}.${suffix} ${i}
120 # sleep 1
121 fi
122 done
123 }
124
125 hide-restrict-arr()
126 {
127 # __restrict_arr causes trouble with ccc, __restrict
128 # is a supported equivalent.
129 #
130 # example:
131 # regmatch_t __pmatch[__restrict_arr]
132 #
133
134 find ${WORKDIR} -iname '*.h' | \
135 xargs | ccc-fixup 's#\(\[__restrict\)_arr\]#\1\]#g'
136 }
137
138 replace-cc-hardcode()
139 {
140 # lots of developers hardcode gcc into their
141 # Makefiles. Try and fix these.
142 #
143 find ${WORKDIR} -iname Makefile | \
144 xargs | ccc-fixup "s#^\(CC.*=\).*g\?cc#\1${CC:-gcc}#g"
145 }
146
147 replace-cxx-hardcode()
148 {
149 # lots of developers hardcode g++ into thier
150 # Makefiles. Try and fix these.
151 find ${WORKDIR} -iname Makefile | \
152 xargs | ccc-fixup "s#^\(CXX.*=\).*[gc]\{1\}++#\1${CXX:-g++}#g"
153 }
154
155 is-ccc()
156 {
157 # return true if ccc is being used.
158 [ "${ARCH}:`basename ${CC:-gcc}`" == "alpha:ccc" ]
159 }
160
161 is-cxx()
162 {
163 # return true if cxx is being used
164 [ "${ARCH}:`basename ${CXX:-g++}`" == "alpha:cxx" ]
165 }
166
167 replace-ccc-g()
168 {
169 # -g will stop ccc/cxx performing optimisation
170 # replacing it with -g3 will let them co-exist.
171 find ${WORKDIR} -iname Makefile | \
172 xargs | ccc-fixup \
173 "s#\(^\CX\{,2\}FLAGS[[:space:]]*=.*[\'\"\x20\t]*\)-g\([\'\"\x20\t]\|$\)#\1-g3\2#g"
174 # FIXME: my eyes! it burns!
175 }
176
177 ccc-elf-check()
178 {
179 # check if argument is a ccc created executable.
180 # this is useful for libraries compiled with ccc,
181 # which might require -lots/-lcpml if a linking binary
182 # isnt being compiled with ccc.
183 local myBINARY=${1:-a.out}
184 if [[ ! "${myBINARY}" == *.a ]]; then
185 # find the offset and size of the elf .note section.
186 # example contents: 000132d2 00000dc8
187 # ^- offset ^- size
188 local elf_note_offset=`objdump -h ${myBINARY} | \
189 grep -E '^\ [0-9]{2,}\ .note\ ' | \
190 awk '{print $6,$3}' | \
191 line`
192 # check if that got anything.
193 [ ! "${elf_note_offset}" ] && return 1
194 # dump contents of section, and check for compaq signature.
195 hexdump -s 0x${elf_note_offset% *} -n $((0x${elf_note_offset#* })) -e '"%_p"' ${myBINARY} | \
196 grep -E 'Compaq Computer Corp.' &>/dev/null && return 0
197 # no compaq message, return 1
198 else
199 # just grep it for the Compaq sig.
200 hexdump -e '"%_p"' ${myBINARY} | \
201 grep -E 'Compaq Computer Corp.' &>/dev/null && return 0
202 fi
203 return 1
204 }
205
206 create-so()
207 {
208 # some applications check for .so, but ccc wont
209 # create one by default
210 if [[ "${2}" == *.so ]]; then
211 # no version suffix.
212 ${LD:-ld} -shared -o ${T}/${2##*/} -soname ${2##*/} \
213 -whole-archive ${1} -no-whole-archive -lots ${LDFLAGS}
214 else
215 # version suffix
216 local so_version=${2##*.so}
217 ${LD:-ld} -shared -o ${T}/${2##*/} -soname `basename ${2/${so_version}}` \
218 -whole-archive ${1} -no-whole-archive -lots ${LDFLAGS}
219 fi
220 # hand installation over to dolib.so
221 dolib.so ${T}/${2##*/}
222 }
223
224 append-ldflags()
225 {
226 LDFLAGS="${LDFLAGS} ${1}"
227 }
228
229 # flag-o-matic clone
230 #
231 #is-ldflags()
232 #{
233 # for x in ${LDFLAGS}
234 # do
235 # if [ "${x}" = "${1}" ]; then
236 # echo true
237 # break
238 # fi
239 # done
240 #}
241
242 is-ldflags() {
243 local x
244 for x in ${LDFLAGS}
245 do
246 if [ "${x}" == "${1}" ]; then
247 tty --quiet < /dev/stdout || echo "true"
248 return 0
249 fi
250 done
251 return 1
252 }
253
254 filter-ldflags()
255 {
256 for x in ${1}
257 do
258 LDFLAGS="${LDFLAGS/${x}}"
259 done
260 }
261
262 otsify()
263 {
264 [ "$DEBUG_CCC_ECLASS" ] && local ar_args="v"
265
266 # confirm argument exists, and is an archive (eg *.a)
267 # if it is, extract libots members into tempdir, then
268 # append them to argument, regenerate index and then return.
269
270 if [ "${1##*.}" == "a" ] && [ -f "${1}" ]; then
271 einfo "otsifying `basename ${1}` ..."
272
273 mkdir ${T}/ccc-otsify-${$}
274 cd ${T}/ccc-otsify-${$}
275
276 einfo " extracting archive members from libots ..."
277 ar ${ar_args}x /usr/lib/libots.a || {
278 eerror " unable to extract libots members."
279 return 1
280 }
281
282 einfo " appending libots members to `basename ${1}` ..."
283 ar ${ar_args}q ${1} ${T}/ccc-otsify-${$}/*.o || {
284 eerror " failed to append libots members to ${1}."
285 return 1
286 }
287
288 einfo " regenerating `basename ${1}` archive index ..."
289 ranlib ${1} || ewarn " ranlib returned an error, probably not important."
290 einfo "otsification completed succesfully."
291 cd ${OLDPWD:-.}
292 return 0
293 else
294 ewarn "called otsify() with bad argument ..."
295 cd ${OLDPWD:-.}
296 return 1
297 fi
298 }
299
300

  ViewVC Help
Powered by ViewVC 1.1.20