massively improve the awk fuckery

thank you krizej I actually forgot about g++ -D
This commit is contained in:
jacekpoz 2024-04-25 11:49:09 +02:00
parent cc538d835e
commit 19ff37e7b8
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8
5 changed files with 12 additions and 28 deletions

View file

@ -41,29 +41,14 @@ _PP_CXX = osuparser.cpp
_PP = $(_PP_HXX) $(_PP_CXX)
PP = $(addprefix $(PREPROCESSED)/, $(_PP))
# the awks below will remove all includes, pragmas and blank lines from the top of the file
# until they hit something else
#
# that something else could be an awk marker comment which saves part of the includes
# from being eaten by awk - ones useful when debugging the output of these godforsaken macros
#
# 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_DEBUG gets rid of all the macros we don't need
# when debugging the preprocessed output
pp: dirs $(PP)
$(PREPROCESSED)/%.hpp: $(INCLUDE)/%.hpp
$(eval TMP := $(shell mktemp).hpp)
awk '/^#include/ || /^#pragma/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP)
$(CXX) $(CXXFLAGS) -E $(TMP) > $@
$(CXX) -DPP_DEBUG $(CXXFLAGS) -E $< > $@
clang-format -i $@
rm -rf $(TMP)
$(PREPROCESSED)/%.cpp: $(SRC)/%.cpp
$(eval TMP := $(shell mktemp).cpp)
awk '/^#include/ || /^#pragma/ || /^[[:space:]]*$$/ {if(!f)next} // {f=1;print}' $< > $(TMP)
$(CXX) $(CXXFLAGS) -E $(TMP) > $@
$(CXX) -DPP_DEBUG $(CXXFLAGS) -E $< > $@
clang-format -i $@
rm -rf $(TMP)

View file

@ -1,17 +1,14 @@
#pragma once
#ifndef PP_DEBUG
#include <cinttypes>
#include <vector>
#include <SFML/Graphics/Color.hpp>
#endif
#include <util_stream_ops.hpp>
// awk stop marker (check make pp)
// <util_stream_ops.hpp> only brings in operator<< definitions
// for sf::Color and std::vector<T>
// doesn't change output, we only need the FOR_EACH macro
#include <foreach.hpp>
#define CONFIG(name, ...) \

View file

@ -1,13 +1,11 @@
#pragma once
#ifndef PP_DEBUG
#include <filesystem>
#endif
#include <config.hpp>
// 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);

View file

@ -1,10 +1,12 @@
#pragma once
#ifndef PP_DEBUG
#include <concepts>
#include <sstream>
#include <vector>
#include <SFML/Graphics/Color.hpp>
#endif
inline std::ostream &operator<<(std::ostream &stream, const sf::Color &color) {
stream << "Color(" << color.r << ", " << color.g << ", " << color.b << ", " << color.a << ")";

View file

@ -1,9 +1,11 @@
#include <osuparser.hpp>
#ifndef PP_DEBUG
#include <algorithm>
#include <array>
#include <fstream>
#include <iostream>
#endif
inline std::string trimString(const std::string &str) {
std::string ret(str);