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:
parent
7faebbd425
commit
85fe229de0
@ -642,6 +642,21 @@ maintaining duplicate logic in the NuttX repository.
|
|||||||
This is a simple test of the board LED driver at
|
This is a simple test of the board LED driver at
|
||||||
`nuttx/drivers/leds/userled_*.c`.
|
`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
|
## `luamod_hello` Hello World Lua module
|
||||||
|
|
||||||
A Lua C module showing how to add built-in modules to the Lua interpreter.
|
A Lua C module showing how to add built-in modules to the Lua interpreter.
|
||||||
|
37
examples/libtest/Kconfig
Normal file
37
examples/libtest/Kconfig
Normal 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
|
25
examples/libtest/Make.defs
Normal file
25
examples/libtest/Make.defs
Normal 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
35
examples/libtest/Makefile
Normal 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
|
39
examples/libtest/libtest.c
Normal file
39
examples/libtest/libtest.c
Normal 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");
|
||||||
|
}
|
30
examples/libtest/libtest.h
Normal file
30
examples/libtest/libtest.h
Normal 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 */
|
41
examples/libtest/libtest_main.c
Normal file
41
examples/libtest/libtest_main.c
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user