diff --git a/dev-libs/libdwarf/Manifest b/dev-libs/libdwarf/Manifest
index 0b1edc3e22..1c18e87bb4 100644
--- a/dev-libs/libdwarf/Manifest
+++ b/dev-libs/libdwarf/Manifest
@@ -1 +1 @@
-DIST libdwarf-20210528.tar.gz 2869691 BLAKE2B 43fb0a45c5e3ab96d402a09b129764fc47a2ff0a6ea9ea8930e074cf648beaec8dba72fc6a6be939c80de14190f7fb486b0c617de93713a78296b4e6c854bf2a SHA512 e0f9c88554053ee6c1b1333960891189e7820c4a4ddc302b7e63754a4cdcfc2acb1b4b6083a722d1204a75e994fff3401ecc251b8c3b24090f8cb4046d90f870
+DIST libdwarf-0.4.0.tar.xz 2380228 BLAKE2B ee9d02284740b3f4961299e2e4530c2934cde4defefebd8a8ca3aab232f0a18fc35d376c2f61ee323f7db7e6460a3f5e662781f8086438c287f716067c2b7594 SHA512 30e5c6c1fc95aa28a014007a45199160e1d9ba870b196d6f98e6dd21a349e9bb31bba1bd6817f8ef9a89303bed0562182a7d46fcbb36aedded76c2f1e0052e1e
diff --git a/dev-libs/libdwarf/libdwarf-0.4.0.ebuild b/dev-libs/libdwarf/libdwarf-0.4.0.ebuild
new file mode 100644
index 0000000000..68f8dd7be9
--- /dev/null
+++ b/dev-libs/libdwarf/libdwarf-0.4.0.ebuild
@@ -0,0 +1,47 @@
+# Copyright 1999-2022 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+inherit meson
+
+DESCRIPTION="The DWARF Debugging Information Format"
+HOMEPAGE="
+ https://www.prevanders.net/dwarf.html
+ https://www.dwarfstd.org
+ https://github.com/davea42/libdwarf-code
+"
+SRC_URI="https://www.prevanders.net/${P}.tar.xz"
+
+LICENSE="LGPL-2.1 GPL-2 BSD"
+SLOT="0"
+KEYWORDS="~amd64"
+IUSE="doc dwarfexample dwarfgen +elf"
+
+DEPEND="
+ sys-libs/zlib
+ elf? ( virtual/libelf:= )
+"
+RDEPEND="${DEPEND}"
+BDEPEND="doc? ( app-doc/doxygen )"
+
+src_configure() {
+
+ local emesonargs=(
+ $(meson_use dwarfgen)
+ $(meson_use dwarfexample)
+ $(meson_use doc)
+ $(meson_use elf libelf)
+ )
+ meson_src_configure
+}
+
+src_install(){
+ meson_src_install
+ dodoc AUTHORS README README.md ChangeLog* NEWS
+ if use doc; then
+ mkdir -p "${ED}/usr/share/doc/${PF}" || die
+ mv "${ED}/usr/share/doc/${PN}/html" "${ED}/usr/share/doc/${PF}/" || die
+ rm -r "${ED}/usr/share/doc/${PN}" || die
+ fi
+}
diff --git a/dev-libs/libdwarf/libdwarf-20210528-r1.ebuild b/dev-libs/libdwarf/libdwarf-20210528-r1.ebuild
deleted file mode 100644
index a1fdd9a05f..0000000000
--- a/dev-libs/libdwarf/libdwarf-20210528-r1.ebuild
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright 1999-2022 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI=8
-
-DESCRIPTION="The DWARF Debugging Information Format"
-HOMEPAGE="
- https://www.prevanders.net/dwarf.html
- http://www.dwarfstd.org
-"
-SRC_URI="https://www.prevanders.net/${P}.tar.gz"
-
-LICENSE="LGPL-2.1 GPL-2 BSD"
-SLOT="0"
-KEYWORDS="~amd64"
-IUSE="dwarfexample dwarfgen +elf global-alloc-sums namestable nonstandardprintf oldframecol sanitize"
-
-DEPEND="
- sys-libs/zlib
- elf? ( virtual/libelf:= )
-"
-RDEPEND="${DEPEND}"
-
-DOCS=( AUTHORS README README.md ChangeLog ChangeLog2018 NEWS )
-
-src_configure() {
-
- local myconf=(
- --disable-static
- --disable-windowspath
- --enable-shared
- --includedir="${EPREFIX}/usr/include/${PN}"
- )
-
- #this configure is so bad it enables when passing --disable
- use dwarfexample && myconf+=(--enable-dwarfexample)
- use dwarfgen && myconf+=(--enable-dwarfgen)
- use elf && myconf+=(--enable-libelf)
- use global-alloc-sums && myconf+=(--enable-global-alloc-csums)
- use namestable && myconf+=(--enable-namestable)
- use nonstandardprintf && myconf+=(--enable-nonstandardprintf)
- use oldframecol && myconf+=(--enable-oldframecol)
- use sanitize && myconf+=(--enable-sanitize)
-
- econf "${myconf[@]}"
-}
-
-src_install(){
- emake DESTDIR="${D}" install
- einstalldocs
-
- #--disable-static get ignored ...
- find "${ED}" -name '*.a' -delete || die
- find "${ED}" -name '*.la' -delete || die
-}
diff --git a/dev-libs/libdwarf/metadata.xml b/dev-libs/libdwarf/metadata.xml
index 57f690a053..0ae906ce8c 100644
--- a/dev-libs/libdwarf/metadata.xml
+++ b/dev-libs/libdwarf/metadata.xml
@@ -6,14 +6,12 @@
lssndrbarbieri@gmail.com
Alessandro Barbieri
+
+ davea42/libdwarf-code
+