Repository: conan-io/conan-center-index

Issue:
[package] libelf/0.8.13: libelf failed to config on ARM64 system
<!-- 
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.
-->

### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **libelf/0.8.13**
  * Operating System+version: **Linux Debian 10**
  * Compiler+version: **GCC 8**
  * Conan version: **conan 1.31.0**
  * Python version: **Python 3.7.3**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
[settings]
os=Linux
os_build=Linux
arch=armv8
arch_build=armv8
compiler=gcc
compiler.version=8
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
Create a simple conanfile.txt:
```
[requires]
libelf/0.8.13

[generators]
cmake
```

Then
```
mkdir build && cd build
conan install .. --build=libelf
```


### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
Configuration:
[settings]
arch=armv8
arch_build=armv8
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=8
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

libelf/0.8.13: Forced build from source
conanfile.txt: Installing package
Requirements
    libelf/0.8.13 from 'conan-center' - Cache
Packages
    libelf/0.8.13:67c966a55c91426283f2d35fd8468ed0740478c0 - Build
Build requirements
    autoconf/2.69 from 'conan-center' - Cache
    m4/1.4.18 from 'conan-center' - Cache
Build requirements packages
    autoconf/2.69:b0bab81756b4971d42859e9b1bc6f8b3fa8e036e - Cache
    m4/1.4.18:a38d7c31d4564d43a7705539d94b1907c6418a85 - Cache

Installing (downloading, building) binaries...
m4/1.4.18: Already installed!
m4/1.4.18: Appending PATH environment variable: /root/.conan/data/m4/1.4.18/_/_/package/a38d7c31d4564d43a7705539d94b1907c6418a85/bin
m4/1.4.18: Setting M4 environment variable: /root/.conan/data/m4/1.4.18/_/_/package/a38d7c31d4564d43a7705539d94b1907c6418a85/bin/m4
autoconf/2.69: Already installed!
autoconf/2.69: Appending PATH env var with : /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin
autoconf/2.69: Setting AC_MACRODIR to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/share/autoconf
autoconf/2.69: Setting AUTOCONF to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autoconf
autoconf/2.69: Setting AUTORECONF to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autoreconf
autoconf/2.69: Setting AUTOHEADER to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autoheader
autoconf/2.69: Setting AUTOM4TE to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autom4te
autoconf/2.69: Setting AUTOM4TE_PERLLIBDIR to /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/share/autoconf
libelf/0.8.13: Applying build-requirement: autoconf/2.69
libelf/0.8.13: Applying build-requirement: m4/1.4.18
libelf/0.8.13: WARN: Build folder is dirty, removing it: /root/.conan/data/libelf/0.8.13/_/_/build/67c966a55c91426283f2d35fd8468ed0740478c0
libelf/0.8.13: Copying sources to build folder
libelf/0.8.13: Building your package in /root/.conan/data/libelf/0.8.13/_/_/build/67c966a55c91426283f2d35fd8468ed0740478c0
libelf/0.8.13: Generator cmake created conanbuildinfo.cmake
libelf/0.8.13: Calling build()
autoreconf: Entering directory `.'
autoreconf: configure.in: not using Gettext
autoreconf: configure.in: not using aclocal
autoreconf: configure.in: tracing
autoreconf: configure.in: not using Libtool
autoreconf: running: /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autoconf --force
autoreconf: running: /root/.conan/data/autoconf/2.69/_/_/package/b0bab81756b4971d42859e9b1bc6f8b3fa8e036e/bin/autoheader --force
autoheader: WARNING: Using auxiliary files such as `acconfig.h', `config.h.bot'
autoheader: WARNING: and `config.h.top', to define templates for `config.h.in'
autoheader: WARNING: is deprecated and discouraged.
autoheader:
autoheader: WARNING: Using the third argument of `AC_DEFINE' and
autoheader: WARNING: `AC_DEFINE_UNQUOTED' allows one to define a template without
autoheader: WARNING: `acconfig.h':
autoheader:
autoheader: WARNING:   AC_DEFINE([NEED_FUNC_MAIN], 1,
autoheader:             [Define if a function `main' is needed.])
autoheader:
autoheader: WARNING: More sophisticated templates can also be produced, see the
autoheader: WARNING: documentation.
autoreconf: configure.in: not using Automake
autoreconf: Leaving directory `.'
libelf/0.8.13: Calling:
 > source_subfolder/configure '--enable-shared=no' '--prefix=/root/.conan/data/libelf/0.8.13/_/_/package/67c966a55c91426283f2d35fd8468ed0740478c0' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libexecdir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/share'
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for a BSD-compatible install... /usr/bin/install -c
checking for ranlib... ranlib
checking whether ln -s works... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for unistd.h... (cached) yes
checking for stdint.h... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking elf.h usability... yes
checking elf.h presence... yes
checking for elf.h... yes
checking sys/elf.h usability... yes
checking sys/elf.h presence... yes
checking for sys/elf.h... yes
checking link.h usability... yes
checking link.h presence... yes
checking for link.h... yes
checking sys/link.h usability... no
checking sys/link.h presence... no
checking for sys/link.h... no
checking if gcc can compile elf.h... yes
checking ar.h usability... yes
checking ar.h presence... yes
checking for ar.h... yes
checking libelf.h usability... no
checking libelf.h presence... no
checking for libelf.h... no
checking nlist.h usability... no
checking nlist.h presence... no
checking for nlist.h... no
checking gelf.h usability... no
checking gelf.h presence... no
checking for gelf.h... no
checking whether to install <libelf.h>, <nlist.h> and <gelf.h>... yes
checking for an ANSI C-conforming const... yes
checking for off_t... yes
checking for size_t... yes
checking size of short... 2
checking size of int... 4
checking size of long... 8
checking size of long long... 8
checking size of __int64... 0
checking for struct Elf32_Dyn... yes
checking for struct nlist in elf.h... no
checking for struct Elf64_Ehdr... yes
checking for Elf64_Addr... yes
checking for struct Elf64_Rel... yes
checking for Elf32_Verdef... yes
checking for Elf64_Verdef... yes
checking for SHT_SUNW_verdef... no
checking for SHT_GNU_verdef... yes
checking for 64-bit integer... long
checking for 32-bit integer... int
checking for 16-bit integer... short
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... yes
checking for working mmap... yes
checking for ftruncate... yes
checking for memcmp... yes
checking for memcpy... yes
checking for memmove... yes
checking for memset... yes
checking whether overlapping arrays are copied correctly... yes
checking the coffee machine... empty - operator may not work as expected
checking whether 64-bit ELF support is sufficient... yes
checking whether to include 64-bit support... yes
checking whether versioning support is sufficient... yes
checking whether to include versioning support... yes
checking whether NLS is requested... yes
checking for dgettext... yes
checking for msgfmt... no
checking for catgets... yes
checking for gencat... /usr/bin/gencat
checking for gmsgfmt... msgfmt
checking for xgettext... xgettext
checking for catalogs to be installed... de
checking for gettext in -lintl... no
checking build system type... source_subfolder/config.guess: unable to guess system type

This script, last modified 2004-06-11, has failed to recognize
the operating system you are using. It is advised that you
download the most up to date version of the config scripts from

    ftp://ftp.gnu.org/pub/gnu/config/

If the version you run (source_subfolder/config.guess) is already up to date, please
send the following data and any information you think might be
pertinent to <config-patches@gnu.org> in order to provide the needed
information to handle your system.

config.guess timestamp = 2004-06-11

uname -m = aarch64
uname -r = 4.19.0-12-arm64
uname -s = Linux
uname -v = #1 SMP Debian 4.19.152-1 (2020-10-18)

/usr/bin/uname -p = unknown
/bin/uname -X     =

hostinfo               =
/bin/universe          =
/usr/bin/arch -k       =
/bin/arch              = aarch64
/usr/bin/oslevel       =
/usr/convex/getsysinfo =

UNAME_MACHINE = aarch64
UNAME_RELEASE = 4.19.0-12-arm64
UNAME_SYSTEM  = Linux
UNAME_VERSION = #1 SMP Debian 4.19.152-1 (2020-10-18)
configure: error: cannot guess build type; you must specify one
libelf/0.8.13:
libelf/0.8.13: ERROR: Package '67c966a55c91426283f2d35fd8468ed0740478c0' build failed
libelf/0.8.13: WARN: Build folder /root/.conan/data/libelf/0.8.13/_/_/build/67c966a55c91426283f2d35fd8468ed0740478c0
ERROR: libelf/0.8.13: Error in build() method, line 96
        self._build_autotools()
while calling '_build_autotools', line 78
        autotools = self._configure_autotools()
while calling '_configure_autotools', line 74
        self._autotools.configure(configure_dir=self._source_subfolder, args=args)
        ConanException: Error 1 while executing source_subfolder/configure '--enable-shared=no' '--prefix=/root/.conan/data/libelf/0.8.13/_/_/package/67c966a55c91426283f2d35fd8468ed0740478c0' '--bindir=${prefix}/bin' '--sbindir=${prefix}/bin' '--libexecdir=${prefix}/bin' '--libdir=${prefix}/lib' '--includedir=${prefix}/include' '--oldincludedir=${prefix}/include' '--datarootdir=${prefix}/share'
```

