Repository: bitcoin/bitcoin (language: cpp)

Issue:
Can't copy to 'build-aux/config.guess' in autoconf.sh: Permission denied
https://github.com/bitcoin/bitcoin/issues/26422 broke the `autogen.sh` part of my development builds on NixOS - found #26422 by bisecting. The error is:

```
$ ./autogen.sh
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build-aux/m4'.
libtoolize: copying file 'build-aux/m4/libtool.m4'
libtoolize: copying file 'build-aux/m4/ltoptions.m4'
libtoolize: copying file 'build-aux/m4/ltsugar.m4'
libtoolize: copying file 'build-aux/m4/ltversion.m4'
libtoolize: copying file 'build-aux/m4/lt~obsolete.m4'
configure.ac:37: installing 'build-aux/compile'
configure.ac:27: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'build-aux/m4'.
libtoolize: copying file 'build-aux/m4/libtool.m4'
libtoolize: copying file 'build-aux/m4/ltoptions.m4'
libtoolize: copying file 'build-aux/m4/ltsugar.m4'
libtoolize: copying file 'build-aux/m4/ltversion.m4'
libtoolize: copying file 'build-aux/m4/lt~obsolete.m4'
configure.ac:122: installing 'build-aux/compile'
configure.ac:58: installing 'build-aux/missing'
src/Makefile.am: installing 'build-aux/depcomp'
cp: cannot create regular file 'build-aux/config.guess': Permission denied
```

_Originally posted by @0xB10C in https://github.com/bitcoin/bitcoin/issues/26422#issuecomment-1589094552_
            


Discussion / hints:
https://github.com/bitcoin/bitcoin/blob/8de9bb7a5ab04669369e2bb59ea92a5c1a91a8d2/autogen.sh#L18 evaluates to true for me. The `depends/config.guess` file has a timestamp of `2023-01-01` while the generated `build-aux/config.guess` file has a timestamp of `2021-06-03`. 

The generated `build-aux/config.guess` file has the file permissions `-r-xr-xr-x` so overwriting it fails.

```
$ autoreconf --version
autoreconf (GNU Autoconf) 2.71

$ libtool --version
libtool (GNU libtool) 2.4.7

$ libtoolize --version
libtoolize (GNU libtool) 2.4.7
```
> The generated `build-aux/config.guess` file has the file permissions `-r-xr-xr-x` so overwriting it fails.

`autoreconf --install --force --warnings=all` copies from the nix-store (in this case `/nix/store/3bvdlza5sxy6kjs9y7v0kbx4gxgp0wg8-autoconf-2.71/share/autoconf/build-aux/config.guess`) to `build-aux/config.guess`. The file has `-r-xr-xr-x` permissions in the nix-store. These permissions are preserved when copying. So the problem is a combination of how the nix-store works, how `autoreconf` copies the files and us trying to overwrite them.

Fix patch:
diff --git a/autogen.sh b/autogen.sh
index d0ac7ef7ed3f1..69c892ffa0e72 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -16,10 +16,14 @@ command -v autoreconf >/dev/null || \
 autoreconf --install --force --warnings=all
 
 if expr "'$(build-aux/config.guess --timestamp)" \< "'$(depends/config.guess --timestamp)" > /dev/null; then
+  chmod ug+w build-aux/config.guess
+  chmod ug+w src/secp256k1/build-aux/config.guess
   cp depends/config.guess build-aux
   cp depends/config.guess src/secp256k1/build-aux
 fi
 if expr "'$(build-aux/config.sub --timestamp)" \< "'$(depends/config.sub --timestamp)" > /dev/null; then
+  chmod ug+w build-aux/config.sub
+  chmod ug+w src/secp256k1/build-aux/config.sub
   cp depends/config.sub build-aux
   cp depends/config.sub src/secp256k1/build-aux
 fi


Test patch: