Initial commit
This commit is contained in:
commit
8928e85d80
8 changed files with 151 additions and 0 deletions
12
.gitignore
vendored
Normal file
12
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
a.out
|
||||
test.out
|
||||
.build/
|
||||
|
||||
*.o
|
||||
*.d
|
||||
*~
|
||||
*.swp
|
||||
*.swo
|
||||
*.bak
|
||||
*.log
|
||||
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 lohhiiccc
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
54
Makefile
Normal file
54
Makefile
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
NAME = a.out
|
||||
TEST_BIN= test.out
|
||||
|
||||
.DEFAULT_GOAL := all
|
||||
MAKEFLAGS += --no-print-directory
|
||||
include sources.mk
|
||||
|
||||
CC = clang
|
||||
CPPFLAGS = -std=c99 -I includes
|
||||
CFLAGS = -Wall -Wextra -Werror -pipe
|
||||
LDFLAGS = -lcriterion
|
||||
|
||||
|
||||
OBJ_DIR = .build
|
||||
|
||||
OBJS = $(SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
||||
.PHONY: all
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MP -c $< -o $@
|
||||
|
||||
-include $(DEPS)
|
||||
|
||||
|
||||
.PHONY: test
|
||||
test: $(TEST_BIN)
|
||||
./$(TEST_BIN)
|
||||
|
||||
$(TEST_BIN): $(TESTS) $(filter %.o,$(OBJS))
|
||||
@mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ -o $@
|
||||
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
$(RM) -r $(OBJ_DIR)
|
||||
|
||||
.PHONY: fclean
|
||||
fclean: clean
|
||||
$(RM) $(NAME)
|
||||
$(RM) $(TEST_BIN)
|
||||
|
||||
.PHONY: re
|
||||
re: fclean
|
||||
$(MAKE) all
|
||||
|
||||
46
README.md
Normal file
46
README.md
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# c-template
|
||||
|
||||
A minimal, clean, and reusable C project template with unit testing support
|
||||
(Criterion), portable Makefile, and clear directory organization.
|
||||
|
||||
## Features
|
||||
|
||||
- Modern portable Makefile (with dependency management)
|
||||
- Example source and header structure (`srcs/`, `includes/`)
|
||||
- Unit test setup using [Criterion](https://github.com/Snaipe/Criterion)
|
||||
- Ready-to-use targets: `all`, `clean`, `fclean`, `re`, `test`
|
||||
- Easily extensible for larger C projects
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Requirements
|
||||
|
||||
- A C compiler (GCC or Clang recommended)
|
||||
- [Criterion](https://github.com/Snaipe/Criterion) for unit tests
|
||||
|
||||
### Build and Run
|
||||
|
||||
```sh
|
||||
make # Build the main binary
|
||||
make test # Build and run unit tests
|
||||
make clean # Remove object files
|
||||
make fclean # Full clean (object files + binaries)
|
||||
make re # Full rebuild
|
||||
```
|
||||
|
||||
Edit `sources.mk` to add your source and test files as the project grows.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
.
|
||||
├── includes/ # Header files
|
||||
├── srcs/ # Source files
|
||||
├── tests/ # Unit test sources
|
||||
├── Makefile
|
||||
├── sources.mk
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
0
includes/.gitkeep
Normal file
0
includes/.gitkeep
Normal file
6
sources.mk
Normal file
6
sources.mk
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
SRC_DIR = srcs
|
||||
SRCS = $(SRC_DIR)/main.c
|
||||
|
||||
TESTS_DIR = tests
|
||||
TESTS= $(TESTS_DIR)/test_main.c
|
||||
6
srcs/main.c
Normal file
6
srcs/main.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
int
|
||||
main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
6
tests/test_main.c
Normal file
6
tests/test_main.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <criterion/criterion.h>
|
||||
|
||||
Test(dummy, always_pass)
|
||||
{
|
||||
cr_assert(0, "Hello, world!");
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue