You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.9 KiB
106 lines
2.9 KiB
SRC=$(wildcard src/*.cpp)
|
|
INCLUDE =include
|
|
|
|
_HX_FEAT?= -DFIXED_ROW_SIZE=24
|
|
|
|
CXXFLAGS_COMMON = -Wall -pedantic --std=gnu++20 $(addprefix -I,$(INCLUDE)) -felide-constructors -fno-strict-aliasing -fno-exceptions
|
|
LDFLAGS_COMMON = -lfmt
|
|
|
|
CXXFLAGS_DEFAULT = -pipe -O3 -march=native -fgraphite -flto
|
|
CXXFLAGS_RELEASE = -fomit-frame-pointer -fmerge-all-constants -fmodulo-sched -funswitch-loops -fsplit-loops
|
|
LDFLAGS_DEFAULT = -O3 -flto
|
|
|
|
CXXFLAGS_DEBUG = -DDEBUG -O0 -g
|
|
|
|
PROJECT = hexview
|
|
|
|
OBJ = $(addprefix obj/,$(SRC:.cpp=.o))
|
|
|
|
### PGO target specific ###
|
|
|
|
# Number of times to run profiling
|
|
PGO_ITERATIONS = 512
|
|
# Size in kb of training files
|
|
PGO_DATASET_SIZE = $$(( 1024 * 4 ))
|
|
|
|
PGO_OBJ = $(addprefix profile/,$(SRC:.cpp=.o))
|
|
PROF_FLAGS = -fprofile-generate
|
|
|
|
###
|
|
|
|
.PHONY: release
|
|
release: | dirs $(PROJECT)-release
|
|
|
|
.PHONY: debug
|
|
debug: | dirs $(PROJECT)-debug
|
|
|
|
.PHONY: pgo
|
|
pgo: | dirs $(PROJECT)-pgo
|
|
|
|
dirs:
|
|
@mkdir -p obj/src
|
|
@mkdir -p profile/src
|
|
|
|
obj/%.o: %.cpp
|
|
$(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
profile/%.o: %.cpp
|
|
$(CXX) -c $< $(_HX_FEAT) $(CXXFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
|
|
|
|
$(PROJECT)-release: CXXFLAGS?= $(CXXFLAGS_DEFAULT)
|
|
$(PROJECT)-release: LDFLAGS?= $(LDFLAGS_DEFAULT)
|
|
$(PROJECT)-release: CXXFLAGS+= $(CXXFLAGS_COMMON)
|
|
$(PROJECT)-release: CXXFLAGS+= $(CXXFLAGS_RELEASE)
|
|
$(PROJECT)-release: LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS)
|
|
$(PROJECT)-release: $(OBJ)
|
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
strip $@
|
|
|
|
|
|
$(PROJECT)-debug: CXXFLAGS += $(CXXFLAGS_COMMON)
|
|
$(PROJECT)-debug: CXXFLAGS += $(CXXFLAGS_DEBUG)
|
|
$(PROJECT)-debug: LDFLAGS += $(LDFLAGS_COMMON)
|
|
$(PROJECT)-debug: $(OBJ)
|
|
$(CXX) $^ $(CXXFLAGS) -o $@ $(LDFLAGS)
|
|
|
|
pgo-generate: $(PGO_OBJ)
|
|
$(CXX) $^ $(CXXFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
|
|
|
|
pgo-profile: pgo-generate
|
|
for i in {1..$(PGO_ITERATIONS)}; do \
|
|
dd if=/dev/urandom of=/tmp/$(PROJECT)-pgo-test bs=1024 count=$(PGO_DATASET_SIZE) >> /dev/null 2>&1; \
|
|
printf "\rIteration $$i / $(PGO_ITERATIONS)"; \
|
|
./pgo-generate /tmp/$(PROJECT)-pgo-test > /tmp/$(PROJECT)-pgo-output; \
|
|
done
|
|
@echo ""
|
|
rm /tmp/$(PROJECT)-pgo-test
|
|
rm /tmp/$(PROJECT)-pgo-output
|
|
rm pgo-generate
|
|
|
|
|
|
pgo-use: CXXFLAGS?= $(CXXFLAGS_DEFAULT)
|
|
pgo-use: LDFLAGS?= $(LDFLAGS_DEFAULT)
|
|
pgo-use: CXXFLAGS+= $(CXXFLAGS_COMMON)
|
|
pgo-use: CXXFLAGS+= $(CXXFLAGS_RELEASE)
|
|
pgo-use: LDFLAGS := $(LDFLAGS_COMMON) -lgcov $(LDFLAGS)
|
|
pgo-use: PROF_FLAGS = -fprofile-use
|
|
pgo-use: $(PGO_OBJ)
|
|
$(CXX) $^ $(CXXFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
|
|
|
|
$(PROJECT)-pgo: CXXFLAGS?= $(CXXFLAGS_DEFAULT)
|
|
$(PROJECT)-pgo: LDFLAGS?= $(LDFLAGS_DEFAULT)
|
|
$(PROJECT)-pgo: CXXFLAGS+= $(CXXFLAGS_COMMON)
|
|
$(PROJECT)-pgo: CXXFLAGS+= $(CXXFLAGS_RELEASE)
|
|
$(PROJECT)-pgo: LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS)
|
|
$(PROJECT)-pgo: | dirs pgo-profile
|
|
find ./profile -name \*.o -exec rm {} +
|
|
$(MAKE) pgo-use
|
|
mv pgo-use $@
|
|
strip $@
|
|
|
|
clean:
|
|
rm -f $(PROJECT)-{release,debug,pgo}
|
|
rm -rf obj
|
|
rm -rf profile
|
|
rm -f pgo-{test,output,generate}
|