Common GNU makefile directory path?

You should be able to use the MAKEFILE_LIST variable like this.

You should be able to use the MAKEFILE_LIST variable, like this: # This must be the first this in Makefile. Common TOP := $(dir $(lastword $(MAKEFILE_LIST))) From the documentation: As make reads various makefiles, including any obtained from the MAKEFILES variable, the command line, the default files, or from include directives, their names will be automatically appended to the MAKEFILE_LIST variable. They are added right before make begins to parse them.

This means that if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile. Once the current makefile has used include, however, the last word will be the just-included makefile.

This worked wonderfully on my dev box, but I realized the target machine was running make 3.79, and the MAKEFILE_LIST feature was added in make 3.80: mail-archive.com/help-make@gnu.org/msg05902.html – cdleary Dec 12 '08 at 1:52 1 It seems MAKEFILE_LIST doesn't contain full paths, only relative paths. – kbyrd Feb 11 '10 at 14:31.

Have you tried doing: # Makefile. Common TOP? = $(shell pwd) COMPONENT_DIR := $(TOP)/component COMPONENT_INC := $(COMPONENT_DIR)/include COMPONENT_LIB := $(COMPONENT_DIR)/libcomponent.

A # other_component/Makefile TOP? = .. include ../Makefile. Common Using the?

= construct will keep TOP from being redefined if it is already set. You can set it to the appropriate value based on where you are in the tree when you invoke make. I confess it's been awhile since I've used GNU make so this may not work or may need some tweaks.

Agreed, that would work. I'm hoping there's a way to do it that doesn't require preparation on the part of the makefile (other than inclusion), but that's certainly a good fallback. – cdleary Nov 27 '08 at 4:53.

This isn't good style because it adds another dependency (i.e. The realpath binary). Depending on your use case, that may be acceptable.

ROOT_DIR = $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) If you don't have realpath installed: $ sudo apt-get install realpath # on debian and derivatives.

I should note that this builds on JesperE's example form above. However, it provides an absolute path to build on top of. – Bill Mar 30 '10 at 19:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions