Skip to content

Commit 2080577

Browse files
committed
first commit
0 parents  commit 2080577

23 files changed

+813
-0
lines changed

.clang-format

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
TabWidth: 4
4+
UseTab: Never
5+
BreakBeforeBraces: Attach
6+
AllowShortIfStatementsOnASingleLine: false
7+
AllowShortLoopsOnASingleLine: false
8+
AllowShortFunctionsOnASingleLine: Inline
9+
ColumnLimit: 0

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.DS_Store
2+
*.o
3+
.so
4+
*.dylib
5+
build
6+
7+
.vscode/*
8+
!.vscode/c_cpp_properties.json
9+
!.vscode/launch.json
10+
!.vscode/settings.json
11+
!.vscode/tasks.json

.vscode/settings.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"[c]": {
3+
"editor.tabSize": 4,
4+
"editor.insertSpaces": true,
5+
"editor.detectIndentation": true,
6+
"editor.formatOnSave": true,
7+
"editor.defaultFormatter": "ms-vscode.cpptools"
8+
},
9+
"cSpell.words": [
10+
"CMSIS",
11+
"ctest",
12+
"tinyclib"
13+
],
14+
"files.associations": {
15+
".clang-format": "yaml",
16+
}
17+
}

CMakeLists.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
cmake_minimum_required(VERSION 3.25)
2+
3+
project(tinyclib LANGUAGES C)
4+
5+
# Set the output directories for libraries and executables
6+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
7+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
8+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
9+
10+
# Set the C standard to C11 and fallback to C99 if not supported
11+
set(CMAKE_C_STANDARD 11)
12+
set(CMAKE_C_STANDARD_REQUIRED ON)
13+
set(CMAKE_C_EXTENSIONS OFF)
14+
include(CheckCCompilerFlag)
15+
check_c_compiler_flag("-std=c11" COMPILER_SUPPORTS_C11)
16+
if(NOT COMPILER_SUPPORTS_C11)
17+
message(WARNING "C11 is not supported by the compiler. Falling back to C99.")
18+
set(CMAKE_C_STANDARD 99)
19+
endif()
20+
21+
# Add include directories
22+
include_directories(${CMAKE_SOURCE_DIR}/include)
23+
24+
# Source files
25+
set(SOURCES
26+
src/tl_app.c
27+
src/tl_config.c
28+
src/tl_error.c
29+
src/tl_test.c
30+
)
31+
32+
# Header files
33+
set(HEADERS
34+
include/tl_app.h
35+
include/tl_config.h
36+
include/tl_constants.h
37+
include/tl_debug.h
38+
include/tl_error.h
39+
include/tl_test.h
40+
)
41+
42+
# Create a static library
43+
add_library(tinyclib STATIC ${SOURCES} ${HEADERS})
44+
45+
# Fetch dependencies
46+
include(FetchContent)
47+
48+
# Fetch Unity test framework
49+
FetchContent_Declare(
50+
Unity
51+
GIT_REPOSITORY https://github.com/ThrowTheSwitch/Unity.git
52+
GIT_TAG v2.6.1
53+
)
54+
FetchContent_GetProperties(Unity)
55+
if(NOT Unity_POPULATED)
56+
FetchContent_MakeAvailable(Unity)
57+
set(Unity_SOURCE_DIR ${CMAKE_BINARY_DIR}/_deps/unity-src)
58+
if(NOT TARGET Unity)
59+
add_library(Unity STATIC ${Unity_SOURCE_DIR}/src/unity.c)
60+
target_include_directories(Unity PUBLIC ${Unity_SOURCE_DIR}/src)
61+
endif()
62+
endif()
63+
64+
# Build tests
65+
option(BUILD_TESTS "Build tests" ON)
66+
if(BUILD_TESTS)
67+
enable_testing()
68+
69+
include_directories(${unity_SOURCE_DIR}/src)
70+
71+
# Add test executable for tl_app
72+
add_executable(tl_app_test tests/arch/generic/tl_app_test.c)
73+
target_link_libraries(tl_app_test Unity tinyclib)
74+
add_test(NAME tl_app_test COMMAND tl_app_test)
75+
76+
# Add test executable for tl_config
77+
add_executable(tl_config_test tests/arch/generic/tl_config_test.c)
78+
target_link_libraries(tl_config_test Unity tinyclib)
79+
add_test(NAME tl_config_test COMMAND tl_config_test)
80+
81+
# Add test executable for tl_debug
82+
add_executable(tl_debug_test tests/arch/generic/tl_debug_test.c)
83+
target_link_libraries(tl_debug_test Unity tinyclib)
84+
add_test(NAME tl_debug_test COMMAND tl_debug_test)
85+
86+
# Add test executable for tl_error
87+
add_executable(tl_error_test tests/arch/generic/tl_error_test.c)
88+
target_link_libraries(tl_error_test Unity tinyclib)
89+
add_test(NAME tl_error_test COMMAND tl_error_test)
90+
91+
# Add test executable for tl_test
92+
add_executable(tl_test_test tests/arch/generic/tl_test_test.c)
93+
target_link_libraries(tl_test_test Unity tinyclib)
94+
add_test(NAME tl_test_test COMMAND tl_test_test)
95+
endif()

CMakePresets.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 25
6+
},
7+
"configurePresets": [
8+
{
9+
"name": "default",
10+
"generator": "Ninja",
11+
"binaryDir": "${sourceDir}/build",
12+
"cacheVariables": {
13+
"CMAKE_BUILD_TYPE": "Debug",
14+
"BUILD_TESTS": "ON"
15+
}
16+
}
17+
],
18+
"buildPresets": [
19+
{
20+
"name": "default",
21+
"configurePreset": "default",
22+
"jobs": 4
23+
}
24+
],
25+
"testPresets": [
26+
{
27+
"name": "default",
28+
"configurePreset": "default",
29+
"output": {
30+
"outputOnFailure": true
31+
}
32+
}
33+
],
34+
"workflowPresets": [
35+
{
36+
"name": "default",
37+
"steps": [
38+
{
39+
"name": "default",
40+
"type": "configure"
41+
},
42+
{
43+
"name": "default",
44+
"type": "build"
45+
},
46+
{
47+
"name": "default",
48+
"type": "test"
49+
}
50+
]
51+
}
52+
]
53+
}

CONTRIBUTING.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Contributing
2+
3+
- Code contributions must be through pull requests.
4+
- Run tests, linting and formatting before make a pull request.
5+
- Pull requests can not be merged without being reviewed.
6+
- Use "Issues" for bug reports, feature requests, discussions and typos.
7+
- Do not refactor existing code without a discussion.
8+
- Do not add a new third party dependency without a discussion.
9+
- Use semantic versioning and git tags for versioning.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 Fatih Cetinkaya - https://github.com/devfacet/tinyclib
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# tinyclib - A tiny C library
2+
3+
tinyclib is a tiny C library for building applications across various platforms,
4+
from server-grade hardware to desktops, mobile, and embedded devices.
5+
6+
## Requirements
7+
8+
- [Clang](https://clang.llvm.org/) or similar C compiler
9+
- [CMake](https://cmake.org/)
10+
11+
### Recommended tools
12+
13+
- [Visual Studio Code](https://code.visualstudio.com/)
14+
- [C/C++ for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools)
15+
- [CMake Tools for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cmake-tools)
16+
17+
## Installation
18+
19+
```shell
20+
git clone https://github.com/devfacet/tinyclib.git
21+
cd tinyclib/
22+
cmake --workflow --preset default
23+
```
24+
25+
## Usage
26+
27+
## Test
28+
29+
```shell
30+
ctest --preset default
31+
```
32+
33+
## Contributing
34+
35+
See [CONTRIBUTING.md](CONTRIBUTING.md)
36+
37+
## License
38+
39+
Licensed under The MIT License (MIT)
40+
For the full copyright and license information, please view the LICENSE.txt file.

include/tl_app.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// See LICENSE.txt and CONTRIBUTING.md for details.
2+
3+
#ifndef TL_APP_H
4+
#define TL_APP_H
5+
6+
#include <stdbool.h>
7+
8+
/**
9+
* @brief Initializes the running app with the given command line arguments.
10+
*
11+
* @param argc The number of command line arguments.
12+
* @param argv The command line arguments.
13+
*
14+
* @return void
15+
*/
16+
void tl_init_app(int argc, char *argv[]);
17+
18+
/**
19+
* @brief Parses the given command line arguments.
20+
*
21+
* @param argc The number of command line arguments.
22+
* @param argv The command line arguments.
23+
*
24+
* @return void
25+
*/
26+
void tl_parse_args(int argc, char *argv[]);
27+
28+
/**
29+
* @brief Looks up a specific flag.
30+
*
31+
* @param flag The flag to look up.
32+
*
33+
* @return true if the flag is found, false otherwise.
34+
*/
35+
bool tl_lookup_flag(const char *flag);
36+
37+
/**
38+
* @brief Returns the value of a specific flag.
39+
*
40+
* @param flag The flag to get.
41+
*
42+
* @return The value of the flag, or NULL if not found.
43+
*/
44+
const char *tl_get_flag(const char *flag);
45+
46+
#endif // TL_APP_H

include/tl_config.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// See LICENSE.txt and CONTRIBUTING.md for details.
2+
3+
#ifndef TL_CONFIG_H
4+
#define TL_CONFIG_H
5+
6+
#include "tl_error.h"
7+
#include <stdbool.h>
8+
9+
/**
10+
* @brief Defines whether ARM NEON is available.
11+
*
12+
* @note Available for certain ARM architectures.
13+
*/
14+
#if defined(__ARM_NEON) || defined(__ARM_NEON__)
15+
#define TL_NEON_AVAILABLE 1
16+
#else
17+
#define TL_NEON_AVAILABLE 0
18+
#endif
19+
20+
/**
21+
* @brief Defines whether ARM CMSIS-DSP is available.
22+
*
23+
* @note Available for all ARM architectures.
24+
*/
25+
#if defined(__ARM_ARCH)
26+
#define TL_CMSIS_DSP_AVAILABLE 1
27+
#else
28+
#define TL_CMSIS_DSP_AVAILABLE 0
29+
#endif
30+
31+
/**
32+
* @brief Returns the debug level.
33+
*
34+
* @return The debug level.
35+
*/
36+
int tl_get_debug_level();
37+
38+
/**
39+
* @brief Sets the debug level.
40+
*
41+
* @param level The debug level.
42+
*
43+
* @return True or false.
44+
*/
45+
bool tl_set_debug_level(int level);
46+
47+
/**
48+
* @brief Returns whether ARM NEON is available.
49+
*
50+
* @return True or false.
51+
*/
52+
bool tl_neon_available();
53+
54+
/**
55+
* @brief Returns whether ARM CMSIS-DSP is available.
56+
*
57+
* @return True or false.
58+
*/
59+
bool tl_cmsis_dsp_available();
60+
61+
#endif // TL_CONFIG_H

include/tl_constants.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// See LICENSE.txt and CONTRIBUTING.md for details.
2+
3+
#ifndef TL_CONSTANTS_H
4+
#define TL_CONSTANTS_H
5+
6+
/**
7+
* @brief Epsilon value for numerical stability
8+
*/
9+
#define TL_EPSILON 1e-7
10+
11+
#endif // TL_CONSTANTS_H

0 commit comments

Comments
 (0)