| 1 | # Copyright (C) PlayControl Software, LLC. |
| 2 | # Eric Wing <ewing . public @ playcontrol.net> |
| 3 | # |
| 4 | # This is a "Prebuilt" Android Makefile provided as an example/template (or direct use if no tweaking is required). |
| 5 | # The idea is that you have already built the chipmunk .so and .a libraries using CMake. |
| 6 | # Now you want to use those prebuilt libraries in your own project. |
| 7 | # Android support prebuilt exteneral modules through its ndk-build system, but you need to have all the pieces setup and in the right place. This is one of those pieces. |
| 8 | # |
| 9 | # This file assumes you built all your chipmunk libs and put things into a directory structure like so: |
| 10 | # |
| 11 | # Android.mk (this file) |
| 12 | # libs/armeabi/libchipmunk.a |
| 13 | # libs/armeabi/libchipmunk.a |
| 14 | # libs/armeabi-v7a/libchipmunk.a |
| 15 | # libs/armeabi-v7a/libchipmunk.a |
| 16 | # libs/x86/libchipmunk.a |
| 17 | # libs/x86/libchipmunk.a |
| 18 | # |
| 19 | # include/chipmunk/chipmunk.h |
| 20 | # ... (the other header files here) |
| 21 | # |
| 22 | # Note that this file is copied into the directory above libs and include. |
| 23 | # Below is the code you need to make this Makefile export the correct headers, libraries, and flags for both dynamic and static versions. |
| 24 | |
| 25 | # LOCAL_PATH needs to be before include |
| 26 | LOCAL_PATH := $(call my-dir) |
| 27 | |
| 28 | # For the dynamic library |
| 29 | include $(CLEAR_VARS) |
| 30 | # This is the name of module the caller will use in LOCAL_SHARED_LIBRARIES |
| 31 | LOCAL_MODULE := chipmunk_shared |
| 32 | LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libchipmunk.so |
| 33 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/chipmunk |
| 34 | # Use LOCAL_EXPORT_CFLAGS to automatically export the correct flags (as necessary) to the calling module so the caller doesn't need to know the details. |
| 35 | #LOCAL_EXPORT_CFLAGS := -DFOO=1 -DCP_USE_DOUBLES=1 -DCP_USE_CGPOINTS=0 |
| 36 | # The .so is already linked so we don't really need to export this. |
| 37 | #LOCAL_EXPORT_LDLIBS := -lm |
| 38 | include $(PREBUILT_SHARED_LIBRARY) |
| 39 | |
| 40 | # For the static library |
| 41 | include $(CLEAR_VARS) |
| 42 | # This is the name of module the caller will use in LOCAL_STATIC_LIBRARIES |
| 43 | LOCAL_MODULE := chipmunk_static |
| 44 | LOCAL_SRC_FILES := libs/$(TARGET_ARCH_ABI)/libchipmunk.a |
| 45 | # Use LOCAL_EXPORT_CFLAGS to automatically export the correct flags (as necessary) to the calling module so the caller doesn't need to know the details. |
| 46 | #LOCAL_EXPORT_CFLAGS := -DFOO=1 -DCP_USE_DOUBLES=1 -DCP_USE_CGPOINTS=0 |
| 47 | # Since the .a isn't linked, it's link dependencies must be passed on to the calling project. |
| 48 | LOCAL_EXPORT_LDLIBS := -lm |
| 49 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include/chipmunk |
| 50 | include $(PREBUILT_STATIC_LIBRARY) |
| 51 | |
| 52 | |
| 53 | |
| 54 | # Two other pieces are needed to make this work which fall outside the scope of this file. |
| 55 | # First, you must have a directory convention for the calling makefile. |
| 56 | # So let's say we put all the above in a directory called Chipmunk2D. The layout looks like this: |
| 57 | # Chipmunk2D/ |
| 58 | # Android.mk (this file) |
| 59 | # libs/armeabi/libchipmunk.a |
| 60 | # libs/armeabi/libchipmunk.a |
| 61 | # libs/armeabi-v7a/libchipmunk.a |
| 62 | # libs/armeabi-v7a/libchipmunk.a |
| 63 | # libs/x86/libchipmunk.a |
| 64 | # libs/x86/libchipmunk.a |
| 65 | # |
| 66 | # include/chipmunk/chipmunk.h |
| 67 | # ... (the other header files here) |
| 68 | |
| 69 | # So the calling makefile looks something like: |
| 70 | # LOCAL_PATH := $(call my-dir) |
| 71 | # include $(CLEAR_VARS) |
| 72 | # LOCAL_MODULE := hello-jni |
| 73 | # LOCAL_SRC_FILES := hello-jni.c |
| 74 | # These are the LOCAL_MODULE names as defined in the prebuilt module's Android.mk. Define either shared or static, but not both. If you use dynamic, don't forget you need to do a System.loadLibrary("chipmunk") in your Java code. |
| 75 | # #LOCAL_SHARED_LIBRARIES := chipmunk_shared |
| 76 | # LOCAL_STATIC_LIBRARIES := chipmunk_static |
| 77 | # include $(BUILD_SHARED_LIBRARY) |
| 78 | # Android build system will look for folder `Chipmunk2D` in all import paths: |
| 79 | # $(call import-module,Chipmunk2D) |
| 80 | # ------ end ----- |
| 81 | |
| 82 | # Second, you need to set the environmental variable NDK_MODULE_PATH to list the directory containing Chipmunk2D. |
| 83 | # So if Chipmunk2D is in /Library/Frameworks/Android/PrebuiltModules |
| 84 | # export NDK_MODULE_PATH=/Library/Frameworks/Android/PrebuiltModules |
| 85 | # Note that NDK_MODULE_PATH may contain multiple directories like the PATH environmental variable. |
| 86 |