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

Contents of /eclass/multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Tue Mar 8 11:56:49 2005 UTC (9 years, 6 months ago) by eradicator
Branch: MAIN
Changes since 1.25: +3 -1 lines
Don't set ABI=default as it causes econf to add --libdir for archs where it used to not add it.

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

  ViewVC Help
Powered by ViewVC 1.1.20