Common GNU makefile directory path

前端 未结 5 1140
我在风中等你
我在风中等你 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:38

    You should be able to use the MAKEFILE_LIST variable, like this:

    # This must be the first line in Makefile.common
    TOP := $(dir $(firstword $(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.

提交回复
热议问题