In a makefile, how to get the relative path from one absolute path to another?

前端 未结 7 2146
别那么骄傲
别那么骄傲 2021-02-19 20:57

An example to illustrate my question:

Top level makefile

rootdir = $(realpath .)
export includedir = $(rootdir)/include
default:
    @$(MAKE) --directory         


        
7条回答
  •  遇见更好的自我
    2021-02-19 21:23

    Doing what you want does not look easy. It may be possible using a lot of combined $(if in the makefile but not portable (gmake only) and cumbersome.

    IMHO, you are trying to solve a problem that you create yourself. Why don't you send the correct value of includedir as a relative path from the Top-level Makefile? It can be done very easily as follows:

    rootdir = $(realpath .)
    default:
        @$(MAKE) --directory=$(rootdir)/src/libs/libfoo includedir=../../../include
    

    Then you can use $(includedir) in the sub-makefiles. It is already defined as relative.

提交回复
热议问题