Skip to content

Instantly share code, notes, and snippets.

@bbl
Created June 13, 2020 12:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bbl/5429c4a0a498c5ef91c10201e1b651c2 to your computer and use it in GitHub Desktop.
Save bbl/5429c4a0a498c5ef91c10201e1b651c2 to your computer and use it in GitHub Desktop.
Get Makefile root directory absolute path
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
test:
@echo $(ROOT_DIR)
@spometun
Copy link

thank you

@chriscz
Copy link

chriscz commented Sep 13, 2023

Ditto! My requirement was slightly different. I have a structure like this

repository/
  tool1/
    Makefile@ -> ../tool.makefile
  tool2/
    Makefile@ -> ../tool.makefile
  tool.makefile

In other words, my tool makefiles are symlinks to the main makefile. In this case the above code always resolves to the repository path.

But changing it to:

ROOT_DIR:=$(realpath $(shell dirname $(firstword $(MAKEFILE_LIST))))

test:
  @echo $(ROOT_DIR)

resolved this resolution issue for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment