From fcefaf88abbd1e6bbc7ddefabf07ddecaeafbe54 Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Thu, 10 Jun 2010 16:53:05 -0700 Subject: [PATCH] Add a sample to demonstrate module exports in the NDK. + add .gitignore Change-Id: Ifa160316e37cf201099ab0d8d89fdd375ee3eb59 --- ndk/.gitignore | 6 ++++++ ndk/samples/module-exports/README.TXT | 9 +++++++++ ndk/samples/module-exports/jni/Android.mk | 23 +++++++++++++++++++++++ ndk/samples/module-exports/jni/bar/bar.c | 6 ++++++ ndk/samples/module-exports/jni/bar/bar.h | 15 +++++++++++++++ ndk/samples/module-exports/jni/foo/foo.c | 20 ++++++++++++++++++++ ndk/samples/module-exports/jni/foo/foo.h | 6 ++++++ ndk/samples/module-exports/jni/zoo/zoo.c | 6 ++++++ 8 files changed, 91 insertions(+) create mode 100644 ndk/.gitignore create mode 100644 ndk/samples/module-exports/README.TXT create mode 100644 ndk/samples/module-exports/jni/Android.mk create mode 100644 ndk/samples/module-exports/jni/bar/bar.c create mode 100644 ndk/samples/module-exports/jni/bar/bar.h create mode 100644 ndk/samples/module-exports/jni/foo/foo.c create mode 100644 ndk/samples/module-exports/jni/foo/foo.h create mode 100644 ndk/samples/module-exports/jni/zoo/zoo.c diff --git a/ndk/.gitignore b/ndk/.gitignore new file mode 100644 index 00000000..48a8878a --- /dev/null +++ b/ndk/.gitignore @@ -0,0 +1,6 @@ +samples/*/libs/ +samples/*/obj/ +samples/*/bin/ +samples/*/gen/ +local.properties +build.xml diff --git a/ndk/samples/module-exports/README.TXT b/ndk/samples/module-exports/README.TXT new file mode 100644 index 00000000..abd6c989 --- /dev/null +++ b/ndk/samples/module-exports/README.TXT @@ -0,0 +1,9 @@ +This sample is used to demonstrate the usage of module exports +(i.e. LOCAL_EXPORT_CFLAGS and similar other variables). + +Here, three modules are defined: foo, bar, zoo + +'foo' exports its include directory and a linker flag +bar simply uses 'foo', as a static library +zoo uses bar, is a shared library. + diff --git a/ndk/samples/module-exports/jni/Android.mk b/ndk/samples/module-exports/jni/Android.mk new file mode 100644 index 00000000..a4b594de --- /dev/null +++ b/ndk/samples/module-exports/jni/Android.mk @@ -0,0 +1,23 @@ +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := foo +LOCAL_SRC_FILES := foo/foo.c +LOCAL_CFLAGS := -DFOO=2 +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo +LOCAL_EXPORT_CFLAGS := -DFOO=1 +LOCAL_EXPORT_LDLIBS := -llog +include $(BUILD_STATIC_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := bar +LOCAL_SRC_FILES := bar/bar.c +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar +LOCAL_STATIC_LIBRARIES := foo +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := zoo +LOCAL_SRC_FILES := zoo/zoo.c +LOCAL_SHARED_LIBRARIES := bar +include $(BUILD_SHARED_LIBRARY) diff --git a/ndk/samples/module-exports/jni/bar/bar.c b/ndk/samples/module-exports/jni/bar/bar.c new file mode 100644 index 00000000..71b21d21 --- /dev/null +++ b/ndk/samples/module-exports/jni/bar/bar.c @@ -0,0 +1,6 @@ +#include "bar.h" + +int bar(int x) +{ + return foo(x)-1; +} diff --git a/ndk/samples/module-exports/jni/bar/bar.h b/ndk/samples/module-exports/jni/bar/bar.h new file mode 100644 index 00000000..a01f5f72 --- /dev/null +++ b/ndk/samples/module-exports/jni/bar/bar.h @@ -0,0 +1,15 @@ +#ifndef BAR_H +#define BAR_H + +/* FOO should be defined to '1' here with the magic of LOCAL_EXPORT_CFLAGS */ +#ifndef FOO +#error FOO should be defined here ! +#endif + +#if FOO != 1 +#error FOO is not correctly defined here ! +#endif + +extern int bar(int x); + +#endif /* BAR_H */ diff --git a/ndk/samples/module-exports/jni/foo/foo.c b/ndk/samples/module-exports/jni/foo/foo.c new file mode 100644 index 00000000..71e85953 --- /dev/null +++ b/ndk/samples/module-exports/jni/foo/foo.c @@ -0,0 +1,20 @@ +#include "foo.h" +#include + +/* FOO should be defined to '2' when building foo.c */ +#ifndef FOO +#error FOO is not defined here ! +#endif + +#if FOO != 2 +#error FOO is incorrectly defined here ! +#endif + +#define LOG_TAG "libfoo" +#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) + +int foo(int x) +{ + LOGI("foo(%d) called !", x); + return x+1; +} diff --git a/ndk/samples/module-exports/jni/foo/foo.h b/ndk/samples/module-exports/jni/foo/foo.h new file mode 100644 index 00000000..e061d106 --- /dev/null +++ b/ndk/samples/module-exports/jni/foo/foo.h @@ -0,0 +1,6 @@ +#ifndef FOO_H +#define FOO_H + +extern int foo(int x); + +#endif /* FOO_H */ diff --git a/ndk/samples/module-exports/jni/zoo/zoo.c b/ndk/samples/module-exports/jni/zoo/zoo.c new file mode 100644 index 00000000..24e72090 --- /dev/null +++ b/ndk/samples/module-exports/jni/zoo/zoo.c @@ -0,0 +1,6 @@ +#include "bar.h" + +int something(void) +{ + return bar(42); +} -- 2.11.0