commit 8928e85d80a2eff4f839aa362f6350684863890c Author: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Sun Jan 11 21:24:49 2026 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..253c543 --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +a.out +test.out +.build/ + +*.o +*.d +*~ +*.swp +*.swo +*.bak +*.log + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e39acfc --- /dev/null +++ b/LICENSE @@ -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. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8b4e62c --- /dev/null +++ b/Makefile @@ -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 + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5d7cc3 --- /dev/null +++ b/README.md @@ -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) diff --git a/includes/.gitkeep b/includes/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/sources.mk b/sources.mk new file mode 100644 index 0000000..47b8ad4 --- /dev/null +++ b/sources.mk @@ -0,0 +1,6 @@ + +SRC_DIR = srcs +SRCS = $(SRC_DIR)/main.c + +TESTS_DIR = tests +TESTS= $(TESTS_DIR)/test_main.c diff --git a/srcs/main.c b/srcs/main.c new file mode 100644 index 0000000..d659c45 --- /dev/null +++ b/srcs/main.c @@ -0,0 +1,6 @@ + +int +main() +{ + return 0; +} diff --git a/tests/test_main.c b/tests/test_main.c new file mode 100644 index 0000000..352559c --- /dev/null +++ b/tests/test_main.c @@ -0,0 +1,6 @@ +#include + +Test(dummy, always_pass) +{ + cr_assert(0, "Hello, world!"); +}