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

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.

Similar Posts

  • MySQL at Facebook

    Facebook uses lots MySQL databases. Any information about how Facebook scales MySQL? Some information on the Web: MySQL at Facebook’s page https://www.facebook.com/MySQLatFacebook?filter=1 A post by Ryan Thiessen, Database Operations at Facebook on Quora: http://www.quora.com/Facebook-Engineering/How-does-Facebook-structure-MySQL-so-that-it-is-robust-and-scalable And more: http://mashable.com/2011/12/15/facebook-timeline-mysql/ http://gigaom.com/2011/12/06/facebook-shares-some-secrets-on-making-mysql-scale/ http://www.wired.com/wiredenterprise/2011/12/facebook-timeline-anatomy “A lot of people are surprised that for this shiny new thing for Facebook, we’re using…

  • How to write a autostart script for gnome

    I want to automatically run a program when I log in gnome. How to write a autorun script for it? Here is one example: $ cat ~/.config/autostart/dropbox.py.desktop [Desktop Entry] Comment[en_US]= Comment= Exec=/home/zma/bin/dropbox.py start GenericName[en_US]= GenericName= Icon=system-run MimeType= Name[en_US]= Name= Path= StartupNotify=true Terminal=false TerminalOptions= Type=Application X-DBUS-ServiceName= X-DBUS-StartupType= X-KDE-SubstituteUID=false X-KDE-Username= To set up a new one, you…

  • Programming language popularity indices?

    Any good programming language popularity indices? Those are interesting ones: TIOBE Indexhttp://www.tiobe.com/index.php/content/paperinfo/tpci/index.html The RedMonk Programming Language Rankings: January 2014 This ranking is published as blog posts. So no persistent homepage found yet. The January 2014 version is: http://redmonk.com/sogrady/2014/01/22/language-rankings-1-14/ Programming Language Popularityhttp://langpop.com/ Read more: Most important aspects or features of the C++ programming language? Are You…

4 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

    1. make files paths : /home/ovsa/krupa/Makefile2/tool
      /home/ovsa/krupa/Makefile2/runtime
      /home/ovsa/krupa/Makefile2/License
      iam running the make in :: make -C ./krupa/Makefile2/License all

      Giving below error:

      make: Entering directory ‘/home/ovsa/krupakar/Makefile2/License’
      mkdir -p /home/ovsa/../License/lib /home/ovsa/../License/bin /home/ovsa/../License/src/lib
      mkdir: cannot create directory ‘/home/ovsa/../License’: Permission denied
      mkdir: cannot create directory ‘/home/ovsa/../License’: Permission denied
      mkdir: cannot create directory ‘/home/ovsa/../License’: Permission denied
      make: *** [Makefile:100: create_dirs] Error 1
      make: Leaving directory ‘/home/ovsa/krupakar/Makefile2/License’

      It is not taking the exact path of the makefile, It is creating the directory in /home

Leave a Reply

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