This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 85fe229de apps/libtest: add libtest demo
85fe229de is described below

commit 85fe229de0ad803de5a64a6907d5c14f92337fd7
Author: chao.an <anc...@xiaomi.com>
AuthorDate: Wed Dec 16 11:34:04 2020 +0800

    apps/libtest: add libtest demo
    
    Redefine the name of BIN to support static library:
    
    BIN = $(APPDIR)/libtest$(LIBEXT)
    
    Signed-off-by: chao.an <anc...@xiaomi.com>
---
 examples/README.md              | 15 +++++++++++++++
 examples/libtest/Kconfig        | 37 +++++++++++++++++++++++++++++++++++++
 examples/libtest/Make.defs      | 25 +++++++++++++++++++++++++
 examples/libtest/Makefile       | 35 +++++++++++++++++++++++++++++++++++
 examples/libtest/libtest.c      | 39 +++++++++++++++++++++++++++++++++++++++
 examples/libtest/libtest.h      | 30 ++++++++++++++++++++++++++++++
 examples/libtest/libtest_main.c | 41 +++++++++++++++++++++++++++++++++++++++++
 7 files changed, 222 insertions(+)

diff --git a/examples/README.md b/examples/README.md
index 66beee97d..ed91792be 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -642,6 +642,21 @@ maintaining duplicate logic in the NuttX repository.
 This is a simple test of the board LED driver at
 `nuttx/drivers/leds/userled_*.c`.
 
+## `libtest` Static Library Test
+
+This example illustrates how you may create a static library. It does the 
following:
+
+It creates a static library called libtest.a that contains an object that 
provides the symbol library_test().
+
+At adds the library as an EXTRA_LIB in the build
+
+EXTRA_LIBS += -ltest
+E XTRA_LIBPATHS += -L$(APPDIR)/examples/libtest
+
+And optionally, it can be configured to:
+
+Generate a built-in command that can be executed by NSH. This command logic 
links with the symbol library_test() that will provided by the libtest.a static 
library.
+
 ## `luamod_hello` Hello World Lua module
 
 A Lua C module showing how to add built-in modules to the Lua interpreter.
diff --git a/examples/libtest/Kconfig b/examples/libtest/Kconfig
new file mode 100644
index 000000000..3a16ffc2b
--- /dev/null
+++ b/examples/libtest/Kconfig
@@ -0,0 +1,37 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_LIBTEST
+       bool "Static library Example"
+       default n
+       ---help---
+               Enable the static library example
+
+if EXAMPLES_LIBTEST
+
+config EXAMPLES_LIBTEST_CMDTOOL
+       tristate "Static library Command Line Tool"
+       default n
+       ---help---
+               By default, static library example is build as only a library.
+               If this option is selected than a simple command line tool that
+               can be ran from NSH will also be generated.
+
+config EXAMPLES_LIBTEST_PROGNAME
+       string "Static library program name"
+       default "libtest"
+       ---help---
+               This is the name of the program that will be used when the NSH 
ELF
+               program is installed.
+
+config EXAMPLES_LIBTEST_PRIORITY
+       int "Static library task priority"
+       default 100
+
+config EXAMPLES_LIBTEST_STACKSIZE
+       int "Static library stack size"
+       default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/libtest/Make.defs b/examples/libtest/Make.defs
new file mode 100644
index 000000000..a76fbef7c
--- /dev/null
+++ b/examples/libtest/Make.defs
@@ -0,0 +1,25 @@
+############################################################################
+# apps/examples/libtest/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################/
+
+ifneq ($(CONFIG_EXAMPLES_LIBTEST),)
+EXTRA_LIBS += -ltest
+EXTRA_LIBPATHS += -L$(APPDIR)/examples/libtest
+CONFIGURED_APPS += $(APPDIR)/examples/libtest
+endif
diff --git a/examples/libtest/Makefile b/examples/libtest/Makefile
new file mode 100644
index 000000000..95606815e
--- /dev/null
+++ b/examples/libtest/Makefile
@@ -0,0 +1,35 @@
+############################################################################
+# apps/examples/libtest/Makefile
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################/
+
+
+include $(APPDIR)/Make.defs
+
+BIN   = libtest$(LIBEXT)
+CSRCS = libtest.c
+
+ifneq ($(CONFIG_EXAMPLES_LIBTEST_CMDTOOL),)
+  PROGNAME  = $(CONFIG_EXAMPLES_LIBTEST_PROGNAME)
+  PRIORITY  = $(CONFIG_EXAMPLES_LIBTEST_PRIORITY)
+  STACKSIZE = $(CONFIG_EXAMPLES_LIBTEST_STACKSIZE)
+  MODULE    = $(CONFIG_EXAMPLES_LIBTEST_CMDTOOL)
+  MAINSRC   = libtest_main.c
+endif
+
+include $(APPDIR)/Application.mk
diff --git a/examples/libtest/libtest.c b/examples/libtest/libtest.c
new file mode 100644
index 000000000..d9d3670b7
--- /dev/null
+++ b/examples/libtest/libtest.c
@@ -0,0 +1,39 @@
+/****************************************************************************
+ * apps/examples/libtest/libtest.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdio.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * library_test
+ ****************************************************************************/
+
+void library_test(void)
+{
+  printf("Hello, Library!!\n");
+}
diff --git a/examples/libtest/libtest.h b/examples/libtest/libtest.h
new file mode 100644
index 000000000..59f7d2acf
--- /dev/null
+++ b/examples/libtest/libtest.h
@@ -0,0 +1,30 @@
+/****************************************************************************
+ * apps/examples/libtest/libtest.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __APPS_EXAMPLES_LIBTEST_LIBTEST_H
+#define __APPS_EXAMPLES_LIBTEST_LIBTEST_H
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+void library_test(void);
+
+#endif /* __APPS_EXAMPLES_LIBTEST_LIBTEST_H */
diff --git a/examples/libtest/libtest_main.c b/examples/libtest/libtest_main.c
new file mode 100644
index 000000000..25b30b5a3
--- /dev/null
+++ b/examples/libtest/libtest_main.c
@@ -0,0 +1,41 @@
+/****************************************************************************
+ * apps/examples/libtest/libtest_main.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdio.h>
+#include "libtest.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * main
+ ****************************************************************************/
+
+int main(int argc, FAR char *argv[])
+{
+  library_test();
+  return 0;
+}

Reply via email to