68 lines
1.5 KiB
Makefile
68 lines
1.5 KiB
Makefile
QUIET=1
|
|
ADDRESS_SANITIZE=1
|
|
|
|
all:first
|
|
|
|
OBJECT_FILES=gui.o main.o simdata.o assembly.o cpu.o
|
|
MAIN_ROM=programs/3d_renderer.rom
|
|
ROMS=test.rom ${MAIN_ROM}
|
|
|
|
make.deps: $(subst .o,.c,${OBJECT_FILES}) $(wildcard *.h)
|
|
@$(CC) -MM $(subst .o,.c,${OBJECT_FILES}) > make.deps
|
|
|
|
include make.deps
|
|
|
|
|
|
ifeq "${QUIET}" "1"
|
|
QUIET_CC = @echo ' CC '$@;
|
|
QUIET_LINK = @echo ' LINK '$@;
|
|
QUIET_FAS = @echo ' FAS '$@;
|
|
QUIET_CLEAN = @echo ' CLEAN .';
|
|
QUIET_VALGRIND = @echo ' VALGRIND '$@;
|
|
Q = @
|
|
else
|
|
Q =
|
|
endif
|
|
|
|
CFLAGS::=-O2 $(shell pkg-config ncursesw --cflags)
|
|
|
|
ifeq "${ADDRESS_SANITIZE}" "1"
|
|
CFLAGS += -fsanitize=address -ggdb
|
|
LDFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=leak
|
|
endif
|
|
|
|
all:${MAIN_ROM}
|
|
|
|
first: ${OBJECT_FILES}
|
|
${QUIET_LINK}
|
|
${Q}gcc -ggdb $^ $(shell pkg-config --libs ncursesw) -lm -o $@ ${LDFLAGS}
|
|
|
|
gprof:
|
|
gprof first -b|less
|
|
|
|
%.rom:%.asm first
|
|
$(QUIET_FAS)
|
|
${Q}./first -i $< -a $@
|
|
|
|
%.o:%.c
|
|
${QUIET_CC}
|
|
${Q}gcc -c $< -Wall -Wextra -Werror ${CFLAGS}
|
|
|
|
callgrind.out:first ${MAIN_ROM}
|
|
${QUIET_VALGRIND}
|
|
${Q}if ldd first |grep asan > /dev/null;\
|
|
then\
|
|
echo ERROR: Binary build with libasan, please rebuild without address sanitiser;\
|
|
else\
|
|
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes --callgrind-out-file=callgrind.out ./first -i programs/3d_renderer.rom;\
|
|
fi
|
|
|
|
|
|
profile: callgrind.out
|
|
kcachegrind $<
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
${QUIET_CLEAN}
|
|
${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out
|