make distcheck -> Error – install: cannot change ownership

[versione italiana]
When you work with GNU software, in 90% of the cases you’re using GNU Autoconf and GNU Automake in order to handle the build process of your software. In some rare case you need to change the group and ownership of a file that you need to install on the system. In this case you just add an install hook in your Makefile.am and call install in this way:

fooDATA_INSTALL = ${INSTALL} -g foogroup -o foouser

This is wonderfull when you have to install your data as root user but it’s a cause of error when you test your package as normal user calling make distcheck.
The result of the above command will be a make error caused by install trying to change ownership of your files without the root permissions:
install: cannot change ownership

What can you do for checking your package?

Well, GNU Automake and GNU Autoconf will come in your help also for this. GNU Automake ships the install-sh file that could be used instead of the GNU Coreutils install program for installing files on your system. Looking at the usage help of this script you can see that there are some environment variables that could be specified to change the behaviour of the script. We now will focus on two of them: CHGRPPROG and CHOWNPROG. Setting these two variables to something that didn’t fail as normal user like “echo” allow us to call install-sh -g foogroup -o foouser without any failure (and without actually change the ownership of the file).

How do you tell Makefile.am that we want to use install-sh instead of install?

Just with another environment variable: INSTALL. If you export INSTALL="path/to/install-sh" and the run configure, in your Makefile will be used install-sh instead of install. If you call make install as root user you can install your files just as if you’re using the install program, but now you can also call make distcheck as normal user for testing your package: just remember to export CHGRPPROG=echo and CHOWNPROG=echo before you execute the test and unset them when you finished.
Good work with your package!