Repository: conan-io/conan

Issue:
[build system] AutoToolsBuildEnvironment on linux distros with default "lib64" libdir
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

On some linux distributions (for example, suse & derivatives), the default libdir for installations is "lib64" on x64 systems, rather than "lib". This prevents nearly every package that uses AutoToolsBuildEnvironment and tools.collect_libs(), because they mostly assume the directory for libraries is "lib". 

This could be fixed in many cases, for example, by adding the "--libdir" flag  with an appropriate value to "./configure", when we call AutoToolsBuildEnvironment.configure(). I realise this might be controversial, since it might break existing packages that _do_ assume "/lib64" directory. However, my experience in installing conan packages is that essentially none of them currently do this, and I have to patch in the "lib64" directory to the folder= argument in tools.collect_libs on most recipes I use that use autotools.

Note the similar problem doesn't occur in (most) cmake build systems because we do pass -DCMAKE_INSTALL_LIBDIR=lib to the cmake configuration command. So in the spirit of that behaviour, I would see doing it for autotools as well to be simply a matter of consistency.


Discussion:
But if the library directory is `lib64`, you should add it to the `self.cpp_info.libdirs`. So you could explicitly call `tools.collect_libs(folder="lib64")` too. Right?
you are correct, of course, but at present this means modifying just about every conan recipe which uses AutoTools when there isn't a pre-built package for my system. In comparison, even though this otherwise would _also_ happen with the cmake generator, it doesn't, because conan goes to great pains to set up all the relevant cmake variables.

Note: the exact same buildsystem (same compiler, same arch) will produce library directory "lib" on a debian system, but "lib64" on suse.
I see. I don't know exactly what can we do without breaking behavior but we will think about it.
I take the point, but I have so far not found a single recipe that _does_ work. 
And note that this would only break behaviour in the case where the recipe has only used tools.collect_libs(folder="lib64"), without _also_ collecting them in "lib", so in fact it only breaks behaviour in the case where the recipe already didn't work on the vast majority of distros in use (debian, ubuntu...). Well actually not strictly true, one could have done something like:

   lib_str = "lib64" if distro_uses_lib64() else "lib"

and this would break those recipes. Perhaps it would be better instead to provide more functionality in the linux distro specific tools of conan? I.e. being able to get this information from conan without having to hard code it all the time...
But this is not only a `collect_libs` issue, right? If the package is built in some distros the lib folder would be different, so the package won't declare correctly where the libraries are located, even without `collect_libs`.
I think I haven't expressed my intent clearly here: I am asking if we can make the AutotoolsBuildEnvironment pass the flags to autotools such that it outputs libraries into the "lib" dir, even on platforms where it otherwise would use "lib64". Thus, collect_libs wouldn't need to be altered.  There is no difference in the built package, the change is happening at package build time.

It's not that pre-built packages would change at all, it would just enable recipes to be build on platforems which use "lib64" without modification of the recipe.

Resolving patch:
diff --git a/conans/client/build/autotools_environment.py b/conans/client/build/autotools_environment.py
--- a/conans/client/build/autotools_environment.py
+++ b/conans/client/build/autotools_environment.py
@@ -147,6 +147,9 @@ def configure(self, configure_dir=None, args=None, build=None, host=None, target
             elif not any(["--prefix=" in arg for arg in args]):
                 args.append("--prefix=%s" % self._conanfile.package_folder.replace("\\", "/"))
 
+            if not any(["--libdir=" in arg for arg in args]):
+                args.append("--libdir=${prefix}/lib")
+
         with environment_append(pkg_env):
             with environment_append(vars or self.vars):
                 configure_dir = self._adjust_path(configure_dir)


Test patch:
diff --git a/conans/test/build_helpers/autotools_configure_test.py b/conans/test/build_helpers/autotools_configure_test.py
--- a/conans/test/build_helpers/autotools_configure_test.py
+++ b/conans/test/build_helpers/autotools_configure_test.py
@@ -493,28 +493,43 @@ def test_make_targets_install(self):
         ab.install()
         self.assertEquals(runner.command_called, "make install -j%s" % cpu_count())
 
-    def autotools_prefix_test(self):
+    def autotools_prefix_libdir_test(self):
         runner = RunnerMock()
         conanfile = MockConanfile(MockSettings({}), None, runner)
         # Package folder is not defined
         ab = AutoToolsBuildEnvironment(conanfile)
         ab.configure()
         self.assertNotIn("--prefix", runner.command_called)
+        self.assertNotIn("--libdir", runner.command_called)
         # package folder defined
         conanfile.package_folder = "/package_folder"
         ab.configure()
         if platform.system() == "Windows":
-            self.assertIn("./configure --prefix=/package_folder", runner.command_called)
+            self.assertIn("./configure --prefix=/package_folder --libdir=${prefix}/lib",
+                          runner.command_called)
         else:
-            self.assertIn("./configure '--prefix=/package_folder'", runner.command_called)
+            self.assertIn("./configure '--prefix=/package_folder' '--libdir=${prefix}/lib'",
+                          runner.command_called)
         # --prefix already used in args
         ab.configure(args=["--prefix=/my_package_folder"])
         if platform.system() == "Windows":
-            self.assertIn("./configure --prefix=/my_package_folder", runner.command_called)
+            self.assertIn("./configure --prefix=/my_package_folder --libdir=${prefix}/lib",
+                          runner.command_called)
             self.assertNotIn("--prefix=/package_folder", runner.command_called)
         else:
-            self.assertIn("./configure '--prefix=/my_package_folder'", runner.command_called)
+            self.assertIn("./configure '--prefix=/my_package_folder' '--libdir=${prefix}/lib'",
+                          runner.command_called)
             self.assertNotIn("'--prefix=/package_folder'", runner.command_called)
+        # --libdir already used in args
+        ab.configure(args=["--libdir=/my_package_folder/superlibdir"])
+        if platform.system() == "Windows":
+            self.assertIn("./configure --libdir=/my_package_folder/superlibdir "
+                          "--prefix=/package_folder", runner.command_called)
+            self.assertNotIn("--libdir=${prefix}/lib", runner.command_called)
+        else:
+            self.assertIn("./configure '--libdir=/my_package_folder/superlibdir' "
+                          "'--prefix=/package_folder'", runner.command_called)
+            self.assertNotIn("'--libdir=${prefix}/lib'", runner.command_called)
 
     def autotools_configure_vars_test(self):
         from mock import patch