Repository: conan-io/conan-center-index

Issue:
[package] libtool/2.4.6: $pkgauxdir is not a directory
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **libtool/2.4.6**
  * Operating System+version: **Fedora 31**
  * Compiler+version: **GCC 9**
  * Docker image: None
  * Conan version: **conan 1.23.0**
  * Python version: **Python 3.7.6**


### 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=x86_64
arch_build=x86_64
compiler=gcc
compiler.version=9
compiler.libcxx=libstdc++11
build_type=Release
[options]
[build_requires]
[env]
```



### Steps to reproduce (Include if Applicable)
The libalsa package has a  build dependency on libtool which isn't added there yet. So I tried to fix this https://github.com/bincrafters/conan-center-index/commits/libalsa_fixes

Now I'm running into the problem of `libtoolize:   error: $pkgauxdir is not a directory: '/tmp/c3ipr/pr_659_8_0_0/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin/share/libtool/build-aux'`

This is a path from CI so we need to figure out how to fix this


### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
$ conan create . libalsa/1.1.9@
Exporting package recipe
libalsa/1.1.9 exports: File 'conandata.yml' found. Exporting it...
libalsa/1.1.9 exports: Copied 1 '.yml' file: conandata.yml
libalsa/1.1.9: A new conanfile.py version was exported
libalsa/1.1.9: Folder: /home/cr0ydon/.conan/data/libalsa/1.1.9/_/_/export
libalsa/1.1.9: Package recipe modified in export, forcing source folder removal
libalsa/1.1.9: Use the --keep-source, -k option to skip it
libalsa/1.1.9: Exported revision: 3108d661dc680d454911259f43b87241
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=9
os=Linux
os_build=Linux
[options]
[build_requires]
[env]

libalsa/1.1.9: Forced build from source
libalsa/1.1.9 (test package): Installing package
Requirements
    libalsa/1.1.9 from 'conan-center' - Cache
Packages
    libalsa/1.1.9:d48130e0dd76369b1338deb3b2372c5a649f9f2d - Build
Build requirements
    autoconf/2.69 from 'conan-center' - Cache
    automake/1.16.1 from 'conan-center' - Cache
    libtool/2.4.6 from 'conan-center' - Cache
Build requirements packages
    autoconf/2.69:44fcf6b9a7fb86b2586303e3db40189d3b511830 - Cache
    automake/1.16.1:204f43eef24cf786568b45ac828cbce89cc82ac8 - Cache
    libtool/2.4.6:7fdf727710370bcc770868a128f7d1b913367db9 - Cache

Installing (downloading, building) binaries...
autoconf/2.69: Already installed!
autoconf/2.69: Appending PATH env var with : /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin
autoconf/2.69: Setting AC_MACRODIR to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/share/autoconf
autoconf/2.69: Setting AUTOCONF to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/autoconf
autoconf/2.69: Setting AUTORECONF to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/autoreconf
autoconf/2.69: Setting AUTOHEADER to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/autoheader
autoconf/2.69: Setting AUTOM4TE to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/autom4te
autoconf/2.69: Setting AUTOM4TE_PERLLIBDIR to /home/cr0ydon/.conan/data/autoconf/2.69/_/_/package/44fcf6b9a7fb86b2586303e3db40189d3b511830/bin/share/autoconf
automake/1.16.1: Already installed!
automake/1.16.1: Appending PATH env var with : /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin
automake/1.16.1: Setting ACLOCAL to /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin/aclocal
automake/1.16.1: Setting AUTOMAKE_DATADIR to /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin/share
automake/1.16.1: Setting AUTOMAKE_LIBDIR to /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin/share/automake-1.16
automake/1.16.1: Setting AUTOMAKE_PERLLIBDIR to /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin/share/automake-1.16
automake/1.16.1: Setting AUTOMAKE to /home/cr0ydon/.conan/data/automake/1.16.1/_/_/package/204f43eef24cf786568b45ac828cbce89cc82ac8/bin/automake
libtool/2.4.6: Already installed!
libtool/2.4.6: Appending PATH env var with : /home/cr0ydon/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin
libtool/2.4.6: Setting LIBTOOL to /home/cr0ydon/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin/libtool
libtool/2.4.6: Setting LIBTOOLIZE to /home/cr0ydon/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin/libtoolize
libtool/2.4.6: Appending var to ACLOCAL_PATH: /home/cr0ydon/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin/share/aclocal
libalsa/1.1.9: Applying build-requirement: libtool/2.4.6
libalsa/1.1.9: Applying build-requirement: automake/1.16.1
libalsa/1.1.9: Applying build-requirement: autoconf/2.69
libalsa/1.1.9: WARN: Build folder is dirty, removing it: /home/cr0ydon/.conan/data/libalsa/1.1.9/_/_/build/d48130e0dd76369b1338deb3b2372c5a649f9f2d
libalsa/1.1.9: Configuring sources in /home/cr0ydon/.conan/data/libalsa/1.1.9/_/_/source
Downloading v1.1.9.tar.gz completed [761.29k]                                            

libalsa/1.1.9: Copying sources to build folder
libalsa/1.1.9: Building your package in /home/cr0ydon/.conan/data/libalsa/1.1.9/_/_/build/d48130e0dd76369b1338deb3b2372c5a649f9f2d
libalsa/1.1.9: Generator txt created conanbuildinfo.txt
libalsa/1.1.9: Calling build()
libtoolize:   error: $pkgauxdir is not a directory: '/tmp/c3ipr/pr_659_8_0_0/.conan/data/libtool/2.4.6/_/_/package/7fdf727710370bcc770868a128f7d1b913367db9/bin/share/libtool/build-aux'
libalsa/1.1.9: 
libalsa/1.1.9: ERROR: Package 'd48130e0dd76369b1338deb3b2372c5a649f9f2d' build failed
libalsa/1.1.9: WARN: Build folder /home/cr0ydon/.conan/data/libalsa/1.1.9/_/_/build/d48130e0dd76369b1338deb3b2372c5a649f9f2d
ERROR: libalsa/1.1.9: Error in build() method, line 59
        autotools = self._configure_autotools()
while calling '_configure_autotools', line 43
        self.run("libtoolize --force --copy --automake")
        ConanException: Error 1 while executing libtoolize --force --copy --automake
```