</details>

From the log, it seems that the file config.guess is outdated (2004-06-11) which doesn't recognize aarch64.


Discussion:
Have you found any workarounds @QShen3?
@mathsten In my case, the dependence for libelf is introduced by glib. So I just disable it using glib:with_elf=False in conanfile.txt

Resolving patch:
diff --git a/recipes/libelf/all/conanfile.py b/recipes/libelf/all/conanfile.py
--- a/recipes/libelf/all/conanfile.py
+++ b/recipes/libelf/all/conanfile.py
@@ -43,6 +43,7 @@ def configure(self):
     def build_requirements(self):
         if self.settings.os != "Windows":
             self.build_requires("autoconf/2.69")
+            self.build_requires("gnu-config/cci.20201022")
 
     def source(self):
         tools.get(**self.conan_data["sources"][self.version])
@@ -86,6 +87,14 @@ def _package_autotools(self):
         if self.settings.os == "Linux" and self.options.shared:
             os.remove(os.path.join(self.package_folder, "lib", "libelf.a"))
 
+    @property
+    def _user_info_build(self):
+        # If using the experimental feature with different context for host and
+        # build, the 'user_info' attributes of the 'build_requires' packages
+        # will be located into the 'user_info_build' object. In other cases they
+        # will be located into the 'deps_user_info' object.
+        return getattr(self, "user_info_build", None) or self.deps_user_info
+
     def build(self):
         if self.settings.os == "Windows":
             self._build_cmake()
@@ -93,6 +102,12 @@ def build(self):
             tools.replace_in_file(os.path.join(self._source_subfolder, "lib", "Makefile.in"),
                                   "$(LINK_SHLIB)",
                                   "$(LINK_SHLIB) $(LDFLAGS)")
+            # libelf sources contains really outdated 'config.sub' and
+            # 'config.guess' files. It not allows to build libelf for armv8 arch.
+            shutil.copy(self._user_info_build["gnu-config"].CONFIG_SUB,
+                        os.path.join(self._source_subfolder, "config.sub"))
+            shutil.copy(self._user_info_build["gnu-config"].CONFIG_GUESS,
+                        os.path.join(self._source_subfolder, "config.guess"))
             self._build_autotools()
 
     def package(self):


Test patch: