From 9e823b7f1d6f1fdf0625e990d7d42920163e03bc Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Fri, 16 May 2014 09:43:01 +0100 Subject: [PATCH] maa_init: fix constructor attribute in maa_init and add working example Signed-off-by: Brendan Le Foll --- api/maa.h | 7 +++++++ examples/analogin_a0.c | 1 - src/CMakeLists.txt | 2 -- src/maa.c | 11 +++++------ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/api/maa.h b/api/maa.h index c6a9bb2..fbd37c4 100644 --- a/api/maa.h +++ b/api/maa.h @@ -174,7 +174,14 @@ typedef struct { * Detects running platform and attempts to use included pinmap * @return maa_result_t maa result */ +#ifndef SWIG +// this sets a compiler attribute (supported by GCC & clang) to have maa_init() +// be called as a constructor make sure your libc supports this! uclibc needs +// to be compiled with UCLIBC_CTOR_DTOR +maa_result_t maa_init() __attribute__((constructor)); +#else maa_result_t maa_init(); +#endif /** Check GPIO * diff --git a/examples/analogin_a0.c b/examples/analogin_a0.c index 010842f..721ff84 100644 --- a/examples/analogin_a0.c +++ b/examples/analogin_a0.c @@ -28,7 +28,6 @@ int main () { - maa_init(); maa_aio_context adc_a0; uint16_t adc_value = 0; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7374c72..89c20c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,8 +73,6 @@ endif () find_package (SWIG) if (SWIG_FOUND) - set (CMAKE_C_FLAGS -DSWIG=${SWIG_FOUND}) - set (CMAKE_CXX_CFLAGS -DSWIG=${SWIG_FOUND}) include (${SWIG_USE_FILE}) add_subdirectory (python) diff --git a/src/maa.c b/src/maa.c index 42e1ea8..822ae94 100644 --- a/src/maa.c +++ b/src/maa.c @@ -39,14 +39,13 @@ maa_get_version() return gVERSION; } -#ifndef SWIG -// this sets a compiler attribute (supported by GCC & clang) to have maa_init() -// be called as a constructor make sure your libc supports this! uclibc needs -// to be compiled with UCLIBC_CTOR_DTOR -maa_result_t maa_init() __attribute__((constructor)); -#endif +#ifdef SWIG maa_result_t maa_init() +#else +maa_result_t __attribute__((constructor)) +maa_init() +#endif { /** Once more board definitions have been added, * A method for detecting them will need to be devised.