Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

PREFIX ?= /usr/local
MANPREFIX ?= ${PREFIX}/man

install:
    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.

EDIT:

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
MANPREFIX ?= ${PREFIX}${SHARE}/man

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

1 Answer 1

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

Your Answer

 
discard

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.