Common GNU makefile directory path

前端 未结 5 1144
我在风中等你
我在风中等你 2020-12-01 00:19

I\'m trying to consolidate some build information by using a common makefile. My problem is that I want to use that makefile from different subdirectory levels, which makes

5条回答
  •  不知归路
    2020-12-01 00:27

    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
    

    Edit: Be sure to use := instead of = because the latter causes make to use late-binding and MAKEFILE_LIST may have changed due to later includes.

提交回复
热议问题