问题
I'm building a bucnh of libraries using ndk-build. At some point, a mk file could be included twice, as it imports 3rd party libraries, I protected double-import using a global variable:
# Importing nlopt!
# Prevent warnings reporting module was imported twice:
ifneq ($(imported_nlopt_$(TARGET_ARCH_ABI)),true)
imported_nlopt_$(TARGET_ARCH_ABI) := true
ifeq ($(APP_OPTIM),debug)
# Importing static library nlopt_debug:
include $(CLEAR_VARS)
LOCAL_MODULE := nlopt_debug
LOCAL_SRC_FILES := nlopt/nlopt-2.4.2/lib/$(PLATFORM)/$(COMPILER)/Debug/$(LIB_PREFIX)nlopt$(DEBUG_INFIX)$(DYNAMIC_LINK_EXT)
include $(PREBUILT_SHARED_LIBRARY)
else
# Importing static library nlopt_release:
include $(CLEAR_VARS)
LOCAL_MODULE := nlopt_release
LOCAL_SRC_FILES := nlopt/nlopt-2.4.2/lib/$(PLATFORM)/$(COMPILER)/Release/$(LIB_PREFIX)nlopt$(DYNAMIC_LINK_EXT)
include $(PREBUILT_SHARED_LIBRARY)
endif
else
$(info "NLOPT already imported!")
endif
I need to do this in many place and it starts anoying me to have the whole file being in an if statement.
Are "early returns" supported in makefiles? Could I do something like:
ifeq ($(imported_nlopt_$(TARGET_ARCH_ABI)),true)
return
endif
imported_nlopt_$(TARGET_ARCH_ABI) := true
...
return is not recognized when I execute this.
回答1:
Luckily in Android.mk it is enough to protect only the statement include $(BUILD_SHARED_LIBRARY), etc
来源:https://stackoverflow.com/questions/40173692/android-makefiles-how-to-early-return