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

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

    The shell has this feature using realpath(1) and the --relative-to flag so you could just invoke the shell.

    Here is an example:

    RELATIVE_FILE1_FILE2:=$(shell realpath --relative-to $(FILE1) $(FILE2))

    You can even process a whole list of files with one invocation of realpath(1) since it knows how to process many file names.

    Here is an example:

    RELATIVES:=$(shell realpath --relative-to $(RELATIVE) $(FILES))

提交回复
热议问题