In a Makefile do we use 'prefix' or 'PREFIX'?
Asked Answered
V

1

6

Currently in my Makefile I have:

prefix ?= /usr/local

So that I can override prefix value when calling make, like in the following:

make prefix="/new_path"

My question is: does a convention exist for naming this variable inside a Makefile, especially do I have to call it prefix or PREFIX?

This matter since lower or upper case matters in this situation!

Note that I do not use autotools, just a "simple" Makefile

Via answered 31/3, 2015 at 10:54 Comment(4)
I don't know if there's a definitive answer. My own preference is to use all caps when the variable is something that I document as being overridable by the user and to use lower case when it's something internal that's not to be messed with.Brezhnev
@noufal Thanks for the explanation. So I will make use in my case of PREFIX (since can be overridden). It's a pitty that i've not found a doc about these convention (even if they are not totally fixed)...Via
That's what I'd do but it's really my own convention.Brezhnev
Wow, I'm astonished this 5+ years old question still doesn't have a definite answer.Enrapture
S
7

The variables for installation directories section of the GNU make manual discusses prefix.

I believe the autotools use a similarly-cased prefix variable/configure flag.

Compare to DESTDIR however.

Spitz answered 31/3, 2015 at 11:39 Comment(2)
@ethan thanks for the doc but I already read it without any clue about my specific concern...Via
The prevailing consensus (between GNU make and the autotools) is to use prefix. I added the bit about DESTDIR just to indicate that they do also use ALL_CAP variables and I don't know why specifically. In the absence of a consensus on PREFIX somewhere else (bsd, etc.) this would seem to indicate that you should use prefix. Which is why I posted the information. I can't give a more concrete/definitive answer than that.Spitz

© 2022 - 2024 — McMap. All rights reserved.