From 8f2d83871b68287cfed08710e4759d858b4fd00a Mon Sep 17 00:00:00 2001 From: asus Date: Tue, 23 Jan 2024 14:42:44 +0100 Subject: [PATCH] creation common makefile --- 1_Colleen/Makefile | 131 +----------------------------------------- 1_Colleen/tmp_Colleen | 14 ----- 2_Grace/Makefile | 112 +----------------------------------- Makefile | 1 + MakefileCommon | 108 ++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 251 deletions(-) delete mode 100644 1_Colleen/tmp_Colleen create mode 100644 MakefileCommon diff --git a/1_Colleen/Makefile b/1_Colleen/Makefile index cb73354..264d4d3 100644 --- a/1_Colleen/Makefile +++ b/1_Colleen/Makefile @@ -1,130 +1,5 @@ -# - - - - - - # -# # -# COLORS # -# # -# - - - - - - # -GRAY = "\e[0;30m" -RED = "\e[0;31m" -GREEN = "\e[0;32m" -YELLOW = "\e[0;33m" -BLUE = "\e[0;34m" -PURPLE = "\e[0;35m" -CYAN = "\e[0;36m" -WHITE = "\e[0;37m" - -B_GRAY = "\e[1;30m" -B_RED = "\e[1;31m" -B_GREEN = "\e[1;32m" -B_YELLOW = "\e[1;33m" -B_BLUE = "\e[1;34m" -B_PURPLE = "\e[1;35m" -B_CYAN = "\e[1;36m" -B_WHITE = "\e[1;37m" - -RESET = "\e[0m" - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . name = value \ . += append to a variable # -# VARIABLES . value . != set result of command # -# . name is case sensitive . ?= set if not already set # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - -NAME = Colleen - -CC = clang -EXT = c - -CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -CFLAGS += -g3 - -VPATH = $(D_SRCS) - -LIBS = - -F_INCLUDES = $(HEADERS:%=$(D_HEADERS)/%) -INCLUDES = -I$(D_HEADERS) - -D_SRCS = . -SRCS = Colleen.c - -D_HEADERS = . -HEADERS = - -D_OBJS = builds -OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) - -ifeq "$(D_OBJS)" "." - RM_OBJS = rm -f $(OBJS) -else - RM_OBJS = rm -rf $(D_OBJS) -endif - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . target: prerequisites . $@ : target # -# RULES . recipe . $< : 1st prerequisite # -# . recipe . $^ : all prerequisites # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - -all: $(NAME) - -# %.$(EXT) | $(D_OBJS) -> pipe is for order-only prerequisites : -# - for each file "%.$(EXT)" : -# - if it has been modified since last time -# - execute rules on corresponding target file "$(D_OBJS)/%.o" -# - and directory "$(D_OBJS)" is order-only prerequisite : -# - it must exist before executing rule -# - but last time modification is not checked -$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) - @echo $(CYAN)"compilation (objects.o) :"$(RESET) - $(CC) $(CFLAGS) -c $< -o $@ - -$(D_OBJS): - mkdir $@ - -$(OBJS): $(F_INCLUDES) - -$(NAME): $(OBJS) - @echo $(CYAN)"linkage (link objects.o) :"$(RESET) - $(CC) $(OBJS) -o $@ $(LIBS) - -leaks: $(NAME) - valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) - -#diff: $(NAME) -# @echo $(CYAN)"compare source with output :"$(RESET) -# @echo "diff --color --report-identical-files tmp_$(NAME) $(SRCS)" -# @diff_output=$$(diff --color --report-identical-files tmp_$(NAME) $(SRCS)); \ -# diff_exit=$$?; \ -# diff_color=$(RED); \ -# if [ "$$diff_exit" -eq 0 ]; then diff_color=$(GREEN); fi; \ -# echo $$diff_color"$$diff_output"$(RESET); - -# old diff version : -#diff: $(NAME) -# @echo $(CYAN)"compare source with output :"$(RESET) -# ./$(NAME) > tmp_$(NAME) -# - diff --color --report-identical-files tmp_$(NAME) $(SRCS) -# rm tmp_$(NAME) - -diff: - @echo $(CYAN)"compare source with output :"$(RESET) - - diff --color tmp_$(NAME) $(SRCS); \ - if [ $$? -eq 0 ]; then echo $(GREEN)"Files $(NAME) and $(SRCS) are identical"$(RESET); fi - -#diff: -# @echo $(CYAN)"compare source with output :"$(RESET) -# $(shell diff --color tmp_$(NAME) $(SRCS) ) -# @if [ $(.SHELLSTATUS) -eq 0 ]; then echo $(GREEN)"Files $(NAME) and $(SRCS) are identical"$(RESET); fi - -clean: - $(RM_OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY : all clean fclean re +NAME = Colleen +SRCS = Colleen.c +include ../MakefileCommon diff --git a/1_Colleen/tmp_Colleen b/1_Colleen/tmp_Colleen deleted file mode 100644 index 6bb97ab..0000000 --- a/1_Colleen/tmp_Colleen +++ /dev/null @@ -1,14 +0,0 @@ -/*comment outside*/ -#include - -char *second_function() { - return "/*comment outside*/%c#include %c%cchar *second_function() {%c return %c%s%c;%c}%c%cint main() {%c /*comment inside*/%c char *program = second_function();%c printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c"; -} - - -int main() { - /*comment inside*/ - char *program = second_function(); - printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10); - return 0; -} diff --git a/2_Grace/Makefile b/2_Grace/Makefile index 0666438..93dc7f8 100644 --- a/2_Grace/Makefile +++ b/2_Grace/Makefile @@ -1,111 +1,5 @@ -# - - - - - - # -# # -# COLORS # -# # -# - - - - - - # -GRAY = "\e[0;30m" -RED = "\e[0;31m" -GREEN = "\e[0;32m" -YELLOW = "\e[0;33m" -BLUE = "\e[0;34m" -PURPLE = "\e[0;35m" -CYAN = "\e[0;36m" -WHITE = "\e[0;37m" - -B_GRAY = "\e[1;30m" -B_RED = "\e[1;31m" -B_GREEN = "\e[1;32m" -B_YELLOW = "\e[1;33m" -B_BLUE = "\e[1;34m" -B_PURPLE = "\e[1;35m" -B_CYAN = "\e[1;36m" -B_WHITE = "\e[1;37m" - -RESET = "\e[0m" - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . name = value \ . += append to a variable # -# VARIABLES . value . != set result of command # -# . name is case sensitive . ?= set if not already set # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - - -NAME = Grace - -CC = clang -EXT = c - -CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -CFLAGS += -g3 - -VPATH = $(D_SRCS) - -LIBS = - -F_INCLUDES = $(HEADERS:%=$(D_HEADERS)/%) -INCLUDES = -I$(D_HEADERS) - -D_SRCS = . -SRCS = Grace.c - -D_HEADERS = . -HEADERS = - -D_OBJS = builds -OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) - -ifeq "$(D_OBJS)" "." - RM_OBJS = rm -f $(OBJS) -else - RM_OBJS = rm -rf $(D_OBJS) -endif - - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -# . target: prerequisites . $@ : target # -# RULES . recipe . $< : 1st prerequisite # -# . recipe . $^ : all prerequisites # -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # - -all: $(NAME) - -# %.$(EXT) | $(D_OBJS) -> pipe is for order-only prerequisites : -# - for each file "%.$(EXT)" : -# - if it has been modified since last time -# - execute rules on corresponding target file "$(D_OBJS)/%.o" -# - and directory "$(D_OBJS)" is order-only prerequisite : -# - it must exist before executing rule -# - but last time modification is not checked -$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) - @echo $(CYAN)"compilation (objects.o) :"$(RESET) - $(CC) $(CFLAGS) -c $< -o $@ - -$(D_OBJS): - mkdir $@ - -$(OBJS): $(F_INCLUDES) - -$(NAME): $(OBJS) - @echo $(CYAN)"linkage (link objects.o) :"$(RESET) - $(CC) $(OBJS) -o $@ $(LIBS) - -leaks: $(NAME) - valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) - -diff: $(NAME) - @echo $(CYAN)"compare source with output :"$(RESET) - ./$(NAME) > tmp_$(NAME) - - diff --color --report-identical-files tmp_$(NAME) $(SRCS) - rm tmp_$(NAME) - -clean: - $(RM_OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY : all clean fclean re +NAME = Grace +SRCS = Grace.c +include ../MakefileCommon diff --git a/Makefile b/Makefile index 4194df4..ab8802a 100644 --- a/Makefile +++ b/Makefile @@ -67,3 +67,4 @@ re: fclean all .PHONY : all clean fclean re + diff --git a/MakefileCommon b/MakefileCommon new file mode 100644 index 0000000..81611e5 --- /dev/null +++ b/MakefileCommon @@ -0,0 +1,108 @@ +# - - - - - - # +# # +# COLORS # +# # +# - - - - - - # + +GRAY = "\e[0;30m" +RED = "\e[0;31m" +GREEN = "\e[0;32m" +YELLOW = "\e[0;33m" +BLUE = "\e[0;34m" +PURPLE = "\e[0;35m" +CYAN = "\e[0;36m" +WHITE = "\e[0;37m" + +B_GRAY = "\e[1;30m" +B_RED = "\e[1;31m" +B_GREEN = "\e[1;32m" +B_YELLOW = "\e[1;33m" +B_BLUE = "\e[1;34m" +B_PURPLE = "\e[1;35m" +B_CYAN = "\e[1;36m" +B_WHITE = "\e[1;37m" + +RESET = "\e[0m" + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . name = value \ . += append to a variable # +# VARIABLES . value . != set result of command # +# . name is case sensitive . ?= set if not already set # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +# FILES : +#NAME -> defined in subfolder makefiles +#SRCS -> defined in subfolder makefiles +LIBS = +D_SRCS = . +D_HEADERS = . +HEADERS = + +# COMPILATION CONFIG : +CC = clang +EXT = c +CFLAGS = -Wall -Wextra -Werror $(INCLUDES) +CFLAGS += -g3 + +# AUTOMATICALLY CREATED : +D_OBJS = builds +OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) +VPATH = $(D_SRCS) +F_INCLUDES = $(HEADERS:%=$(D_HEADERS)/%) +INCLUDES = -I$(D_HEADERS) +ifeq "$(D_OBJS)" "." + RM_OBJS = rm -f $(OBJS) +else + RM_OBJS = rm -rf $(D_OBJS) +endif + + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # +# . target: prerequisites . $@ : target # +# RULES . recipe . $< : 1st prerequisite # +# . recipe . $^ : all prerequisites # +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # + +all: $(NAME) + +# %.$(EXT) | $(D_OBJS) -> pipe is for order-only prerequisites : +# - for each file "%.$(EXT)" : +# - if it has been modified since last time +# - execute rules on corresponding target file "$(D_OBJS)/%.o" +# - and directory "$(D_OBJS)" is order-only prerequisite : +# - it must exist before executing rule +# - but last time modification is not checked +$(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) + @echo $(CYAN)"compilation (objects.o) :"$(RESET) + $(CC) $(CFLAGS) -c $< -o $@ + +$(D_OBJS): + mkdir $@ + +$(OBJS): $(F_INCLUDES) + +$(NAME): $(OBJS) + @echo $(CYAN)"linkage (link objects.o) :"$(RESET) + $(CC) $(OBJS) -o $@ $(LIBS) + +leaks: $(NAME) + valgrind --leak-check=full --show-leak-kinds=all ./$(NAME) + +diff: $(NAME) + @echo $(CYAN)"compare source with output :"$(RESET) + ./$(NAME) > tmp_$(NAME) + - diff --color tmp_$(NAME) $(SRCS); \ + if [ $$? -eq 0 ]; then echo $(GREEN)"Files $(NAME) and $(SRCS) are identical"$(RESET); else echo $(RED)":Files $(NAME) and $(SRCS) differ"$(RESET); fi + rm tmp_$(NAME) + +clean: + $(RM_OBJS) + +fclean: clean + rm -f $(NAME) + +re: fclean all + +.PHONY : all clean fclean re + +