Created attachment 442806 [details] ebuild file octave.org has released a bugfix release 4.0.3. I just copied over the octave-4.0.2-r1.ebuild file and removed the octave-4.0.0-imagemagick.patch because it fails. The package then compiles and starts fine for me, with the restrictions of bugs #590674 (need sci-libs/cxsparse release which install a pkg-config file like cxsparse-3.1.2), #590676 (no library containing tputs found) and #590686 (incoherent Qt support, export QT_SELECT=qt4 to compile).
commit 209273b20054ce83a2aa71c62d256dea7e564cc6 Author: David Seifert <soap@gentoo.org> Date: Sun Aug 21 11:02:05 2016 +0200 sci-mathematics/octave: version bump Gentoo-bug: 590676, 590792 * EAPI=6 * Make patches -p1 compliant * Use pkg-config for finding curses flags