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

前端 未结 7 2086
别那么骄傲
别那么骄傲 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:29

    Python is portable! So, I would suggest you this simple example in your submakefile

    With current_dir and destination_dir paths os.path.relpath() does the job for you so you do not have to re-invent the wheel.

    submakefile.mk

    current_dir=$(CURDIR)
    makefile_target:
        (echo "import os"; echo "print(os.path.relpath('$(destination_dir)', '$(current_dir)'))" )| python
    

提交回复
热议问题