簡體   English   中英

在編譯時訪問 Makefile 變量 shell

[英]Accessing Makefile variable in compile time shell

我有一個 makefile, 1.mk,內容如下:

#!make

aa := x
bb := y
cc := z

export
include abc.mk

all:
    @echo $(chk1)

另一個makefile,abc.mk,內容如下:

#!make

chk1 := $(shell set -o posix; set | awk -F "=" 'BEGIN{ORS=" "}1 $$1~/[a-zA-Z_][a-zA-Z0-9_]*/ {print $$1}')
chk2 := $(shell env &> pqr)

export

當我檢查時,沒有一個具有 makefile 變量:

> make all -f 1.mk | grep aa

> grep 'aa' pqr

因此我可以說,編譯時 shell 沒有 makefile 變量。 我想要一種在編譯時 shell 中訪問所有 makefile 變量的方法。

約束:我事先不知道變量名以下列方式編寫代碼:

chk2 := $(shell export aa=$(aa); env &> pqr)

據我了解 make exports 生成變量的方式,它只在配方中這樣做,而不是在用shell function 調用的 shell 中這樣做。您可以使用例如:

$ cat Makefile
aa := x
export
chk := $(shell echo $$aa)

.PHONY: all

all:
    @printf 'in shell function: aa = $(chk)\n'
    @printf 'in recipe:         aa = %s\n' "$$aa"

$ make
in shell function: aa = 
in recipe:         aa = x

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM