| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- # Copyright 1999-2026 Gentoo Authors
- # Distributed under the terms of the GNU General Public License v2
- EAPI="8"
- CHOST="avr"
- CTARGET="avr"
- inherit flag-o-matic
- DESCRIPTION="C library for Atmel AVR microcontrollers"
- HOMEPAGE="https://github.com/avrdudes/avr-libc https://www.nongnu.org/avr-libc/"
- # Upstream moved from Savannah to GitHub with 2.2.0. The GitHub "release"
- # tarball ships a pre-generated ./configure and the avr/{lib,devices} trees
- # (mlib-gen.py output), so no bootstrap / autotools / python is needed to
- # build it. Manual pages are no longer a separate download; they are built
- # from the tree only when doxygen is present, which we do not pull in.
- MY_TAG="avr-libc-$(ver_rs 1- '_')-release"
- SRC_URI="https://github.com/avrdudes/avr-libc/releases/download/${MY_TAG}/${P}.tar.bz2"
- LICENSE="BSD"
- SLOT="0"
- # 'amd64' is a blessed placeholder for crossdev. It could
- # be any other arch. See bug #620316#c5
- # Don't add more arches to KEYWORDS.
- KEYWORDS="amd64"
- IUSE="headers-only"
- DEPEND=">=sys-devel/crossdev-0.9.1"
- [[ ${CATEGORY/cross-} != ${CATEGORY} ]] \
- && RDEPEND="!dev-embedded/avr-libc" \
- || RDEPEND=""
- DOCS="AUTHORS NEWS NEWS.md README.md"
- pkg_setup() {
- # check for avr-gcc, bug #134738
- ebegin "Checking for avr-gcc"
- if type -p avr-gcc > /dev/null ; then
- eend 0
- else
- eend 1
- eerror
- eerror "Failed to locate 'avr-gcc' in \$PATH. You can install an AVR toolchain using:"
- eerror " $ crossdev -t avr"
- eerror
- die "AVR toolchain not found"
- fi
- }
- src_prepare() {
- default
- # work around broken gcc versions PR45261: drop MCUs the installed
- # avr-gcc does not know about so ./configure does not choke on them.
- local mcu
- for mcu in $(sed -r -n '/CHECK_AVR_DEVICE/{s:.*[(](.*)[)]:\1:;p}' configure.ac) ; do
- if avr-gcc -E - -mmcu=${mcu} <<<"" |& grep -q 'unknown MCU' ; then
- sed -i "/HAS_${mcu}=yes/s:yes:no:" configure || die
- fi
- done
- strip-flags
- strip-unsupported-flags
- }
- src_configure() {
- # --enable-device-lib builds the per-device lib<mcu>.a / crt<mcu>.o.
- # It is on by default with avr-gcc >= 5.1 but be explicit. Docs are
- # off by default in 2.2+; keep them off (no doxygen dependency).
- econf \
- --host=avr \
- --enable-device-lib \
- --disable-doc
- }
- src_install() {
- default
- # Make sure different cross-compilers don't collide #414075
- if [[ -d ${ED}/usr/share/doc/${PF} ]] ; then
- mv "${ED}"/usr/share/doc/{${PF},${CTARGET}-${PF}} || die
- fi
- # https://github.com/avrdudes/avr-libc/issues/1060 documents that,
- # since avr-libc 2.3.0, crt<mcu>.o only *declares* `main` as a
- # referenced symbol so the linker is supposed to pull in
- # __call_main (which actually calls main()+exit()) from
- # lib<mcu>.a's call_main.o. In practice a plain `.global main` in
- # crt<mcu>.o is satisfied directly by the user's own main() and
- # never triggers extraction of call_main.o, so .init9 stays empty
- # and the reset vector falls straight through into __bad_interrupt
- # (jmp 0) -- main() is never called and the device does nothing.
- # Work around this by forcing `-u __call_main` on every link via a
- # small specs file dropped next to avr-gcc's own specs; this is a
- # no-op for pre-2.3.0-style self-contained crt objects.
- local gccdir
- gccdir=$(avr-gcc -print-search-dirs | sed -n 's/^install: //p') || die
- [[ -d ${gccdir} ]] || die "could not determine avr-gcc install dir"
- local specs="${T}/specs"
- avr-gcc -dumpspecs > "${specs}" || die
- sed -i '/^\*lib:$/{n;s/$/ -u __call_main/}' "${specs}" || die
- grep -q -- '-u __call_main' "${specs}" || die "failed to patch *lib spec"
- insinto "${gccdir#${EPREFIX}}"
- newins "${specs}" specs
- }
|