I'm trying to generate Android.mk files automatically for an existing build environment. This environment has many libraries linking to each other and also possibly linking to 3rd party libs (like boost).
Let's say I have libA using boost.
My goal being to build both libA and libB by running ndk-build from libB folder.
So I generate this Android.mk for libA:
LOCAL_PATH := $(call my-dir)
# Import boost
include $(CLEAR_VARS)
LOCAL_MODULE    := boost_atomic
LOCAL_SRC_FILES := ../dev/libcpp/boost/1.60.1/lib/libboost_atomic.a
include $(PREBUILT_STATIC_LIBRARY)
# libA:
include $(CLEAR_VARS)
LOCAL_MODULE    := libA
LOCAL_SRC_FILES := libA.cpp
LOCAL_C_INCLUDES := ../dev/libcpp/boost/1.60.1
# boost import:
LOCAL_CPPFLAGS += -DHAVE_CONFIG_H -fexceptions -frtti
LOCAL_STATIC_LIBRARIES += boost_atomic
# build libA:
include $(BUILD_SHARED_LIBRARY)
Now I have libB using both boost and libA. libB's Android.mk is very similar to libA's except I added the import of libA file as below: 
# Import libA
include $(CLEAR_VARS)
LOCAL_MODULE := libA
include ../../libA/jni/Android.mk
When I try to make libB, I'm being reported:
Android NDK: Trying to define local module 'boost_atomic' in ../../libA/jni/Android.mk.
Android NDK: But this module was already defined by ../../libA/jni/Android.mk.
B:/Android/android-ndk-r11b/build//../build/core/build-module.mk:34: *** Android
 NDK: Aborting.    .  Stop.
Is there a way for me to check if boost_atomic is already defined (like if (exists boost_atomic)) to make sure it gets defined once only? Or should I suffix all the names (ending up with boost_system_for_libA and boost_system_for_libB) to prevent the conflict? Or any other alternative?
 
     
    