</details>



Discussion:

Resolving patch:
diff --git a/recipes/libtool/all/conanfile.py b/recipes/libtool/all/conanfile.py
--- a/recipes/libtool/all/conanfile.py
+++ b/recipes/libtool/all/conanfile.py
@@ -10,6 +10,7 @@ class LibtoolConan(ConanFile):
     description = "GNU libtool is a generic library support script. "
     topics = ("conan", "libtool", "configure", "library", "shared", "static")
     license = ("GPL-2.0-or-later", "GPL-3.0-or-later")
+    exports_sources = "patches/**"
 
     settings = "os_build", "arch_build", "compiler"
     _autotools = None
@@ -38,12 +39,13 @@ def build_requirements(self):
 
     @contextmanager
     def _build_context(self):
-        if self.settings.compiler == "Visual Studio":
-            with tools.vcvars(self.settings):
-                with tools.environment_append({"CC": "cl -nologo", "CXX": "cl -nologo",}):
-                    yield
-        else:
-            yield
+        with tools.environment_append(self._libtool_relocatable_env):
+            if self.settings.compiler == "Visual Studio":
+                with tools.vcvars(self.settings):
+                    with tools.environment_append({"CC": "cl -nologo", "CXX": "cl -nologo",}):
+                        yield
+            else:
+                yield
 
     def _configure_autotools(self):
         if self._autotools:
@@ -57,14 +59,19 @@ def _configure_autotools(self):
         conf_args = [
             "--datarootdir={}".format(datarootdir),
             "--prefix={}".format(prefix),
-            "--disable-shared",
-            "--disable-static",
+            "--enable-shared",
+            "--enable-static",
             "--disable-ltdl-install",
         ]
         self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder)
         return self._autotools
 
+    def _patch_sources(self):
+        for patch in self.conan_data["patches"][self.version]:
+            tools.patch(**patch)
+
     def build(self):
+        self._patch_sources()
         with self._build_context():
             autotools = self._configure_autotools()
             autotools.make()
@@ -90,27 +97,36 @@ def package(self):
     def package_id(self):
         del self.info.settings.compiler
 
+    @property
+    def _libtool_relocatable_env(self):
+        datadir = os.path.join(self.package_folder, "bin", "share")
+        return {
+            "LIBTOOL_PREFIX": tools.unix_path(self.package_folder),
+            "LIBTOOL_DATADIR": tools.unix_path(datadir),
+            "LIBTOOL_PKGAUXDIR": tools.unix_path(os.path.join(datadir, "libtool", "build-aux")),
+            "LIBTOOL_PKGLTDLDIR": tools.unix_path(os.path.join(datadir, "libtool")),
+            "LIBTOOL_ACLOCALDIR": tools.unix_path(os.path.join(datadir, "aclocal")),
+        }
+
     def package_info(self):
         bin_path = os.path.join(self.package_folder, "bin")
-        self.output.info("Appending PATH env var with : {}".format(bin_path))
+        self.output.info("Appending PATH env: {}".format(bin_path))
         self.env_info.PATH.append(bin_path)
 
         bin_ext = ".exe" if self.settings.os_build == "Windows" else ""
 
-        libtool = os.path.join(self.package_folder, "bin", "libtool" + bin_ext)
-        if self.settings.os_build == "Windows":
-            libtool = tools.unix_path(libtool)
-        self.output.info("Setting LIBTOOL to {}".format(libtool))
+        libtool = tools.unix_path(os.path.join(self.package_folder, "bin", "libtool" + bin_ext))
+        self.output.info("Setting LIBTOOL env to {}".format(libtool))
         self.env_info.LIBTOOL = libtool
 
-        libtoolize = os.path.join(self.package_folder, "bin", "libtoolize" + bin_ext)
-        if self.settings.os_build == "Windows":
-            libtoolize = tools.unix_path(libtoolize)
-        self.output.info("Setting LIBTOOLIZE to {}".format(libtoolize))
+        libtoolize = tools.unix_path(os.path.join(self.package_folder, "bin", "libtoolize" + bin_ext))
+        self.output.info("Setting LIBTOOLIZE env to {}".format(libtoolize))
         self.env_info.LIBTOOLIZE = libtoolize
 
-        libtool_aclocal = os.path.join(self.package_folder, "bin", "share", "aclocal" + bin_ext)
-        if self.settings.os_build == "Windows":
-            libtool_aclocal = tools.unix_path(libtool_aclocal)
-        self.output.info("Appending var to ACLOCAL_PATH: {}".format(libtool_aclocal))
+        libtool_aclocal = tools.unix_path(os.path.join(self.package_folder, "bin", "share", "aclocal" + bin_ext))
+        self.output.info("Appending ACLOCAL_PATH env: {}".format(libtool_aclocal))
         self.env_info.ACLOCAL_PATH.append(libtool_aclocal)
+
+        # These are private environment variables so don't output anything
+        for key, value in self._libtool_relocatable_env.items():
+            setattr(self.env_info, key, value)


Test patch: