Add a sample to demonstrate module exports in the NDK.

+ add .gitignore

Change-Id: Ifa160316e37cf201099ab0d8d89fdd375ee3eb59
This commit is contained in:
David 'Digit' Turner
2010-06-10 16:53:05 -07:00
parent d616e8b214
commit fcefaf88ab
8 changed files with 91 additions and 0 deletions

6
ndk/.gitignore vendored Normal file
View File

@@ -0,0 +1,6 @@
samples/*/libs/
samples/*/obj/
samples/*/bin/
samples/*/gen/
local.properties
build.xml

View 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.

View 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)

View File

@@ -0,0 +1,6 @@
#include "bar.h"
int bar(int x)
{
return foo(x)-1;
}

View 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 */

View 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;
}

View File

@@ -0,0 +1,6 @@
#ifndef FOO_H
#define FOO_H
extern int foo(int x);
#endif /* FOO_H */

View File

@@ -0,0 +1,6 @@
#include "bar.h"
int something(void)
{
return bar(42);
}