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

Contents of /trunk/prefix/eclass/gnatbuild.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1166 - (show annotations) (download)
Sat Mar 25 22:08:50 2006 UTC (13 years, 1 month ago) by kito
File size: 15886 byte(s)
PREFIX->EPREFIX DEST->EDEST
1 # Copyright 1999-2006 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/gnatbuild.eclass,v 1.4 2006/01/23 23:03:08 george Exp $
4
5 # ATTN!
6 # set HOMEPAGE and LICENSE in appropriate ebuild, as we have
7 # gnat developed at two locations now.
8
9 inherit versionator toolchain-funcs flag-o-matic multilib
10
11 EXPORT_FUNCTIONS pkg_setup pkg_postinst pkg_prerm src_unpack src_compile src_install
12
13 DESCRIPTION="Based on the ${ECLASS} eclass"
14
15 IUSE="nls multilib"
16
17 RDEPEND="app-admin/eselect-gnat"
18
19 #---->> globals and SLOT <<----
20
21 # just a check, this location seems to vary too much, easier to track it in
22 # ebuild
23 #[ -z "${GNATSOURCE}" ] && die "please set GNATSOURCE in ebuild! (before inherit)"
24
25 # versioning
26 # because of gnatpro/gnatgpl we need to track both gcc and gnat versions
27
28 # these simply default to $PV
29 GNATMAJOR=$(get_version_component_range 1)
30 GNATMINOR=$(get_version_component_range 2)
31 GNATBRANCH=$(get_version_component_range 1-2)
32 GNATRELEASE=$(get_version_component_range 1-3)
33
34 # GCCVER and SLOT logic
35 #
36 # I better define vars for package names, as there was discussion on proper
37 # naming and it may change
38 PN_GnatGCC="gnat-gcc"
39 PN_GnatGpl="gnat-gpl"
40 PN_GnatPro="gnat-pro"
41
42 # ATTN! GCCVER stands for the provided backend gcc, not the one on the system
43 # so tc-* functions are of no use here
44 #
45 # GCCVER can be set in the ebuild, but then care will have to be taken
46 # to set it before inheriting, which is easy to forget
47 # so set it here for what we can..
48 if [[ ${PN} == "${PN_GnatGCC}" ]] ; then
49 GCCVER="${PV}"
50 elif [[ ${PN} == "${PN_GnatGpl}" ]] ; then
51 GCCVER="${GNATRELEASE}"
52 elif [[ ${PN} == "${PN_GnatPro}" ]] ; then
53 # Ada Core provided stuff is really conservative and changes backends rarely
54 case "${GNATMAJOR}" in
55 "3") GCCVER="2.8.1" ;;
56 "2005") GCCVER="3.4.5" ;;
57 esac
58 else
59 # gpc, gdc and possibly others will use a lot of common logic, I'll try to
60 # provide some support for them via this eclass
61 die "no support for other gcc frontends so far. Sorry."
62 fi
63
64 # finally extract GCC version strings
65 GCCMAJOR=$(get_version_component_range 1 "${GCCVER}")
66 GCCMINOR=$(get_version_component_range 2 "${GCCVER}")
67 GCCBRANCH=$(get_version_component_range 1-2 "${GCCVER}")
68 GCCRELEASE=$(get_version_component_range 1-3 "${GCCVER}")
69
70 # SLOT logic, make it represent gcc backend, as this is what matters most
71 SLOT="${GCCBRANCH}"
72
73 # possible future crosscompilation support
74 export CTARGET=${CTARGET:-${CHOST}}
75
76 is_crosscompile() {
77 [[ ${CHOST} != ${CTARGET} ]]
78 }
79
80
81 # set our install locations
82 PREFIX=${GNATBUILD_PREFIX:-/usr} # not sure we need this hook, but may be..
83 LIBPATH=${EPREFIX}/lib/${PN}/${CTARGET}/${SLOT}
84 LIBEXECPATH=${EPREFIX}/libexec/${PN}/${CTARGET}/${SLOT}
85 INCLUDEPATH=${LIBPATH}/include
86 BINPATH=${EPREFIX}/${CTARGET}/${PN}-bin/${SLOT}
87 DATAPATH=${EPREFIX}/share/${PN}-data/${CTARGET}/${SLOT}
88
89 # ebuild globals
90 if [[ ${PN} == "${PN_GnatPro}" ]] && [[ ${GNATMAJOR} == "3" ]]; then
91 DEPEND="x86? ( >=app-shells/tcsh-6.0 )"
92 fi
93 S="${WORKDIR}/gcc-${GCCVER}"
94
95 # bootstrap globals, common to src_unpack and src_compile
96 case $(tc-arch) in
97 ppc)
98 GNATBOOT="${WORKDIR}/gnat-3.15p-powerpc-unknown-linux-gnu"
99 GNATBOOTINST="${GNATBOOT}"
100 GCC_EXEC_BASE="${GNATBOOT}/lib/gcc-lib"
101 ;;
102 amd64 | x86)
103 GNATBOOT="${WORKDIR}/usr"
104 ;;
105 esac
106
107 # some buildtime globals
108 GNATBUILD="${WORKDIR}/build"
109
110 # necessary for detecting lib locations and creating env.d entry
111 #XGCC="${GNATBUILD}/gcc/xgcc -B${GNATBUILD}/gcc"
112
113 #----<< globals and SLOT >>----
114
115 # set SRC_URI's in ebuilds for now
116
117 #----<< support checks >>----
118 # skipping this section - do not care about hardened/multilib for now
119
120 #---->> specs + env.d logic <<----
121 # TODO!!!
122 # set MANPATH, etc..
123 #----<< specs + env.d logic >>----
124
125
126 #---->> some helper functions <<----
127 is_multilib() {
128 [[ ${GCCMAJOR} < 3 ]] && return 1
129 case ${CTARGET} in
130 mips64*|powerpc64*|s390x*|sparc64*|x86_64*)
131 has_multilib_profile || use multilib ;;
132 *) false ;;
133 esac
134 }
135
136 # adapted from toolchain,
137 # left only basic multilib functionality and cut off mips stuff
138 create_gnat_env_entry() {
139 dodir /etc/env.d/gnat
140 local gnat_envd_base="/etc/env.d/gnat/${CTARGET}-${PN}-${SLOT}"
141
142 gnat_envd_file="${D}${gnat_envd_base}"
143 # gnat_specs_file=""
144
145 echo "PATH=\"${BINPATH}:${LIBEXECPATH}\"" > ${gnat_envd_file}
146
147 LDPATH="${LIBPATH}"
148 for path in 32 64 o32 ; do
149 [[ -d ${LIBPATH}/${path} ]] && LDPATH="${LDPATH}:${LIBPATH}/${path}"
150 done
151 echo "LDPATH=\"${LDPATH}\"" >> ${gnat_envd_file}
152
153 echo "MANPATH=\"${DATAPATH}/man\"" >> ${gnat_envd_file}
154 echo "INFOPATH=\"${DATAPATH}/info\"" >> ${gnat_envd_file}
155
156 is_crosscompile && echo "CTARGET=${CTARGET}" >> ${gnat_envd_file}
157
158 # Set which specs file to use
159 # [[ -n ${gnat_specs_file} ]] && echo "GCC_SPECS=\"${gnat_specs_file}\"" >> ${gnat_envd_file}
160 }
161
162 # eselect stuff taken straight from toolchain.eclass and greatly simplified
163 add_profile_eselect_conf() {
164 local gnat_config_file=$1
165 local abi=$2
166 local var
167
168 echo >> ${gnat_config_file}
169 if ! is_multilib ; then
170 echo " ctarget=${CTARGET}" >> ${gnat_config_file}
171 else
172 echo "[${abi}]" >> ${gnat_config_file}
173 var="CTARGET_${abi}"
174 if [[ -n ${!var} ]] ; then
175 echo " ctarget=${!var}" >> ${gnat_config_file}
176 else
177 var="CHOST_${abi}"
178 if [[ -n ${!var} ]] ; then
179 echo " ctarget=${!var}" >> ${gnat_config_file}
180 else
181 echo " ctarget=${CTARGET}" >> ${gnat_config_file}
182 fi
183 fi
184 fi
185
186 var="CFLAGS_${abi}"
187 if [[ -n ${!var} ]] ; then
188 echo " cflags=${!var}" >> ${gnat_config_file}
189 fi
190 }
191
192
193 create_eselect_conf() {
194 # it would be good to source gnat.eselect module here too,
195 # but we only need one path
196 local config_dir="/usr/share/gnat/eselect"
197 local gnat_config_file="${D}/${config_dir}/${CTARGET}-${PN}-${SLOT}"
198 local abi
199
200 dodir ${config_dir}
201
202 echo "[global]" > ${gnat_config_file}
203 echo " version=${CTARGET}-${SLOT}" >> ${gnat_config_file}
204 echo " binpath=${BINPATH}" >> ${gnat_config_file}
205 echo " libexecpath=${LIBEXECPATH}" >> ${gnat_config_file}
206 echo " ldpath=${LIBPATH}" >> ${gnat_config_file}
207 echo " manpath=${DATAPATH}/man" >> ${gnat_config_file}
208 echo " infopath=${DATAPATH}/info" >> ${gnat_config_file}
209 # echo " alias_cc=gcc" >> ${compiler_config_file}
210 # echo " stdcxx_incdir=${STDCXX_INCDIR##*/}" >> ${compiler_config_file}
211 echo " bin_prefix=${CTARGET}" >> ${gnat_config_file}
212
213 for abi in $(get_all_abis) ; do
214 add_profile_eselect_conf "${gnat_config_file}" "${abi}"
215 done
216 }
217
218
219 # active compiler selection, called from pkg_postinst
220 do_gnat_config() {
221 eselect gnat set ${CTARGET}-${PN}-${SLOT} &> /dev/null
222
223 einfo "The following gnat profile has been activated:"
224 einfo "${CTARGET}-${PN}-${SLOT}"
225 einfo ""
226 einfo "The compiler has been installed as gnatgcc, and the coverage testing"
227 einfo "tool as gnatgcov."
228 }
229
230 #---->> pkg_* <<----
231 gnatbuild_pkg_setup() {
232 debug-print-function ${FUNCNAME} $@
233
234 # Setup variables which would normally be in the profile
235 if is_crosscompile ; then
236 multilib_env ${CTARGET}
237 if ! use multilib ; then
238 MULTILIB_ABIS=${DEFAULT_ABI}
239 fi
240 fi
241
242 # we dont want to use the installed compiler's specs to build gnat!
243 unset GCC_SPECS
244 }
245
246 gnatbuild_pkg_postinst() {
247 do_gnat_config
248 }
249
250 # eselect-gnat can be unmerged together with gnat-*, so we better do this before
251 # actual removal takes place, rather than in postrm, like toolchain does
252 gnatbuild_pkg_prerm() {
253 # files for eselect module are left behind, so we need to cleanup.
254 if [ ! -f ${EPREFIX}/usr/share/eselect/modules/gnat.eselect ] ; then
255 eerror "eselect-gnat was prematurely unmerged!"
256 eerror "You will have to manually remove unnecessary files"
257 eerror "under /etc/eselect/gnat and /etc/env.d/55gnat-xxx"
258 exit # should *not* die, as this will stop unmerge!
259 fi
260
261 # this copying/modifying and then sourcing of a gnat.eselect is a hack,
262 # but having a duplicate functionality is really bad - gnat.eselect module
263 # might change..
264 cat ${EPREFIX}/usr/share/eselect/modules/gnat.eselect | \
265 grep -v "svn_date_to_version" | \
266 grep -v "DESCRIPTION" \
267 > ${WORKDIR}/gnat.esel
268 . ${WORKDIR}/gnat.esel
269
270 # see if we need to unset gnat
271 if [[ $(get_current_gnat) == "${CTARGET}-${PN}-${SLOT}" ]] ; then
272 eselect gnat unset &> /dev/null
273 fi
274 }
275 #---->> pkg_* <<----
276
277 #---->> src_* <<----
278
279 # common unpack stuff
280 gnatbuild_src_unpack() {
281 debug-print-function ${FUNCNAME} $@
282 [ -z "$1" ] && gnatbuild_src_unpack all
283
284 while [ "$1" ]; do
285 case $1 in
286 base_unpack)
287 unpack ${A}
288 ;;
289
290 common_prep)
291 # Prepare the gcc source directory
292 if [ "2.8.1" == "${GCCVER}" ] ; then
293 cd "${S}"
294 else
295 cd "${S}/gcc"
296 fi
297 touch cstamp-h.in
298 touch ada/[es]info.h
299 touch ada/nmake.ad[bs]
300 # set the compiler name to gnatgcc
301 for i in `find ada/ -name '*.ad[sb]'`; do \
302 sed -i -e "s/\"gcc\"/\"gnatgcc\"/g" ${i}; \
303 done
304 # add -fPIC flag to shared libs
305 cd ada
306 patch Make-lang.in < ${FILESDIR}/gnat-Make-lang.in.patch
307
308 mkdir -p "${GNATBUILD}"
309 ;;
310
311 all)
312 gnatbuild_src_unpack base_unpack common_prep
313 ;;
314 esac
315 shift
316 done
317 }
318
319 # it would be nice to split configure and make steps
320 # but both need to operate inside specially tuned evironment
321 # so just do sections for now (as in eclass section of handbook)
322 # sections are: configure, make-tools, bootstrap,
323 # gnatlib_and_tools, gnatlib-shared
324 gnatbuild_src_compile() {
325 debug-print-function ${FUNCNAME} $@
326 if [[ -z "$1" ]]; then
327 gnatbuild_src_compile all
328 return $?
329 fi
330
331 if [ "all" == "$1" ]
332 then # specialcasing "all" to avoid scanning sources unnecessarily
333 gnatbuild_src_compile configure make-tools \
334 bootstrap gnatlib_and_tools gnatlib-shared
335
336 else
337 # Set some paths to our bootstrap compiler.
338 export PATH="${GNATBOOT}/bin:${PATH}"
339 if [ "${PN_GnatPro}-3.15p" == "${P}" ]; then
340 GNATLIB="${GNATBOOT}/lib/gcc-lib/${CTARGET}/${SLOT}"
341 else
342 GNATLIB="${GNATBOOT}/lib/gnatgcc/${CTARGET}/${SLOT}"
343 fi
344
345 export CC="${GNATBOOT}/bin/gnatgcc"
346
347 export ADA_OBJECTS_PATH="${GNATLIB}/adalib"
348 export ADA_INCLUDE_PATH="${GNATLIB}/adainclude"
349 export LDFLAGS="-L${GNATLIB}"
350
351 # if [ "2.8.1" == ${GCCVER} ]; then
352 # export BINUTILS_ROOT="${GNATBOOT}"
353 # fi
354
355 #einfo "CC=${CC}, ADA_INCLUDE_PATH=${ADA_INCLUDE_PATH}, LDFLAGS=${LDFLAGS}"
356
357 while [ "$1" ]; do
358 case $1 in
359 configure)
360 debug-print-section configure
361 # Configure gcc
362 local confgcc
363
364 # some cross-compile logic from toolchain
365 confgcc="${confgcc} --host=${CHOST}"
366 if is_crosscompile || tc-is-cross-compiler ; then
367 confgcc="${confgcc} --target=${CTARGET}"
368 fi
369 [[ -n ${CBUILD} ]] && confgcc="${confgcc} --build=${CBUILD}"
370
371 # Native Language Support
372 if use nls ; then
373 confgcc="${confgcc} --enable-nls --without-included-gettext"
374 else
375 confgcc="${confgcc} --disable-nls"
376 fi
377
378 # reasonably sane globals (from toolchain)
379 confgcc="${confgcc} \
380 --with-system-zlib \
381 --disable-checking \
382 --disable-werror \
383 --disable-libunwind-exceptions"
384
385 cd "${GNATBUILD}"
386 CFLAGS="${CFLAGS}" CXXFLAGS="${CXXFLAGS}" "${S}"/configure \
387 --prefix=${EPREFIX} \
388 --bindir=${BINPATH} \
389 --includedir=${INCLUDEPATH} \
390 --libdir="${LIBPATH}" \
391 --libexecdir="${LIBEXECPATH}" \
392 --datadir=${DATAPATH} \
393 --mandir=${DATAPATH}/man \
394 --infodir=${DATAPATH}/info \
395 --program-prefix=gnat \
396 --enable-languages="c,ada" \
397 --enable-libada \
398 --with-gcc \
399 --enable-threads=posix \
400 --enable-shared \
401 --with-system-zlib \
402 --disable-nls \
403 ${confgcc} || die "configure failed"
404 ;;
405
406 make-tools)
407 debug-print-section make-tools
408 # Compile helper tools
409 cd "${GNATBOOT}"
410 cp ${S}/gcc/ada/xtreeprs.adb .
411 cp ${S}/gcc/ada/xsinfo.adb .
412 cp ${S}/gcc/ada/xeinfo.adb .
413 cp ${S}/gcc/ada/xnmake.adb .
414 gnatmake xtreeprs && \
415 gnatmake xsinfo && \
416 gnatmake xeinfo && \
417 gnatmake xnmake || die "building helper tools"
418 ;;
419
420 bootstrap)
421 debug-print-section bootstrap
422 # and, finally, the build itself
423 cd "${GNATBUILD}"
424 emake bootstrap || die "bootstrap failed"
425 ;;
426
427 gnatlib_and_tools)
428 debug-print-section gnatlib_and_tools
429 einfo "building gnatlib_and_tools"
430 cd "${GNATBUILD}"
431 emake -j1 -C gcc gnatlib_and_tools ||
432 die "gnatlib_and_tools failed"
433 ;;
434
435 gnatlib-shared)
436 debug-print-section gnatlib-shared
437 einfo "building shared lib"
438 cd "${GNATBUILD}"
439 rm -f gcc/ada/rts/*.{o,ali} || die
440 #otherwise make tries to reuse already compiled (without -fPIC) objs..
441 emake -j1 -C gcc gnatlib-shared LIBRARY_VERSION="${GCCBRANCH}" ||
442 die "gnatlib-shared failed"
443 ;;
444 esac
445 shift
446 done # while
447 fi # "all" == "$1"
448 }
449
450
451 gnatbuild_src_install() {
452 debug-print-function ${FUNCNAME} $@
453
454 if [[ -z "$1" ]] ; then
455 gnatbuild_src_install all
456 return $?
457 fi
458
459 while [ "$1" ]; do
460 case $1 in
461 install) # runs provided make install
462 debug-print-section install
463 # Do not allow symlinks in /usr/lib/gcc/${CHOST}/${MY_PV}/include as
464 # this can break the build.
465 for x in "${GNATBUILD}"/gcc/include/* ; do
466 if [ -L ${x} ] ; then
467 rm -f ${x}
468 fi
469 done
470 # Remove generated headers, as they can cause things to break
471 # (ncurses, openssl, etc). (from toolchain.eclass)
472 for x in $(find "${WORKDIR}"/build/gcc/include/ -name '*.h') ; do
473 grep -q 'It has been auto-edited by fixincludes from' "${x}" \
474 && rm -f "${x}"
475 done
476
477
478 # Install gnatgcc, tools and native threads library
479 cd "${GNATBUILD}"
480 if [ "${PN_GnatGpl}-3.4.5.1" != "${P}" ]; then # this one is strange
481 make DESTDIR=${D} install || die
482 #make a convenience info link
483 dosym ${DATAPATH}/info/gnat_ugn_unw.info ${DATAPATH}/info/gnat.info
484 fi
485 ;;
486
487 move_libs)
488 debug-print-section move_libs
489 # gcc insists on installing libs in its own place
490 mv "${D}${LIBPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBPATH}"
491 if [ "${ARCH}" == "amd64" ]; then
492 # ATTN! this may in fact be related to multilib, rather than amd64
493 mv "${D}${LIBPATH}"/../lib64/libgcc_s* "${D}${LIBPATH}"
494 mv "${D}${LIBPATH}"/../lib/libgcc_s* "${D}${LIBPATH}"/32/
495 fi
496 mv "${D}${LIBEXECPATH}/gcc/${CTARGET}/${GCCRELEASE}"/* "${D}${LIBEXECPATH}"
497
498 # set the rts libs
499 cd "${D}${LIBPATH}"
500 mkdir rts-native
501 mv adalib adainclude rts-native
502 ln -s rts-native/adalib adalib
503 ln -s rts-native/adainclude adainclude
504
505 # force gnatgcc to use its own specs - when installed it reads specs
506 # from system gcc location. Do the simple wrapper trick for now
507 # !ATTN! change this if eselect-gnat starts to follow eselect-compiler
508 cd "${D}${BINPATH}"
509 mv gnatgcc gnatgcc_2wrap
510 cat > gnatgcc << EOF
511 #! /bin/bash
512 # wrapper to cause gnatgcc read appropriate specs
513 BINDIR=\$(dirname \$0)
514 \${BINDIR}/gnatgcc_2wrap -specs="${LIBPATH}/specs" \$@
515 EOF
516 chmod a+x gnatgcc
517
518 # use gid of 0 because some stupid ports don't have
519 # the group 'root' set to gid 0 (toolchain.eclass)
520 chown -R root:0 "${D}${LIBPATH}"
521 ;;
522
523 cleanup)
524 debug-print-section cleanup
525
526 rm -rf "${D}${LIBPATH}"/../li{b,b64}
527 rm -rf "${D}${LIBPATH}/gcc"
528 rm -rf "${D}${LIBEXECPATH}/gcc"
529 rm -f "${D}${LIBPATH}"/libiberty.a # this one comes with binutils
530 rmdir "${D}${LIBPATH}"/include/ # should be empty
531
532 rm -rf "${D}${LIBEXECPATH}"/install-tools/
533
534 # this one is installed by gcc and is a duplicate even here anyway
535 rm -f "${D}${BINPATH}/${CTARGET}-gcc-${GCCRELEASE}"
536
537 # remove duplicate docs
538 cd "${D}${DATAPATH}"
539 has noinfo ${FEATURES} \
540 && rm -rf info \
541 || rm -f info/{dir,gcc,cpp}*
542 has noman ${FEATURES} \
543 && rm -rf man \
544 || rm -rf man/man7/
545 ;;
546
547 prep_env)
548 #dodir /etc/env.d/gnat
549 #create_gnat_env_entry
550 # instead of putting junk under /etc/env.d/gnat we recreate env files as
551 # needed with eselect
552 create_eselect_conf
553 ;;
554
555 all)
556 gnatbuild_src_install install move_libs cleanup prep_env
557 ;;
558 esac
559 shift
560 done # while
561 }

  ViewVC Help
Powered by ViewVC 1.1.20