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.
fcmp/Makefile

106 lines
2.9 KiB

4 years ago
SRC = $(wildcard src/*.c)
INCLUDE=include
PROJECT=fcmp
4 years ago
OPT_FLAGS+= -fgraphite
4 years ago
FEAT_CFLAGS?= -D_RUN_THREADED=0
FEAT_LDFLAGS?= -lpthread
4 years ago
RELEASE_CFLAGS?= -O3 -march=native -flto $(OPT_FLAGS)
RELEASE_LDFLAGS?= -O3 -flto
DEBUG_CFLAGS?= -DDEBUG -O0 -g
4 years ago
DEBUG_LDFLAGS?= -O0
CFLAGS+= $(FEAT_CFLAGS) -Wall -pedantic --std=gnu11 $(addprefix -I,$(INCLUDE))
LDFLAGS+= $(FEAT_LDFLAGS)
4 years ago
4 years ago
# PGO specific vars
4 years ago
PROF_ITERATIONS=10
4 years ago
PROF_LARGE_BOUND= $$(( 1024 * 1024 * 10 ))
PROF_SMALL_BOUND= $$(( 1024 * 10 ))
PROF_LOCATION?=/tmp/fcmp-pgo
PROF_FLAGS = -fprofile-generate
4 years ago
OBJ = $(addprefix obj/,$(SRC:.c=.o))
4 years ago
PGO_OBJ = $(addprefix prof/,$(SRC:.c=.o))
4 years ago
.PHONY: release
release: | dirs $(PROJECT)-release
.PHONY: debug
debug: | dirs $(PROJECT)-debug
4 years ago
.PHONY: pgo
pgo: | dirs $(PROJECT)-pgo
4 years ago
dirs:
4 years ago
@mkdir -p {obj,prof}/src
4 years ago
4 years ago
obj/%.o: %.c
4 years ago
$(CC) -c $< $(CFLAGS) -o $@ $(LDFLAGS)
4 years ago
prof/%.o: %.c
$(CC) -c $< $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
4 years ago
$(PROJECT)-release: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
$(PROJECT)-release: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
$(PROJECT)-release: $(OBJ)
$(CC) $^ $(CFLAGS) -o $@ $(LDFLAGS)
strip $@
$(PROJECT)-debug: CFLAGS := $(DEBUG_CFLAGS) $(CFLAGS)
$(PROJECT)-debug: LDFLAGS := $(DEBUG_LDFLAGS) $(LDFLAGS)
$(PROJECT)-debug: $(OBJ)
$(CC) $^ $(CFLAGS) -o $@ $(LDFLAGS)
4 years ago
pgo-generate: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
pgo-generate: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
4 years ago
pgo-generate: $(PGO_OBJ)
4 years ago
$(CC) $^ $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
4 years ago
pgo-reset:
find ./prof -name \*.gcda -exec rm {} +
4 years ago
pgo-profile: pgo-reset pgo-generate
4 years ago
#./profile/gen $(PROF_LARGE_BOUND) "$(PROF_LOCATION)/large"
#./profile/gen $(PROF_SMALL_BOUND) "$(PROF_LOCATION)/small"
for i in {1..$(PROF_ITERATIONS)}; do \
4 years ago
rm -rf $(PROF_LOCATION); \
mkdir -p $(PROF_LOCATION)/{large,small}; \
printf "Iteration $$i of $(PROF_ITERATIONS)\r"; \
./profile/gen $(PROF_LARGE_BOUND) "$(PROF_LOCATION)/large" >> /dev/null; \
./profile/gen $(PROF_SMALL_BOUND) "$(PROF_LOCATION)/small" >> /dev/null; \
./pgo-generate $(PROF_LOCATION)/large/matching/* > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/large/unmatching/* > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/small/matching/* > $(PROF_LOCATION)/stdout; \
./pgo-generate $(PROF_LOCATION)/small/unmatching/* > $(PROF_LOCATION)/stdout; \
rm -rf $(PROF_LOCATION)/{large,small}; \
4 years ago
done
4 years ago
@echo ""
4 years ago
rm -rf $(PROF_LOCATION)
rm pgo-generate
pgo-use: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
pgo-use: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
pgo-use: PROF_FLAGS = -fprofile-use
pgo-use: $(PGO_OBJ)
4 years ago
$(CC) $^ $(CFLAGS) $(PROF_FLAGS) -o $@ $(LDFLAGS) $(PROF_FLAGS)
4 years ago
$(PROJECT)-pgo: CFLAGS := $(RELEASE_CFLAGS) $(CFLAGS)
$(PROJECT)-pgo: LDFLAGS := $(RELEASE_LDFLAGS) $(LDFLAGS)
$(PROJECT)-pgo: pgo-profile
find ./prof -name \*.o -exec rm {} +
$(MAKE) pgo-use
mv pgo-use $@
strip $@
4 years ago
clean:
4 years ago
rm -rf {obj,prof}
4 years ago
rm -f $(PROJECT)-{release,debug,pgo}