osuplusplus/Makefile
jacekpoz e1dbdf5228
speed up make pp from 23 seconds to almost instant
this is done by removing all headers from the top of the file using that
awk written by the amazing Jappie3 from the hyprland discord

g++ -E itself was pretty fast but clang-format took a while to format a
52k line file (wonder why), removing std makes the files considerably
smaller and makes the whole operation almost instant

one small issue is currently the script removes every single header
unless it hits something else - not ideal since my own headers will get
wiped too and in the preprocessed output not all macros will be
evaluated (e.g. FOR_EACH from for_each.hpp in config.hpp)
2024-04-24 23:25:15 +02:00

59 lines
1.4 KiB
Makefile

CXX = g++
CXXFLAGS = -std=c++20 -O3 -Wall -Wextra -Wpedantic
LDFLAGS = -lsfml-graphics -lsfml-window -lsfml-system
NAME = osu++
INCLUDE = include
CXXFLAGS += -I$(INCLUDE)
SRC = src
BIN = target
PREPROCESSED = preprocessed
_PROG = HitObjectDrawable.cpp main.cpp osuparser.cpp TextureManager.cpp
PROG = $(addprefix $(SRC)/, $(_PROG))
OBJ = $(_PROG:.cpp=.o)
.PHONY: all clean
all: dirs $(NAME)
dirs:
mkdir -p $(BIN)
mkdir -p $(PREPROCESSED)
$(NAME): $(OBJ)
$(CXX) $(addprefix $(BIN)/, $^) $(LDFLAGS) -o $(BIN)/$@
%.o: $(SRC)/%.cpp
$(CXX) -c $< $(CXXFLAGS) -o $(BIN)/$@
clean:
rm -rf $(addprefix $(BIN)/, $(OBJ))
rm -rf $(BIN)/$(NAME)
rm -rf $(BIN)
rm -rf $(PREPROCESSED)
_PP_HXX = osuparser.hpp config.hpp
_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
pp: dirs $(PP)
$(PREPROCESSED)/%.hpp: $(INCLUDE)/%.hpp
$(eval TMP := $(shell mktemp).hpp)
awk '/^#include/ || /^#pragma/ || /^namespace/ || /^[[: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)
$(CXX) $(CXXFLAGS) -E $(TMP) > $@
clang-format -i $@
rm -rf $(TMP)