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

Contents of /eclass/multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.17 - (hide annotations) (download)
Thu Feb 3 05:29:07 2005 UTC (9 years, 7 months ago) by eradicator
Branch: MAIN
Changes since 1.16: +32 -2 lines
Added get_all_abis.  Renamed get_abi_order to 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.17 # $Header: /var/cvsroot/gentoo-x86/eclass/multilib.eclass,v 1.16 2005/01/31 06:37:31 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     get_abi_order() {
191 eradicator 1.17 ewarn "Please update your ebuild to use get_install_abis instead of get_abi_order"
192     get_install_abis ${@}
193     }
194    
195     get_install_abis() {
196 eradicator 1.2 local order=""
197    
198     if [ -z "${MULTILIB_ABIS}" ]; then
199     echo "NOMULTILIB"
200     return 1
201     fi
202    
203     if hasq multilib-pkg-force ${RESTRICT} ||
204     { hasq multilib-pkg ${FEATURES} && hasq multilib-pkg ${RESTRICT}; }; then
205     for x in ${MULTILIB_ABIS}; do
206     if [ "${x}" != "${DEFAULT_ABI}" ]; then
207     hasq ${x} ${ABI_DENY} || ordera="${ordera} ${x}"
208     fi
209     done
210     hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${ordera} ${DEFAULT_ABI}"
211    
212     if [ -n "${ABI_ALLOW}" ]; then
213     local ordera=""
214     for x in ${order}; do
215     if hasq ${x} ${ABI_ALLOW}; then
216     ordera="${ordera} ${x}"
217     fi
218     done
219     order="${ordera}"
220     fi
221     else
222     order="${DEFAULT_ABI}"
223     fi
224    
225     if [ -z "${order}" ]; then
226     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."
227     fi
228    
229     echo ${order}
230     return 0
231     }
232    
233 eradicator 1.17 # Return a list of the ABIs supported by this profile.
234     # the last one in the list being the default.
235     get_all_abis() {
236     local order=""
237    
238     if [ -z "${MULTILIB_ABIS}" ]; then
239     echo "NOMULTILIB"
240     return 1
241     fi
242    
243     for x in ${MULTILIB_ABIS}; do
244     if [ "${x}" != "${DEFAULT_ABI}" ]; then
245     order="${order:+${order }}${x}"
246     fi
247     done
248     order="${order:+${order} }${DEFAULT_ABI}"
249    
250     echo ${order}
251     return 0
252     }
253    
254 eradicator 1.16 # get_all_libdirs()
255 eradicator 1.2 # Returns a list of all the libdirs used by this profile. This includes
256     # those that might not be touched by the current ebuild.
257 eradicator 1.1 get_all_libdirs() {
258 eradicator 1.2 local libdirs="lib"
259     local abi
260     local dir
261    
262 eradicator 1.14 if has_multilib_profile; then
263 eradicator 1.1 for abi in ${MULTILIB_ABIS}; do
264 eradicator 1.2 [ "$(get_abi_LIBDIR ${abi})" != "lib" ] && libdirs="${libdirs} $(get_abi_LIBDIR ${abi})"
265 eradicator 1.1 done
266     elif [ -n "${CONF_LIBDIR}" ]; then
267 eradicator 1.2 for dir in ${CONF_LIBDIR} ${CONF_MULTILIBDIR:=lib32}; do
268     [ "${dir}" != "lib" ] && libdirs="${libdirs} ${dir}"
269     done
270     fi
271    
272     echo "${libdirs}"
273     }
274    
275     # Return true if ${ABI} is the last ABI on our list (or if we're not
276     # using the new multilib configuration. This can be used to determine
277     # if we're in the last (or only) run through src_{unpack,compile,install}
278     is_final_abi() {
279 eradicator 1.14 ! has_multilib_profile && return 0
280 eradicator 1.2 local ALL_ABIS=$(get_abi_order)
281     local LAST_ABI=${ALL_ABIS/* /}
282     [ "${LAST_ABI}" = "${ABI}" ]
283     }
284    
285     # echo the number of ABIs we will be installing for
286     number_abis() {
287     get_abi_order | wc -w
288     }
289    
290 eradicator 1.10 # get_ml_incdir [<include dir> [<ABI>]]
291     # include dir defaults to /usr/include
292     # ABI defaults to ${ABI} or ${DEFAULT_ABI}
293     get_ml_incdir() {
294     local dir=/usr/include
295    
296     if [[ ${#} -gt 0 ]]; then
297     incdir=${1}
298     shift
299     fi
300    
301     if [[ -z "${MULTILIB_ABIS}" ]]; then
302     echo ${incdir}
303     return 0
304     fi
305    
306     local abi=${ABI:-${DEFAULT_ABI}}
307     if [[ ${#} -gt 0 ]]; then
308     abi=${1}
309     shift
310     fi
311    
312     if [[ -d "${dir}/gentoo-multilib/${abi}" ]]; then
313     echo ${dir}/gentoo-multilib/${abi}
314     else
315     echo ${dir}
316     fi
317     }
318    
319 eradicator 1.2 # prep_ml_includes:
320     #
321     # Some includes (include/asm, glibc, etc) are ABI dependent. In this case,
322     # We can install them in different locations for each ABI and create a common
323     # header which includes the right one based on CDEFINE_${ABI}. If your
324     # package installs ABI-specific headers, just add 'prep_ml_includes' to the
325     # end of your src_install(). It takes a list of directories that include
326     # files are installed in (default is /usr/include if none are passed).
327     #
328     # Example:
329     # src_install() {
330     # ...
331     # prep_ml_includes /usr/qt/3/include
332     # }
333    
334     prep_ml_includes() {
335     if [ $(number_abis) -gt 1 ]; then
336     local dir
337 eradicator 1.11 local dirs
338     local base
339    
340     if [ ${#} -eq 0 ]; then
341     dirs="/usr/include"
342     else
343     dirs="${@}"
344     fi
345    
346 eradicator 1.2 for dir in ${dirs}; do
347 eradicator 1.11 base=${T}/gentoo-multilib/${dir}/gentoo-multilib
348     mkdir -p ${base}
349     [ -d ${base}/${ABI} ] && rm -rf ${base}/${ABI}
350     mv ${D}/${dir} ${base}/${ABI}
351 eradicator 1.2 done
352    
353     if is_final_abi; then
354 eradicator 1.11 base=${T}/gentoo-multilib
355     pushd ${base}
356 eradicator 1.15 find . | tar -c -T - -f - | tar -x --no-same-owner -f - -C ${D}
357 eradicator 1.11 popd
358 eradicator 1.13
359     for dir in ${dirs}; do
360     local args=${dir}
361     local abi
362     for abi in $(get_abi_order); do
363     args="${args} $(get_abi_CDEFINE ${abi}):${dir}/gentoo-multilib/${abi}"
364     done
365     create_ml_includes ${args}
366 eradicator 1.12 done
367 eradicator 1.2 fi
368     fi
369     }
370    
371     # If you need more control than prep_ml_includes can offer (like linux-headers
372     # for the asm-* dirs, then use create_ml_includes. The firs argument is the
373     # common dir. The remaining args are of the form <symbol>:<dir> where
374     # <symbol> is what is put in the #ifdef for choosing that dir.
375     #
376     # Ideas for this code came from debian's sparc-linux headers package.
377     #
378     # Example:
379     # create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64
380     # create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64
381     create_ml_includes() {
382     local dest="${1}"
383     shift
384     local mlinfo="${@}"
385     local basedirs=$(create_ml_includes-listdirs ${mlinfo})
386    
387     create_ml_includes-makedestdirs ${dest} ${basedirs}
388    
389     local file
390     for file in $(create_ml_includes-allfiles ${basedirs}); do
391     local name="$(echo $file | tr a-z A-Z | sed 's:[^A-Z]:_:g')"
392     {
393     echo "/* Common header file autogenerated by create_ml_includes in multilib.eclass */"
394 eradicator 1.4 #echo "#ifndef __CREATE_ML_INCLUDES_STUB_${name}__"
395     #echo "#define __CREATE_ML_INCLUDES_STUB_${name}__"
396     #echo ""
397 eradicator 1.2
398     local dir
399     for dir in ${basedirs}; do
400     if [ -f "${D}/${dir}/${file}" ]; then
401     echo "#ifdef $(create_ml_includes-sym_for_dir ${dir} ${mlinfo})"
402 eradicator 1.5 echo "#include \"$(create_ml_includes-relative_between ${dest}/$(dirname ${file}) ${dir}/${file})\""
403 eradicator 1.2 echo "#endif /* $(create_ml_includes-sym_for_dir ${dir} ${mlinfo}) */"
404     echo ""
405     fi
406     done
407    
408 eradicator 1.4 #echo "#endif /* __CREATE_ML_INCLUDES_STUB_${name}__ */"
409 eradicator 1.2 } > ${D}/${dest}/${file}
410     done
411     }
412    
413     # Helper function for create_ml_includes
414     create_ml_includes-relative_between() {
415 eradicator 1.5 local src="$(create_ml_includes-tidy_path ${1})"
416     local dst="$(create_ml_includes-tidy_path ${2})"
417    
418     src=(${src//\// })
419     dst=(${dst//\// })
420    
421     local i
422     for ((i=0; i<${#src[*]}; i++)); do
423     [ "${dst[i]}" != "${src[i]}" ] && break
424     done
425    
426     local common=$i
427    
428     for ((i=${#src[*]}; i>common; i--)); do
429     echo -n ../
430     done
431    
432     for ((i=common; i<${#dst[*]}-1; i++)); do
433     echo -n ${dst[i]}/
434     done
435    
436     echo -n ${dst[i]}
437 eradicator 1.3 }
438    
439     # Helper function for create_ml_includes
440 eradicator 1.5 create_ml_includes-tidy_path() {
441     local removed="${1}"
442    
443 eradicator 1.6 if [ -n "${removed}" ]; then
444 eradicator 1.5 # Remove multiple slashes
445     while [ "${removed}" != "${removed/\/\//\/}" ]; do
446     removed=${removed/\/\//\/}
447     done
448    
449     # Remove . directories
450     while [ "${removed}" != "${removed//\/.\//\/}" ]; do
451     removed=${removed//\/.\//\/}
452     done
453     [ "${removed##*/}" = "." ] && removed=${removed%/*}
454    
455     # Removed .. directories
456 eradicator 1.6 while [ "${removed}" != "${removed//\/..\/}" ]; do
457     local p1="${removed%%\/..\/*}"
458     local p2="${removed#*\/..\/}"
459    
460     removed="${p1%\/*}/${p2}"
461 eradicator 1.5 done
462    
463     # Remove trailing ..
464 eradicator 1.6 [ "${removed##*/}" = ".." ] && removed=${removed%/*/*}
465 eradicator 1.5
466     # Remove trailing /
467     [ "${removed##*/}" = "" ] && removed=${removed%/*}
468    
469 eradicator 1.3 echo ${removed}
470     fi
471 eradicator 1.2 }
472    
473     # Helper function for create_ml_includes
474     create_ml_includes-listdirs() {
475     local dirs
476     local data
477     for data in ${@}; do
478     dirs="${dirs} ${data/*:/}"
479     done
480     echo ${dirs:1}
481     }
482    
483     # Helper function for create_ml_includes
484     create_ml_includes-makedestdirs() {
485     local dest=${1}
486     shift
487     local basedirs=${@}
488    
489     dodir ${dest}
490    
491     local basedir
492     for basedir in ${basedirs}; do
493     local dir
494     for dir in $(find ${D}/${basedir} -type d); do
495     dodir ${dest}/${dir/${D}\/${basedir}/}
496     done
497     done
498     }
499    
500     # Helper function for create_ml_includes
501     create_ml_includes-allfiles() {
502     local basedirs=${@}
503    
504 eradicator 1.7 local basedir
505 eradicator 1.2 for basedir in ${basedirs}; do
506     local file
507     for file in $(find ${D}/${basedir} -type f); do
508     echo ${file/${D}\/${basedir}\//}
509     done
510     done | sort | uniq
511     }
512    
513     # Helper function for create_ml_includes
514     create_ml_includes-sym_for_dir() {
515     local dir="${1}"
516     shift
517     local data
518     for data in ${@}; do
519     if [ "${dir}" = "${data/*:/}" ]; then
520     echo ${data/:*/}
521     return 0
522     fi
523     done
524 eradicator 1.7 echo "Shouldn't be here -- create_ml_includes-sym_for_dir ${1} ${@}"
525 eradicator 1.2 # exit because we'll likely be called from a subshell
526     exit 1
527 eradicator 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.20