Skip to content

Commit b191086

Browse files
committed
lib: posix: Use more fine-grained and orthogonal Kconfig options
Basic requirements: 1. It should be possible to control whether include/posix/ is added to include search path or not. 2. It should be possible to use individual parts of POSIX API, without bringing in everything else. For example, if user is interested in just sleep(), should be possible to enable just that. 3. Keep existing CONFIG_POSIX_API as "master switch", which enables "a lot of POSIX APIs". Fixes: zephyrproject-rtos#12965 Signed-off-by: Paul Sokolovsky <[email protected]>
1 parent 898973b commit b191086

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

lib/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
if(NOT CONFIG_NATIVE_APPLICATION)
22
add_subdirectory(libc)
33
endif()
4-
add_subdirectory_ifdef(CONFIG_POSIX_API posix)
4+
add_subdirectory(posix)
55
add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V1 cmsis_rtos_v1)
66
add_subdirectory_ifdef(CONFIG_CMSIS_RTOS_V2 cmsis_rtos_v2)
77
add_subdirectory(gui)

lib/posix/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11

22
add_library(PTHREAD INTERFACE)
33

4-
target_include_directories(PTHREAD INTERFACE ${ZEPHYR_BASE}/include/posix)
4+
if(CONFIG_POSIX_HEADERS)
5+
zephyr_include_directories(${ZEPHYR_BASE}/include/posix)
6+
endif()
57

68
zephyr_library()
79
zephyr_library_sources(pthread_common.c)
@@ -11,7 +13,7 @@ zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC pthread_barrier.c)
1113
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC pthread.c)
1214
zephyr_library_sources(pthread_sched.c)
1315
zephyr_library_sources(clock.c)
14-
zephyr_library_sources(sleep.c)
16+
zephyr_library_sources_ifdef(CONFIG_POSIX_SLEEP sleep.c)
1517
zephyr_library_sources(timer.c)
1618
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC pthread_rwlock.c)
1719
zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC semaphore.c)

lib/posix/Kconfig

+14-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,24 @@ config POSIX_MAX_FDS
1515
config POSIX_API
1616
depends on !ARCH_POSIX
1717
bool "POSIX APIs"
18+
select POSIX_HEADERS
19+
select POSIX_SLEEP
1820
help
1921
Enable mostly-standards-compliant implementations of
2022
various POSIX (IEEE 1003.1) APIs.
2123

22-
if POSIX_API
24+
config POSIX_HEADERS
25+
bool "Make available POSIX headers"
26+
help
27+
If enabled, applications will be able to include <unistd.h>,
28+
<sys/socket.h> and all other POSIX headers under their native
29+
names. If disabled, all the headers are still available, with
30+
"posix/" prefix, e.g. <posix/unistd.h>.
31+
32+
config POSIX_SLEEP
33+
bool "POSIX sleep()/usleep() calls"
34+
help
35+
Provide sleep()/usleep() calls.
2336

2437
config PTHREAD_IPC
2538
bool "POSIX pthread IPC API"
@@ -95,5 +108,3 @@ config POSIX_MAX_OPEN_FILES
95108
is additionally bounded by CONFIG_POSIX_MAX_FDS.
96109
endif
97110
endif # FILE_SYSTEM
98-
99-
endif # POSIX_API

0 commit comments

Comments
 (0)