Add a sample to demonstrate module exports in the NDK.
+ add .gitignore Change-Id: Ifa160316e37cf201099ab0d8d89fdd375ee3eb59
This commit is contained in:
6
ndk/.gitignore
vendored
Normal file
6
ndk/.gitignore
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
samples/*/libs/
|
||||
samples/*/obj/
|
||||
samples/*/bin/
|
||||
samples/*/gen/
|
||||
local.properties
|
||||
build.xml
|
||||
9
ndk/samples/module-exports/README.TXT
Normal file
9
ndk/samples/module-exports/README.TXT
Normal file
@@ -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.
|
||||
|
||||
23
ndk/samples/module-exports/jni/Android.mk
Normal file
23
ndk/samples/module-exports/jni/Android.mk
Normal file
@@ -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)
|
||||
6
ndk/samples/module-exports/jni/bar/bar.c
Normal file
6
ndk/samples/module-exports/jni/bar/bar.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "bar.h"
|
||||
|
||||
int bar(int x)
|
||||
{
|
||||
return foo(x)-1;
|
||||
}
|
||||
15
ndk/samples/module-exports/jni/bar/bar.h
Normal file
15
ndk/samples/module-exports/jni/bar/bar.h
Normal file
@@ -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 */
|
||||
20
ndk/samples/module-exports/jni/foo/foo.c
Normal file
20
ndk/samples/module-exports/jni/foo/foo.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "foo.h"
|
||||
#include <android/log.h>
|
||||
|
||||
/* 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;
|
||||
}
|
||||
6
ndk/samples/module-exports/jni/foo/foo.h
Normal file
6
ndk/samples/module-exports/jni/foo/foo.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef FOO_H
|
||||
#define FOO_H
|
||||
|
||||
extern int foo(int x);
|
||||
|
||||
#endif /* FOO_H */
|
||||
6
ndk/samples/module-exports/jni/zoo/zoo.c
Normal file
6
ndk/samples/module-exports/jni/zoo/zoo.c
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "bar.h"
|
||||
|
||||
int something(void)
|
||||
{
|
||||
return bar(42);
|
||||
}
|
||||
Reference in New Issue
Block a user