apps/libtest: add libtest demo

Redefine the name of BIN to support static library:

BIN = $(APPDIR)/libtest$(LIBEXT)

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-12-16 11:34:04 +08:00 committed by patacongo
parent 7faebbd425
commit 85fe229de0
7 changed files with 222 additions and 0 deletions

View File

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

37
examples/libtest/Kconfig Normal file
View File

@ -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

View File

@ -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

35
examples/libtest/Makefile Normal file
View File

@ -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

View File

@ -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");
}

View File

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

View File

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