在添加到依赖项之前,check变量为空

时间:2016-03-18 08:02:38

标签: makefile gnu-make

来自AOSP build / core / Makefile

的代码

如果有人将INSTALLED_RAMDISK_TARGET设置为空(意外),那么recoveryimage将没有RAMDISK

如何检查每个依赖项是否为空? 或者还有其他建议吗?

1016 $(INSTALLED_RECOVERYIMAGE_TARGET): $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
1017         $(INSTALLED_RAMDISK_TARGET) \
1018         $(INSTALLED_BOOTIMAGE_TARGET) \
1019         $(INTERNAL_RECOVERYIMAGE_FILES) \
1020         $(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
1021         $(INSTALLED_2NDBOOTLOADER_TARGET) \
1022         $(recovery_build_prop) $(recovery_resource_deps) \
1023         $(recovery_fstab) \
1024         $(RECOVERY_INSTALL_OTA_KEYS)
1025         $(call build-recoveryimage-target, $@)

我尝试了下面的方法,但是徒劳,因为foreach会跳过变量,这是空的

1016 RECOVERYIMAGE_REQUIRED := $(MKBOOTFS) $(MKBOOTIMG) $(MINIGZIP) \
1017         $(INSTALLED_RAMDISK_TARGET) \
1018         $(INSTALLED_BOOTIMAGE_TARGET) \
1019         $(INTERNAL_RECOVERYIMAGE_FILES) \
1020         $(recovery_initrc) $(recovery_sepolicy) $(recovery_kernel) \
1021         $(INSTALLED_2NDBOOTLOADER_TARGET) \
1022         $(recovery_build_prop) $(recovery_resource_deps) \
1023         $(recovery_fstab) \
1024         $(RECOVERY_INSTALL_OTA_KEYS)
1025         $(call build-recoveryimage-target, $@)
1026 $(foreach item,$(HOSDIMAGE_REQUIRED), \
1027    $(eval _item := $(strip $(item))) \
1028    $(if $(_item),$(info $(_item) checked),$(error dependency is empty)) \                                                                                                                               
1029    )
1030 $(INSTALLED_RECOVERYIMAGE_TARGET): $(RECOVERYIMAGE_REQUIRED)

2 个答案:

答案 0 :(得分:2)

哦,我希望--error-undefined-variables能够匹配现有的--warn-undefined-variables。与此同时,您可以使用以下内容:

depvarnames := \
  MKBOOTFS \
  MKBOOTIMG \
  MINIGZIP \
  ⋮

deps := $(foreach _,${depvarnames},$(or $_,$(error $$$_ is empty!)))

${INSTALLED_RECOVERYIMAGE_TARGET}: ${deps}
    recipe
    ⋮

答案 1 :(得分:0)

下面是我的解决方案,看起来很愚蠢,但它确实对我很有帮助

NULL :=
SPACE := $(NULL) $(NULL)
DQUOTE = " 

RECOVERYIMAGE_REQUIRED := \
               "$(MKBOOTFS)" \
               "$(MKBOOTIMG)" \
               "$(MINIGZIP)" \
               "$(PRODUCT_OUT)/ramdisk.img" \
               "$(PRODUCT_OUT)/boot.img" \
               "$(rec_initrc)" \
               "$(rec_kernel)" \
               "$(rec_build_prop)" \
               "$(rec_resource_deps)" \
               "$(rec_fstab)"

$(foreach item, $(RECOVERYIMAGE_REQUIRED), \
    $(eval _item := $(strip $(item))) \
    $(if $(filter "", $(_item)),$(error dependency is empty),) \
)

RECOVERYIMAGE_OPTIONAL := \
               "$(INSTALLED_2NDBOOTLOADER_TARGET)" \

$(foreach item, $(RECOVERYIMAGE_REQUIRED) $(RECOVERYIMAGE_OPTIONAL), \
    $(if $(strip $(subst $(DQUOTE),$(SPACE),$(item))), \
         $(eval RECOVERYIMAGE_FINAL_LIST += $(strip $(subst $(DQUOTE),$(SPACE),$(item)))), \
    ) \ 
)

$(INSTALLED_RECOVERYIMAGE_TARGET): $(RECOVERYIMAGE_FINAL_LIST)