How to get the full path and directory of a Makefile itself?

Posted on

How to get the full path and directory of a Makefile itself like finding Bash script’s own path?

This 2 lines in Makefile get the full path and dir of the Makefile itself:

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

The piece of code gets you Makefile, finds its absolute path and the directory. It does not rely on your work directory at all.

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

3 comments

  1. how to get the files list included by a Makefile?
    For example:
    TOP?=/vobs
    include $(TOP)/util/mak/compiler.mk
    and compiler.mk may also include other files.
    How to get the all included file list?

    thanks

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts