From 65aac2c25a2a88768e5bebc6f169406a2bf207c0 Mon Sep 17 00:00:00 2001 From: asus Date: Thu, 25 Jan 2024 18:40:37 +0100 Subject: [PATCH] added sed command in makefile to concat quine --- 1_Colleen/Colleen.c | 11 ++--------- 3_Sully/Sully.c | 20 +++++++------------- MakefileCommon | 18 ++++++++++++++++-- notes.md | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/1_Colleen/Colleen.c b/1_Colleen/Colleen.c index da3dfcb..1fd64d6 100644 --- a/1_Colleen/Colleen.c +++ b/1_Colleen/Colleen.c @@ -2,16 +2,9 @@ comment outside */ #include - -char *second_function() { - return "/*%c comment outside%c*/%c#include %c%cchar *second_function() {%c return %c%s%c;%c}%c%cint main() {%c /*%c comment inside%c */%c char *program = second_function();%c printf(program, 10, 10, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c"; -} - -int main() { +char *second_function() { return "/*%c comment outside%c*/%c#include %cchar *second_function() { return %c%s%c; }%cint main() { char *program = second_function(); printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); return 0;%c /*%c comment inside%c */%c}%c"; } +int main() { char *program = second_function(); printf(program, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); return 0; /* comment inside */ - char *program = second_function(); - printf(program, 10, 10, 10, 10, 10, 10, 34, program, 34, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10); - return 0; } diff --git a/3_Sully/Sully.c b/3_Sully/Sully.c index ac95bde..bfb97c5 100644 --- a/3_Sully/Sully.c +++ b/3_Sully/Sully.c @@ -1,14 +1,8 @@ #include -#define PRINT quine, 10, print, 10, 92, 10, 92, 10, 92, 10, 92, 10, 92, 10, 34, quine, 34, 92, 10, 92, 10, 92, 10, 10, 10, 10, 10 -#define FT(...) int main(){\ - /*\ - comment\ - */\ - char *print = #__VA_ARGS__;\ - char *quine = "#include %c#define PRINT %s%c#define FT(...) int main(){%c%c /*%c%c comment%c%c */%c%c char *print = #__VA_ARGS__;%c%c char *quine = %c%s%c;%c%c printf(PRINT);%c%c return 0;%c%c}%c#define FFT(...) FT(__VA_ARGS__)%c%cFFT(PRINT)%c";\ - printf(PRINT);\ - return 0;\ -} -#define FFT(...) FT(__VA_ARGS__) - -FFT(PRINT) +#define xstr(s) #s +#define str(s) xstr(s) +#define MAIN(s) int main() { char *quine = "#include \n#define xstr(s) #s\n#define str(s) xstr(s)\n#define MAIN(s) "s"\n/*\n comment\n*/\nMAIN(str(MAIN(s)))\n"; FILE *file = fopen("Grace_kid.c", "w"); fprintf(file, "%s", quine); return 0; } +/* + comment +*/ +MAIN(str(MAIN(s))) diff --git a/MakefileCommon b/MakefileCommon index 29620e1..4aed8ec 100644 --- a/MakefileCommon +++ b/MakefileCommon @@ -49,6 +49,7 @@ CFLAGS += -g3 # AUTOMATICALLY CREATED : D_OBJS = builds OBJS = $(SRCS:%.$(EXT)=$(D_OBJS)/%.o) +EXPLODED = $(SRCS:%.$(EXT)=%_exploded.$(EXT)) VPATH = $(D_SRCS) F_INCLUDES = $(HEADERS:%=$(D_HEADERS)/%) INCLUDES = -I$(D_HEADERS) @@ -65,7 +66,18 @@ endif # . recipe . $^ : all prerequisites # # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # -all: $(NAME) +all: concat $(NAME) + +# sed : +# -z : instead of classic "-e", looks for lines that ends with \0 instead of \n, usefull when lines can contain \n +# 's/\\\n\t*//g' : subsitutes backslash '\\' followed by newline '\n' followed by any number of tabs '\t*', and replace them by nothing +# empty recipe : +# - to avoid makefile complaining when $(EXPLODED) does not exist +# - https://www.gnu.org/software/make/manual/html_node/Empty-Recipes.html +concat: $(EXPLODED) + @echo $(CYAN)"create the condensed version of the quine :"$(RESET) + - test -f $< && sed -z 's/\\\n\t*//g' $< > $(SRCS) +$(EXPLODED): ; # %.$(EXT) | $(D_OBJS) -> pipe is for order-only prerequisites : # - for each file "%.$(EXT)" : @@ -74,6 +86,8 @@ all: $(NAME) # - and directory "$(D_OBJS)" is order-only prerequisite : # - it must exist before executing rule # - but last time modification is not checked +# - it avoids recompiling each time because the build folder was +# modified by creation of other objects files $(D_OBJS)/%.o: %.$(EXT) | $(D_OBJS) @echo $(CYAN)"compilation (objects.o) :"$(RESET) $(CC) $(CFLAGS) -c $< -o $@ @@ -104,6 +118,6 @@ fclean: clean re: fclean all -.PHONY : all clean fclean re +.PHONY : all clean fclean re concat diff leaks diff --git a/notes.md b/notes.md index 5598f52..c101333 100644 --- a/notes.md +++ b/notes.md @@ -2,6 +2,41 @@ - [preprocessor strip comments before exapnding macros](https://stackoverflow.com/questions/1510869/does-the-c-preprocessor-strip-comments-or-expand-macros-first) - [create an include with a macro OR NOT](https://stackoverflow.com/questions/1135822/escaping-a-symbol-in-a-define-macro) +--- + +## make rules : + +- make in root will make all projects +- make in each project will compile this project +- make diff : compile if necessary, and run the program then compare the output +- make concat : create the concatenated version, finale version, of the quine + +## folder structure + +> Each programs will have to be coded in C and in Assembly, and respectivly in a folder named C and ASM, each folders containing its own Makefile with the usual rules. + +``` +dr_quine/ +│ +├─ C/ +│ ├─ Colleen.c +│ ├─ Grace.c +│ ├─ Sully.c +│ ├─ Makefile +│ └─ ... +│ +└─ ASM/ + ├─ Colleen.asm + ├─ Grace.asm + ├─ Sully.asm + ├─ Makefile + └─ ... +``` + + +--- + + ## Grace ---