From c967207520bf0d4d56a9f0e868b0e7a8be01659e Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Wed, 24 Apr 2024 23:36:25 +0200 Subject: [PATCH] awk marker comments to save necessary macros I restructured the beginnings of the preprocessed files for debugging to make the awks in the makefile not eat headers which are needed for debugging (e.g. the FOR_EACH macro) it's done by putting awk marker comments: // awk stop marker (check make pp) after the macros to be eaten by awk and before the ones we wanna keep I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this --- Makefile | 13 ++++++++++--- include/config.hpp | 8 +++++++- include/osuparser.hpp | 8 ++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index b94f3a1..339100b 100644 --- a/Makefile +++ b/Makefile @@ -41,19 +41,26 @@ _PP_CXX = osuparser.cpp _PP = $(_PP_HXX) $(_PP_CXX) PP = $(addprefix $(PREPROCESSED)/, $(_PP)) -# TODO work out how to keep my own headers in the awk somehow +# the awks below will remove all includes, pragmas and blank lines from the top of the file +# until they hit something else +# +# doing that makes clang-format considerably faster (c++ std moment) +# but also removes my own headers which makes some of the macros not evaluate +# +# that issue is fixed by adding a comment that'll stop the awk before my macros +# and after all the others pp: dirs $(PP) $(PREPROCESSED)/%.hpp: $(INCLUDE)/%.hpp $(eval TMP := $(shell mktemp).hpp) - awk '/^#include/ || /^#pragma/ || /^namespace/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP) + awk '/^#include/ || /^#pragma/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP) $(CXX) $(CXXFLAGS) -E $(TMP) > $@ clang-format -i $@ rm -rf $(TMP) $(PREPROCESSED)/%.cpp: $(SRC)/%.cpp $(eval TMP := $(shell mktemp).cpp) - awk '/^#include/ || /^#pragma/ || /^namespace/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP) + awk '/^#include/ || /^#pragma/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP) $(CXX) $(CXXFLAGS) -E $(TMP) > $@ clang-format -i $@ rm -rf $(TMP) diff --git a/include/config.hpp b/include/config.hpp index 5c8257b..0c6b0be 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -5,9 +5,15 @@ #include -#include #include +// awk stop marker (check make pp) +// only brings in operator<< definitions +// for sf::Color and std::vector +// doesn't change output, we only need the FOR_EACH macro + +#include + #define CONFIG(name, ...) \ struct name {\ __VA_ARGS__\ diff --git a/include/osuparser.hpp b/include/osuparser.hpp index 457be8b..7a7be8e 100644 --- a/include/osuparser.hpp +++ b/include/osuparser.hpp @@ -2,10 +2,14 @@ #include -namespace fs = std::filesystem; - #include +// no marker here since config.hpp is only included to bring +// the generated struct into scope +// the output will be the same regardless + +namespace fs = std::filesystem; + #define CONFIG(name, ...) name parse##name(fs::path configPath); #define SECTION(name, ...)