3

When I run sudo make install on a compiled package from the GNU archive, it uses mkdir -p to create the destination directories.

I'd prefer it to use mkdir -p -m 0755 or install -d -m 0755 instead in order to ensure the destination directory has proper permissions for everyone under all circumstances, not just when the umask for root is 0022 (which isn't true for me).

The package is using autoconf/automake and it looks like the behaviour is controlled by an M4 macro called AC_PROG_MKDIR_P.

At the moment I can run sudo chmod 0755 on the directories I know have wrong permissions. But this isn't clearly the right option.

I'd avoid to study the whole documentation in order to accomplish "just that".

Any hint?

8

The macro AC_PROG_MKDIR_P is a feature test macro. It expands to shell code that tests for the best mkdir -p-capable command available. It uses MKDIR_P and ac_cv_path_mkdir (a "cache variable") to figure out what command to use.

You may set the value of MKDIR_P to the command that you want to use for creating directories. The command that you use must be able to create not only a single directory but also the parent directories if these are not already existing (just like mkdir -p does).

Normal:

$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/local/bin/gmkdir -p
checking for gawk... gawk
...

With MKDIR_P set:

$ ./configure MKDIR_P='install -d -m 0755'
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... install -d -m 0755
checking for gawk... gawk
...

According to the documentation, one should be able to make this "permanent" by setting the cache variable ac_cv_path_mkdir to the wanted command. This variable can be set directly in the configure script (ugly) or by modifying the created config.cache file after running configure with the -C option once. However, I've found that configure adds a -p option to the value of this command which may not be wanted (the meaning of this option is different between mkdir and install).

If you're happy with re-generating the configure script from its configure.ac source, you may set MKDIR_P to a value just after the call to AC_INIT. Then run autoconf (or autoreconf) to recreate configure.

The most flexible way would be to set the MKDIR_P environment variable in the current shell session with export MKDIR_P='install -d' (or whatever you need). This would not require modifying any files, but would affect all configure scripts that you run in that shell session.

  • It works, indeed. Is there a way to make this choice "permanent" within the ./configure script? – EnzoR Apr 7 '18 at 6:59
  • @Enzo See my updated answer. – Kusalananda Apr 7 '18 at 7:14
  • I think the proper way is the one you hint with "If you're happy with re-generating the configure script...". But it's not clear to me whether MKDIR_P="mkdir -m 0755" is enough. – EnzoR Apr 7 '18 at 15:15
  • 1
    I just added that line (MKDIR_P="mkdir -m 0755") and did the who run. IT WORKS. THANKS. – EnzoR Apr 7 '18 at 15:59
  • 1
    @Enzo Good! You may want to add -p to that though. You will want it to create missing intermediate directories too. – Kusalananda Apr 7 '18 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.