/[gentoo-x86]/eclass/multilib.eclass
Gentoo

Contents of /eclass/multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.18 - (hide annotations) (download)
Thu Feb 3 05:52:51 2005 UTC (9 years, 5 months ago) by eradicator
Branch: MAIN
Changes since 1.17: +4 -9 lines
Removing get_abi_order since all ebuild have been converted to use get_install_abis.

1 eradicator 1.1 # Copyright 1999-2004 Gentoo Foundation
2     # Distributed under the terms of the GNU General Public License v2
3 eradicator 1.18 # $Header: /var/cvsroot/gentoo-x86/eclass/multilib.eclass,v 1.17 2005/02/03 05:29:07 eradicator Exp $
4 eradicator 1.1 #
5     # Author: Jeremy Huddleston <eradicator@gentoo.org>
6     #
7     # This eclass is for all functions pertaining to handling multilib.
8     # configurations.
9    
10     ECLASS=multilib
11     INHERITED="$INHERITED $ECLASS"
12    
13     DESCRIPTION="Based on the ${ECLASS} eclass"
14    
15 eradicator 1.14 # has_multilib_profile:
16 eradicator 1.15 # Return true if the current profile is a multilib profile and lists more than
17     # one abi in ${MULTILIB_ABIS}. You might want to use this like
18     # 'use multilib || has_multilib_profile' until all profiles utilizing the
19     # 'multilib' use flag are removed from portage
20 eradicator 1.14
21     # is_final_abi:
22     # Return true if ${ABI} is the final abi to be installed (and thus we are
23     # on our last run through a src_* function.
24    
25     # number_abis:
26     # echo the number of ABIs we will be installing for
27    
28 eradicator 1.17 # get_install_abis:
29 eradicator 1.14 # Return a list of the ABIs we want to install for with
30     # the last one in the list being the default.
31    
32 eradicator 1.17 # get_all_abis:
33     # Return a list of the ABIs supported by this profile.
34     # the last one in the list being the default.
35    
36 eradicator 1.16 # get_all_libdirs:
37 eradicator 1.14 # Returns a list of all the libdirs used by this profile. This includes
38     # those that might not be touched by the current ebuild and always includes
39     # "lib".
40    
41     # get_libdir:
42     # Returns the libdir for the selected ABI. This is backwards compatible
43     # and simply calls get_abi_LIBDIR() on newer profiles. You should use this
44     # to determine where to install shared objects (ex: /usr/$(get_libdir))
45    
46     # get_abi_var <VAR> [<ABI>]:
47     # returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
48     #
49     # get_abi_CFLAGS:
50     # get_abi_CDEFINE:
51     # get_abi_LIBDIR:
52     # Aliases for 'get_abi_var CFLAGS', etc.
53    
54     # get_ml_incdir [<include dir> [<ABI>]]
55     # include dir defaults to /usr/include
56     # ABI defaults to ${ABI} or ${DEFAULT_ABI}
57     #
58     # If a multilib include dir is associated with the passed include dir, then
59     # we return it, otherwise, we just echo back the include dir. This is
60     # neccessary when a built script greps header files rather than testing them
61     # via #include (like perl) to figure out features.
62    
63     # prep_ml_includes:
64     # Some includes (include/asm, glibc, etc) are ABI dependent. In this case,
65     # We can install them in different locations for each ABI and create a common
66     # header which includes the right one based on CDEFINE_${ABI}. If your
67     # package installs ABI-specific headers, just add 'prep_ml_includes' to the
68     # end of your src_install(). It takes a list of directories that include
69     # files are installed in (default is /usr/include if none are passed).
70     #
71     # Example:
72     # src_install() {
73     # ...
74     # prep_ml_includes /usr/qt/3/include
75     # }
76    
77     # create_ml_includes <include dir> <symbol 1>:<dir 1> [<symbol 2>:<dir 2> ...]
78     # If you need more control than prep_ml_includes can offer (like linux-headers
79     # for the asm-* dirs, then use create_ml_includes. The firs argument is the
80     # common dir. The remaining args are of the form <symbol>:<dir> where
81     # <symbol> is what is put in the #ifdef for choosing that dir.
82     #
83     # Ideas for this code came from debian's sparc-linux headers package.
84     #
85     # Example:
86     # create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64
87     # create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64
88    
89     ### END DOCUMENTATION ###
90    
91     # has_multilib_profile()
92     has_multilib_profile() {
93 eradicator 1.15 [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
94 eradicator 1.14 }
95    
96 eradicator 1.1 # This function simply returns the desired lib directory. With portage
97     # 2.0.51, we now have support for installing libraries to lib32/lib64
98     # to accomidate the needs of multilib systems. It's no longer a good idea
99     # to assume all libraries will end up in lib. Replace any (sane) instances
100     # where lib is named directly with $(get_libdir) if possible.
101     #
102     # Travis Tilley <lv@gentoo.org> (24 Aug 2004)
103     #
104     # Jeremy Huddleston <eradicator@gentoo.org> (23 Dec 2004):
105     # Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set,
106     # fall back on old behavior. Any profile that has these set should also
107     # depend on a newer version of portage (not yet released) which uses these
108     # over CONF_LIBDIR in econf, dolib, etc...
109     get_libdir() {
110     LIBDIR_TEST=$(type econf)
111     if [ ! -z "${CONF_LIBDIR_OVERRIDE}" ] ; then
112     # if there is an override, we want to use that... always.
113     CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}"
114 eradicator 1.2 elif [ -n "$(get_abi_LIBDIR)" ]; then
115 eradicator 1.1 CONF_LIBDIR="$(get_abi_LIBDIR)"
116     elif [ "${LIBDIR_TEST/CONF_LIBDIR}" == "${LIBDIR_TEST}" ]; then # we don't have CONF_LIBDIR support
117     # will be <portage-2.0.51_pre20
118     CONF_LIBDIR="lib"
119     fi
120     # and of course, default to lib if CONF_LIBDIR isnt set
121     echo ${CONF_LIBDIR:=lib}
122     unset LIBDIR_TEST
123     }
124    
125     get_multilibdir() {
126     if [ -n "$(get_abi_LIBDIR)" ]; then
127     eerror "get_multilibdir called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org"
128     exit 1
129     fi
130     echo ${CONF_MULTILIBDIR:=lib32}
131     }
132    
133     # Sometimes you need to override the value returned by get_libdir. A good
134     # example of this is xorg-x11, where lib32 isnt a supported configuration,
135     # and where lib64 -must- be used on amd64 (for applications that need lib
136     # to be 32bit, such as adobe acrobat). Note that this override also bypasses
137     # portage version sanity checking.
138     # get_libdir_override expects one argument, the result get_libdir should
139     # return:
140     #
141     # get_libdir_override lib64
142     #
143     # Travis Tilley <lv@gentoo.org> (31 Aug 2004)
144     get_libdir_override() {
145     if [ -n "$(get_abi_LIBDIR)" ]; then
146     eerror "get_libdir_override called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org"
147     exit 1
148     fi
149     CONF_LIBDIR="$1"
150     CONF_LIBDIR_OVERRIDE="$1"
151     }
152    
153     # get_abi_var <VAR> [<ABI>]
154     # returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
155     #
156     # ex:
157     # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
158     #
159     # Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
160     # This will hopefully be added to portage soon...
161     #
162     # If <ABI> is not specified, ${ABI} is used.
163     # If <ABI> is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used.
164     # If <ABI> is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string.
165     #
166     # Jeremy Huddleston <eradicator@gentoo.org>
167     get_abi_var() {
168     local flag=${1}
169     local abi
170     if [ $# -gt 1 ]; then
171     abi=${2}
172     elif [ -n "${ABI}" ]; then
173     abi=${ABI}
174     elif [ -n "${DEFAULT_ABI}" ]; then
175     abi=${DEFAULT_ABI}
176     else
177     return 1
178     fi
179    
180     local var="${flag}_${abi}"
181     echo ${!var}
182     }
183    
184     get_abi_CFLAGS() { get_abi_var CFLAGS ${@}; }
185 eradicator 1.2 get_abi_CDEFINE() { get_abi_var CDEFINE ${@}; }
186 eradicator 1.1 get_abi_LIBDIR() { get_abi_var LIBDIR ${@}; }
187    
188 eradicator 1.2 # Return a list of the ABIs we want to install for with
189     # the last one in the list being the default.
190 eradicator 1.17 get_install_abis() {
191 eradicator 1.2 local order=""
192    
193     if [ -z "${MULTILIB_ABIS}" ]; then
194     echo "NOMULTILIB"
195     return 1
196     fi
197    
198     if hasq multilib-pkg-force ${RESTRICT} ||
199     { hasq multilib-pkg ${FEATURES} && hasq multilib-pkg ${RESTRICT}; }; then
200     for x in ${MULTILIB_ABIS}; do
201     if [ "${x}" != "${DEFAULT_ABI}" ]; then
202     hasq ${x} ${ABI_DENY} || ordera="${ordera} ${x}"
203     fi
204     done
205     hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${ordera} ${DEFAULT_ABI}"
206    
207     if [ -n "${ABI_ALLOW}" ]; then
208     local ordera=""
209     for x in ${order}; do
210     if hasq ${x} ${ABI_ALLOW}; then
211     ordera="${ordera} ${x}"
212     fi
213     done
214     order="${ordera}"
215     fi
216     else
217     order="${DEFAULT_ABI}"
218     fi
219    
220     if [ -z "${order}" ]; then
221     die "The ABI list is empty. Are you using a proper multilib profile? Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package."
222     fi
223    
224     echo ${order}
225     return 0
226     }
227    
228 eradicator 1.17 # Return a list of the ABIs supported by this profile.
229     # the last one in the list being the default.
230     get_all_abis() {
231     local order=""
232    
233     if [ -z "${MULTILIB_ABIS}" ]; then
234     echo "NOMULTILIB"
235     return 1
236     fi
237    
238     for x in ${MULTILIB_ABIS}; do
239     if [ "${x}" != "${DEFAULT_ABI}" ]; then
240     order="${order:+${order }}${x}"
241     fi
242     done
243     order="${order:+${order} }${DEFAULT_ABI}"
244    
245     echo ${order}
246     return 0
247     }
248    
249 eradicator 1.16 # get_all_libdirs()
250 eradicator 1.2 # Returns a list of all the libdirs used by this profile. This includes
251     # those that might not be touched by the current ebuild.
252 eradicator 1.1 get_all_libdirs() {
253 eradicator 1.2 local libdirs="lib"
254     local abi
255     local dir
256    
257 eradicator 1.14 if has_multilib_profile; then
258 eradicator 1.1 for abi in ${MULTILIB_ABIS}; do
259 eradicator 1.2 [ "$(get_abi_LIBDIR ${abi})" != "lib" ] && libdirs="${libdirs} $(get_abi_LIBDIR ${abi})"
260 eradicator 1.1 done
261     elif [ -n "${CONF_LIBDIR}" ]; then
262 eradicator 1.2 for dir in ${CONF_LIBDIR} ${CONF_MULTILIBDIR:=lib32}; do
263     [ "${dir}" != "lib" ] && libdirs="${libdirs} ${dir}"
264     done
265     fi
266    
267     echo "${libdirs}"
268     }
269    
270     # Return true if ${ABI} is the last ABI on our list (or if we're not
271     # using the new multilib configuration. This can be used to determine
272     # if we're in the last (or only) run through src_{unpack,compile,install}
273     is_final_abi() {
274 eradicator 1.14 ! has_multilib_profile && return 0
275 eradicator 1.18 local ALL_ABIS=$(get_install_abis)
276 eradicator 1.2 local LAST_ABI=${ALL_ABIS/* /}
277     [ "${LAST_ABI}" = "${ABI}" ]
278     }
279    
280     # echo the number of ABIs we will be installing for
281     number_abis() {
282 eradicator 1.18 get_install_abis | wc -w
283 eradicator 1.2 }
284    
285 eradicator 1.10 # get_ml_incdir [<include dir> [<ABI>]]
286     # include dir defaults to /usr/include
287     # ABI defaults to ${ABI} or ${DEFAULT_ABI}
288     get_ml_incdir() {
289     local dir=/usr/include
290    
291     if [[ ${#} -gt 0 ]]; then
292     incdir=${1}
293     shift
294     fi
295    
296     if [[ -z "${MULTILIB_ABIS}" ]]; then
297     echo ${incdir}
298     return 0
299     fi
300    
301     local abi=${ABI:-${DEFAULT_ABI}}
302     if [[ ${#} -gt 0 ]]; then
303     abi=${1}
304     shift
305     fi
306    
307     if [[ -d "${dir}/gentoo-multilib/${abi}" ]]; then
308     echo ${dir}/gentoo-multilib/${abi}
309     else
310     echo ${dir}
311     fi
312     }
313    
314 eradicator 1.2 # prep_ml_includes:
315     #
316     # Some includes (include/asm, glibc, etc) are ABI dependent. In this case,
317     # We can install them in different locations for each ABI and create a common
318     # header which includes the right one based on CDEFINE_${ABI}. If your
319     # package installs ABI-specific headers, just add 'prep_ml_includes' to the
320     # end of your src_install(). It takes a list of directories that include
321     # files are installed in (default is /usr/include if none are passed).
322     #
323     # Example:
324     # src_install() {
325     # ...
326     # prep_ml_includes /usr/qt/3/include
327     # }
328    
329     prep_ml_includes() {
330     if [ $(number_abis) -gt 1 ]; then
331     local dir
332 eradicator 1.11 local dirs
333     local base
334    
335     if [ ${#} -eq 0 ]; then
336     dirs="/usr/include"
337     else
338     dirs="${@}"
339     fi
340    
341 eradicator 1.2 for dir in ${dirs}; do
342 eradicator 1.11 base=${T}/gentoo-multilib/${dir}/gentoo-multilib
343     mkdir -p ${base}
344     [ -d ${base}/${ABI} ] && rm -rf ${base}/${ABI}
345     mv ${D}/${dir} ${base}/${ABI}
346 eradicator 1.2 done
347    
348     if is_final_abi; then
349 eradicator 1.11 base=${T}/gentoo-multilib
350     pushd ${base}
351 eradicator 1.15 find . | tar -c -T - -f - | tar -x --no-same-owner -f - -C ${D}
352 eradicator 1.11 popd
353 eradicator 1.13
354     for dir in ${dirs}; do
355     local args=${dir}
356     local abi
357 eradicator 1.18 for abi in $(get_install_abis); do
358 eradicator 1.13 args="${args} $(get_abi_CDEFINE ${abi}):${dir}/gentoo-multilib/${abi}"
359     done
360     create_ml_includes ${args}
361 eradicator 1.12 done
362 eradicator 1.2 fi
363     fi
364     }
365    
366     # If you need more control than prep_ml_includes can offer (like linux-headers
367     # for the asm-* dirs, then use create_ml_includes. The firs argument is the
368     # common dir. The remaining args are of the form <symbol>:<dir> where
369     # <symbol> is what is put in the #ifdef for choosing that dir.
370     #
371     # Ideas for this code came from debian's sparc-linux headers package.
372     #
373     # Example:
374     # create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64
375     # create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64
376     create_ml_includes() {
377     local dest="${1}"
378     shift
379     local mlinfo="${@}"
380     local basedirs=$(create_ml_includes-listdirs ${mlinfo})
381    
382     create_ml_includes-makedestdirs ${dest} ${basedirs}
383    
384     local file
385     for file in $(create_ml_includes-allfiles ${basedirs}); do
386     local name="$(echo $file | tr a-z A-Z | sed 's:[^A-Z]:_:g')"
387     {
388     echo "/* Common header file autogenerated by create_ml_includes in multilib.eclass */"
389 eradicator 1.4 #echo "#ifndef __CREATE_ML_INCLUDES_STUB_${name}__"
390     #echo "#define __CREATE_ML_INCLUDES_STUB_${name}__"
391     #echo ""
392 eradicator 1.2
393     local dir
394     for dir in ${basedirs}; do
395     if [ -f "${D}/${dir}/${file}" ]; then
396     echo "#ifdef $(create_ml_includes-sym_for_dir ${dir} ${mlinfo})"
397 eradicator 1.5 echo "#include \"$(create_ml_includes-relative_between ${dest}/$(dirname ${file}) ${dir}/${file})\""
398 eradicator 1.2 echo "#endif /* $(create_ml_includes-sym_for_dir ${dir} ${mlinfo}) */"
399     echo ""
400     fi
401     done
402    
403 eradicator 1.4 #echo "#endif /* __CREATE_ML_INCLUDES_STUB_${name}__ */"
404 eradicator 1.2 } > ${D}/${dest}/${file}
405     done
406     }
407    
408     # Helper function for create_ml_includes
409     create_ml_includes-relative_between() {
410 eradicator 1.5 local src="$(create_ml_includes-tidy_path ${1})"
411     local dst="$(create_ml_includes-tidy_path ${2})"
412    
413     src=(${src//\// })
414     dst=(${dst//\// })
415    
416     local i
417     for ((i=0; i<${#src[*]}; i++)); do
418     [ "${dst[i]}" != "${src[i]}" ] && break
419     done
420    
421     local common=$i
422    
423     for ((i=${#src[*]}; i>common; i--)); do
424     echo -n ../
425     done
426    
427     for ((i=common; i<${#dst[*]}-1; i++)); do
428     echo -n ${dst[i]}/
429     done
430    
431     echo -n ${dst[i]}
432 eradicator 1.3 }
433    
434     # Helper function for create_ml_includes
435 eradicator 1.5 create_ml_includes-tidy_path() {
436     local removed="${1}"
437    
438 eradicator 1.6 if [ -n "${removed}" ]; then
439 eradicator 1.5 # Remove multiple slashes
440     while [ "${removed}" != "${removed/\/\//\/}" ]; do
441     removed=${removed/\/\//\/}
442     done
443    
444     # Remove . directories
445     while [ "${removed}" != "${removed//\/.\//\/}" ]; do
446     removed=${removed//\/.\//\/}
447     done
448     [ "${removed##*/}" = "." ] && removed=${removed%/*}
449    
450     # Removed .. directories
451 eradicator 1.6 while [ "${removed}" != "${removed//\/..\/}" ]; do
452     local p1="${removed%%\/..\/*}"
453     local p2="${removed#*\/..\/}"
454    
455     removed="${p1%\/*}/${p2}"
456 eradicator 1.5 done
457    
458     # Remove trailing ..
459 eradicator 1.6 [ "${removed##*/}" = ".." ] && removed=${removed%/*/*}
460 eradicator 1.5
461     # Remove trailing /
462     [ "${removed##*/}" = "" ] && removed=${removed%/*}
463    
464 eradicator 1.3 echo ${removed}
465     fi
466 eradicator 1.2 }
467    
468     # Helper function for create_ml_includes
469     create_ml_includes-listdirs() {
470     local dirs
471     local data
472     for data in ${@}; do
473     dirs="${dirs} ${data/*:/}"
474     done
475     echo ${dirs:1}
476     }
477    
478     # Helper function for create_ml_includes
479     create_ml_includes-makedestdirs() {
480     local dest=${1}
481     shift
482     local basedirs=${@}
483    
484     dodir ${dest}
485    
486     local basedir
487     for basedir in ${basedirs}; do
488     local dir
489     for dir in $(find ${D}/${basedir} -type d); do
490     dodir ${dest}/${dir/${D}\/${basedir}/}
491     done
492     done
493     }
494    
495     # Helper function for create_ml_includes
496     create_ml_includes-allfiles() {
497     local basedirs=${@}
498    
499 eradicator 1.7 local basedir
500 eradicator 1.2 for basedir in ${basedirs}; do
501     local file
502     for file in $(find ${D}/${basedir} -type f); do
503     echo ${file/${D}\/${basedir}\//}
504     done
505     done | sort | uniq
506     }
507    
508     # Helper function for create_ml_includes
509     create_ml_includes-sym_for_dir() {
510     local dir="${1}"
511     shift
512     local data
513     for data in ${@}; do
514     if [ "${dir}" = "${data/*:/}" ]; then
515     echo ${data/:*/}
516     return 0
517     fi
518     done
519 eradicator 1.7 echo "Shouldn't be here -- create_ml_includes-sym_for_dir ${1} ${@}"
520 eradicator 1.2 # exit because we'll likely be called from a subshell
521     exit 1
522 eradicator 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20