Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When distributing a custom utility I'll typically write a makefile that installs binaries to /usr/local by default

PREFIX ?= /usr/local

    install utility ${PREFIX}/bin/
    install utility.1 ${MANPREFIX}/man1/

The path to local binaries is fairly standard across different platforms, but the man path is not

  • Linux: /usr/local/share/man or /usr/local/man
  • MacOS - /usr/local/share/man
  • BSD: /usr/local/man

Is there a portable way to write this makefile? It seems unreasonable to expect users to set MANPREFIX to the correct path before installing.


BSD make support assignment of a shell command using !=, which could be used to test if a path exists

SHARE != [ -d ${PREFIX}/share/man ] && echo /share || true

This is a new feature for GNU make, so it's likely not portable yet. This works in GNU make, but not BSD make:

MANPREFIX ?= $(shell [ -d ${PREFIX}/share/man ] && echo ${PREFIX}/share/man || echo ${PREFIX}/man)
share|improve this question

The textbook answer is to use autoconf. Finding the right installation directories on every platform is part of its job.

Autoconf isn't perfect, but it's often better than reinventing the wheel.

share|improve this answer
What about utilities that require no compilation step, like a collection of scripts? Would you still suggest using a Makefile in that case? – Jorge Bucaran Oct 14 '15 at 1:50
@JorgeBucaran You may want to have an install target even if there's no build step, and you probably have test targets anyway. If you don't test, you might not have a makefile (or equivalent) at all and rely only on packaging-specific scripts (debian/rules, RPM specs, BSD ports, etc.). – Gilles Oct 14 '15 at 11:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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