2019年3月21日 星期四

在執行期取得目前Makefile腳本檔所在的目錄 Absolute Path of current Makefile 含測試結果


範例程式取得Makefile所在絕對路徑 (Absolute Path of current Makefile)


current_mk_abspathname := $(abspath $(lastword $(MAKEFILE_LIST)))
current_mk_absdir := $(dir $(current_mk_abspathname))
all:
@echo "Makefile absolute pathname: $(current_mk_abspathname)" ; \
echo "Makefile absolute path: $(current_mk_absdir)"

test results on linux


/build$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
/build$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.4 LTS
Release: 16.04
Codename: xenial
/build$ make -f 2019-03-21/01-abspath-mk.mk
Makefile absolute pathname: /build/2019-03-21/01-abspath-mk.mk
Makefile absolute path: /build/2019-03-21/


參考

https://www.systutorials.com/241620/how-to-get-the-full-path-and-directory-of-a-makefile-itself/

沒有留言: