Gentoo emerge: Failed Running automake

This article is for Gentoo build problem:

Failed Running automake

but basically the problem could occur in any Linux system and the solution is logically the same.
During our @world update our emerge failed on:

>>> Emerging (44 of 95) dev-libs/libmemcached-1.0.18-r3::gentoo
 * libmemcached-1.0.18.tar.gz BLAKE2B SHA512 size ;-) ...                                                                                                            [ ok ]
>>> Unpacking source...
>>> Unpacking libmemcached-1.0.18.tar.gz to /var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work
>>> Source unpacked in /var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work
>>> Preparing source in /var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work/libmemcached-1.0.18 ...
 * Applying debug-disable-enable-1.0.18.patch ...                                                                                                                    [ ok ]
 * Applying continuum-1.0.18.patch ...                                                                                                                               [ ok ]
 * Applying libmemcached-1.0.18-gcc7.patch ...                                                                                                                       [ ok ]
 * Running eautoreconf in '/var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work/libmemcached-1.0.18' ...
 * Running libtoolize --install --copy --force --automake ...                                                                                                        [ ok ]
 * Running aclocal -I m4 -I libtest/m4 ...                                                                                                                           [ ok ]
 * Running autoconf --force ...                                                                                                                                      [ ok ]
 * Running autoheader ...                                                                                                                                            [ ok ]
 * Running automake --add-missing --copy --foreign --force-missing ...                                                                                               [ !! ]

 * Failed Running automake !
 * 
 * Include in your bugreport the contents of:
 * 
 *   /var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/temp/automake.out

 * ERROR: dev-libs/libmemcached-1.0.18-r3::gentoo failed (prepare phase):
 *   Failed Running automake !
 * 
 * Call stack:
 *     ebuild.sh, line  124:  Called src_prepare
 *   environment, line 2214:  Called eautoreconf
 *   environment, line  714:  Called eautomake
 *   environment, line  668:  Called autotools_run_tool 'automake' '--add-missing' '--copy' '--foreign' '--force-missing'
 *   environment, line  532:  Called die
 * The specific snippet of code:
 *           die "Failed Running $1 !";
 * 
 * If you need support, post the output of `emerge --info '=dev-libs/libmemcached-1.0.18-r3::gentoo'`,
 * the complete build log and the output of `emerge -pqv '=dev-libs/libmemcached-1.0.18-r3::gentoo'`.
 * The complete build log is located at '/var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/temp/build.log'.
 * The ebuild environment file is located at '/var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/temp/environment'.
 * Working directory: '/var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work/libmemcached-1.0.18'
 * S: '/var/tmp/portage/dev-libs/libmemcached-1.0.18-r3/work/libmemcached-1.0.18'

>>> Failed to emerge dev-libs/libmemcached-1.0.18-r3, Log file:

We have installed automake, the dependency is OK, there is no need of new version of automake (the libmemcached did not required to install a new version as a dependency), but still the build process failed!
automake has many different versions installed on the same system and the problem is that one of your currently installed version is too old, so you must upgrade all versions (from the all different branches installed).
First check what versions are installed (equery is part of app-portage/gentoolkit):

root@srv ~ # equery list automake
 * Searching for automake ...
[I--] [??] sys-devel/automake-1.11.3:1.11
[I--] [??] sys-devel/automake-1.12.6:1.12
[I--] [??] sys-devel/automake-1.13.4:1.13
[I--] [??] sys-devel/automake-1.14.1:1.14
[IP-] [  ] sys-devel/automake-1.15.1-r2:1.15
[IP-] [  ] sys-devel/automake-1.16.1-r1:1.16

We have version from branch 1.11, 1.12, 1.13 and 1.14 – one of these version is causing the problem!
Up until now no package required as a dependency 1.15 and 1.16, so we do not have it installed.

Here we upgrade them all to their latest versions in every branch version:

root@srv ~ # emerge -vu sys-devel/automake:1.11 sys-devel/automake:1.12 sys-devel/automake:1.13 sys-devel/automake:1.14

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild     U  ] sys-devel/automake-1.12.6-r2:1.12::gentoo [1.12.6:1.12::gentoo] USE="-test%" 1368 KiB
[ebuild     U  ] sys-devel/automake-1.11.6-r3:1.11::gentoo [1.11.3:1.11::gentoo] USE="-test%" 896 KiB
[ebuild     U  ] sys-devel/automake-1.14.1-r2:1.14::gentoo [1.14.1:1.14::gentoo] USE="-test%" 1455 KiB
[ebuild     U  ] sys-devel/automake-1.13.4-r2:1.13::gentoo [1.13.4:1.13::gentoo] USE="-test%" 1416 KiB

Total: 4 packages (4 upgrades), Size of downloads: 5133 KiB

As you can see we have updated version in every branch! And after updating them the building of libmemcached passed smoothly!
It’s not only in Gentoo, in most Linux distros (such as Ubuntu, CentOS, Manjaro, Mint and so on) have multiple automake version installed, so if you encounter this problem check your automake version installed for their latest versions and also if you miss some of them.