From e1636d05ab281495511fef58ea1ec7776464bd0b Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 10 Jul 2024 14:52:08 +0900 Subject: [PATCH 1/2] Add an alternative way to override LFS_MALLOC etc With the existing method, (-DLFS_MALLOC=my_malloc) users often had to use compiler options like -include, which was not so portable. This change introduces another way to provide partial overrides of lfs_util.h using a user-provided header. --- lfs_util.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lfs_util.h b/lfs_util.h index 4e577009..91b740ef 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -8,6 +8,9 @@ #ifndef LFS_UTIL_H #define LFS_UTIL_H +#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x) +#define LFS_STRINGIZE2(x) #x + // Users can override lfs_util.h with their own configuration by defining // LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h). // @@ -15,11 +18,26 @@ // provided by the config file. To start, I would suggest copying lfs_util.h // and modifying as needed. #ifdef LFS_CONFIG -#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x) -#define LFS_STRINGIZE2(x) #x #include LFS_STRINGIZE(LFS_CONFIG) #else +// Alternatively, users can provide a header file which defines +// macros and other things consumed by littlefs. +// +// For example, provide my_defines.h, which contains +// something like: +// +// #include +// extern void *my_malloc(size_t sz); +// #define LFS_MALLOC(sz) my_malloc(sz) +// +// And build littlefs with the header by defining LFS_USER_DEFINES. +// (-DLFS_USER_DEFINES=my_defines.h) + +#ifdef LFS_USER_DEFINES +#include LFS_STRINGIZE(LFS_USER_DEFINES) +#endif + // System includes #include #include From 4a845be0beccda3d9872eb4935f471e2eb245553 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 18 Sep 2024 15:17:17 +0900 Subject: [PATCH 2/2] Rename LFS_USER_DEFINES to LFS_DEFINES --- lfs_util.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lfs_util.h b/lfs_util.h index 91b740ef..0aec4885 100644 --- a/lfs_util.h +++ b/lfs_util.h @@ -31,11 +31,11 @@ // extern void *my_malloc(size_t sz); // #define LFS_MALLOC(sz) my_malloc(sz) // -// And build littlefs with the header by defining LFS_USER_DEFINES. -// (-DLFS_USER_DEFINES=my_defines.h) +// And build littlefs with the header by defining LFS_DEFINES. +// (-DLFS_DEFINES=my_defines.h) -#ifdef LFS_USER_DEFINES -#include LFS_STRINGIZE(LFS_USER_DEFINES) +#ifdef LFS_DEFINES +#include LFS_STRINGIZE(LFS_DEFINES) #endif // System includes