add format to make

This commit is contained in:
whaffman 2026-03-27 18:31:28 +01:00
parent 0a5bbd0161
commit 756ceebed5
2 changed files with 22 additions and 2 deletions

View File

@ -32,4 +32,9 @@ re:
$(MAKE) -C $$ex re; \ $(MAKE) -C $$ex re; \
done done
.PHONY: all clean fclean re format:
for ex in $(EX); do \
$(MAKE) -C $$ex format; \
done
.PHONY: all clean fclean re format

View File

@ -16,6 +16,8 @@ SRC = $(notdir $(wildcard src/*.cpp))
OBJ = $(SRC:.cpp=.o) OBJ = $(SRC:.cpp=.o)
CC = c++ CC = c++
CFLAGS = -Wall -Wextra -Werror -std=c++11 CFLAGS = -Wall -Wextra -Werror -std=c++11
FORMATTER = clang-format
FORMAT_FILES = $(wildcard src/*.[ch] src/*.[ch]pp inc/*.[ch] inc/*.[ch]pp)
all: $(NAME) all: $(NAME)
@ -36,4 +38,17 @@ fclean: clean
re: fclean all re: fclean all
.PHONY: all clean fclean re run format:
@if command -v $(FORMATTER) >/dev/null 2>&1; then \
if [ -n "$(FORMAT_FILES)" ]; then \
$(FORMATTER) -i --style=file $(FORMAT_FILES); \
printf "Formatted %s\n" "$(NAME)"; \
else \
printf "No files to format in %s\n" "$(NAME)"; \
fi; \
else \
printf "clang-format not found. Please install clang-format.\n"; \
exit 1; \
fi
.PHONY: all clean fclean re run format