add format to make
This commit is contained in:
parent
0a5bbd0161
commit
756ceebed5
7
Makefile
7
Makefile
@ -32,4 +32,9 @@ re:
|
||||
$(MAKE) -C $$ex re; \
|
||||
done
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
format:
|
||||
for ex in $(EX); do \
|
||||
$(MAKE) -C $$ex format; \
|
||||
done
|
||||
|
||||
.PHONY: all clean fclean re format
|
||||
17
common.mk
17
common.mk
@ -16,6 +16,8 @@ SRC = $(notdir $(wildcard src/*.cpp))
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
CC = c++
|
||||
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)
|
||||
|
||||
@ -36,4 +38,17 @@ fclean: clean
|
||||
|
||||
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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user