[英]variable to switch the pre-requisites for a target in a Makefile
我希望使用“MY_TYPE”來切換目標“top”的先決條件。
基於 MY_TYPE 我可以 select 所需的先決條件
例如,對於
MY_TYPE=FOO,我希望 $(BUILD) $(TARGETS) $(X_LOCALS) 作為 top 的先決條件
MY_TYPE=BAR,我希望 $(BUILD) $(TARGETS) $(Y_LOCALS) 作為 top 的先決條件
我怎樣才能實現它?
下面是一個簡單的代碼片段。
BUILD = build
TARGETS = targets
XLOCALS = xlocals
YLOCALS = ylocals
# can be FOO or BAR
MY_TYPE ?= FOO
$(BUILD):
printf "\t Doing Build\n"
$(TARGETS):
printf "\t Doing target\n"
$(XLOCALS):
printf "\t my local build for X \n"
$(YLOCALS):
printf "\t my local build for Y \n"
# based on MY_TYPE Can I select the pre-requisites required
# For example, for
# MY_TYPE=FOO , I wish to have $(BUILD) $(TARGETS) $(X_LOCALS) as pre-requisites for 'top' target
# MY_TYPE=BAR , I wish to have $(BUILD) $(TARGETS) $(Y_LOCALS) as pre-requisites for 'top' target
# How can I achieve it .
top: $(BUILD) $(TARGETS) $(XLOCALS)
printf "\t doing top\n"
很高興接受你的想法。
沒有什么比這更容易了,只需使用條件:
ifeq ($(MY_TYPE),FOO)
top: $(X_LOCALS)
endif
ifeq ($(MY_TYPE),BAR)
top: $(Y_LOCALS)
endif
top: $(BUILD) $(TARGETS)
@echo prereqs are $^
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.