2017年8月23日 星期三

Makefile的賦值運算符(=, :=, +=, ?=)

Makefile的賦值運算符(=, :=, +=, ?=)

總結:
= 是最基本的賦值
:= 會覆蓋變數之前的值
?= 變數為空時才給值,不然則維持之前的值
+= 將值附加到變數的後面

另外 =, :=這兩賦值運算符號在網路上查詢,常常會看到這種說法:
= 在執行時擴展(values within it are recursively expanded when the variable is used, not when it's declared)
:= 在定義時擴展(values within it are expanded at declaration time)
而白話一點的說法如下範例所示

  1. =
  make會將整個makefile展開後,才決定變數的值。也就是说,變數的值會是整個Makefile中最後被指定的值。看例子:

x = hello
y = $(x) world!
x = hi

all:
@echo $(y)

  在上例中,輸出結果將會是 hi world! ,而不是 hello world!

  2. :=
  變數的值在Makefile展開途中就會被給定,而不是整個Makefile展開後的最终值。

x := hello
y := $(x) world!
x := hi

all:
@echo $(y)

  輸出結果 ====> hello world!

2 則留言:

  1. Awesome post
    In the Shortest period of time to visit and feel the freshness of Taj Mahal You can choose a option of
    Same Day Jaipur Tour By Car. In 12 hours tour of Agra from Delhi which covered 3 World UNESCO and historical monuments of Agra which is Taj Mahal, Agra Fort And Baby Taj ( Itimad-ud-daulah).
    We have more packages like...
    Same Day Jaipur Tour By Train
    Same Day Agra Tour By Train
    Golden Triangle Tour 3 Night And 4 Days

    回覆刪除
  2. WOW Great Post! Really a wonderful post. Thanks for posting such an informative & useful post with us. keep posting & inspire us like this post.

    You Can Visit India’s Hot Tourist Destinations On Same Day. If You Are Short Of Time And Want To Travel To India For A Day Or Two Then Our Day Trips Is Best Option For You. Golden Triangle Tours India). You know the beauty of monuments in Delhi, Agra, Jaipur. More...

    Same Day Agra Tour by Car
    4 Days Golden Triangle Tour
    Golden Triangle Tour 6 Days
    Same Day Agra Tour By Train

    Discover Amazing India
    +91-8266881111
    info@discoveramazingindia.com
    http://www.discoveramazingindia.com

    回覆刪除