2024-01-29 13:03:43 +00:00
|
|
|
QUIET=1
|
2024-02-20 02:12:57 +00:00
|
|
|
ADDRESS_SANITIZE=1
|
2024-03-02 00:23:29 +00:00
|
|
|
USE_AALIB=1
|
2024-01-29 13:03:43 +00:00
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
all:first
|
|
|
|
|
2024-02-27 02:55:14 +00:00
|
|
|
OBJECT_FILES=gui.o gui_display.o main.o simdata.o assembly.o cpu.o
|
2024-03-02 23:26:35 +00:00
|
|
|
MAIN_ROM=programs/utah_teapot.rom
|
|
|
|
ROMS=test.rom ${MAIN_ROM} programs/cube.rom
|
|
|
|
UTAH_TEAPOT_ASCII_STL=assets/Utah_teapot_ascii.stl
|
|
|
|
AXIL_PROGS=auxiliary_progs/stl_to_source_code
|
2024-02-03 22:54:20 +00:00
|
|
|
|
|
|
|
make.deps: $(subst .o,.c,${OBJECT_FILES}) $(wildcard *.h)
|
|
|
|
@$(CC) -MM $(subst .o,.c,${OBJECT_FILES}) > make.deps
|
|
|
|
|
|
|
|
include make.deps
|
|
|
|
|
2024-01-29 13:03:43 +00:00
|
|
|
|
|
|
|
ifeq "${QUIET}" "1"
|
2024-02-26 19:04:54 +00:00
|
|
|
QUIET_CC = @echo ' CC '$@;
|
|
|
|
QUIET_LINK = @echo ' LINK '$@;
|
|
|
|
QUIET_FAS = @echo ' FAS '$@;
|
|
|
|
QUIET_CLEAN = @echo ' CLEAN .';
|
|
|
|
QUIET_VALGRIND = @echo ' VALGRIND '$@;
|
2024-03-02 23:26:35 +00:00
|
|
|
QUIET_STL_CONV = @echo ' STL_TO_SOURCE_CODE '$@;
|
|
|
|
|
2024-02-26 19:04:54 +00:00
|
|
|
Q = @
|
2024-01-29 13:03:43 +00:00
|
|
|
else
|
2024-03-02 23:26:35 +00:00
|
|
|
Q =
|
2024-01-29 13:03:43 +00:00
|
|
|
endif
|
|
|
|
|
2024-02-20 15:36:12 +00:00
|
|
|
CFLAGS::=-O2 $(shell pkg-config ncursesw --cflags)
|
2024-03-02 00:23:29 +00:00
|
|
|
|
|
|
|
ifeq "${USE_AALIB}" "1"
|
|
|
|
CFLAGS::=$(shell pkg-config ncursesw --cflags)
|
2024-02-27 02:55:14 +00:00
|
|
|
LDFLAGS::=$(shell aalib-config --libs)
|
2024-03-02 00:23:29 +00:00
|
|
|
endif
|
2024-02-20 15:27:24 +00:00
|
|
|
|
2024-02-20 02:12:57 +00:00
|
|
|
ifeq "${ADDRESS_SANITIZE}" "1"
|
|
|
|
CFLAGS += -fsanitize=address -ggdb
|
|
|
|
LDFLAGS += -fsanitize=address -fsanitize=undefined -fsanitize=leak
|
|
|
|
endif
|
|
|
|
|
2024-02-16 18:11:58 +00:00
|
|
|
all:${MAIN_ROM}
|
2024-02-03 18:03:37 +00:00
|
|
|
|
2024-01-29 13:03:43 +00:00
|
|
|
first: ${OBJECT_FILES}
|
|
|
|
${QUIET_LINK}
|
2024-02-20 15:36:12 +00:00
|
|
|
${Q}gcc -ggdb $^ $(shell pkg-config --libs ncursesw) -lm -o $@ ${LDFLAGS}
|
2024-02-20 02:12:57 +00:00
|
|
|
|
|
|
|
gprof:
|
|
|
|
gprof first -b|less
|
2024-01-22 12:11:07 +00:00
|
|
|
|
2024-02-03 18:03:37 +00:00
|
|
|
%.rom:%.asm first
|
|
|
|
$(QUIET_FAS)
|
2024-02-16 17:06:27 +00:00
|
|
|
${Q}./first -i $< -a $@
|
2024-02-03 18:03:37 +00:00
|
|
|
|
2024-03-02 23:26:35 +00:00
|
|
|
auxiliary_progs/%:auxiliary_progs/%.c
|
|
|
|
${QUIET_CC}
|
|
|
|
${Q}gcc $< -DUSE_AALIB=${USE_AALIB} -Wall -Wextra -Werror -O2 -o $@
|
|
|
|
|
|
|
|
|
|
|
|
programs/utah_teapot.asm: auxiliary_progs/stl_to_source_code ${UTAH_TEAPOT_ASCII_STL} programs/3d_renderer.asm
|
|
|
|
${QUIET_STL_CONV}
|
|
|
|
${Q}cat programs/3d_renderer.asm >> "$@_"
|
|
|
|
${Q}auxiliary_progs/stl_to_source_code < "${UTAH_TEAPOT_ASCII_STL}" >> "$@_"
|
|
|
|
${Q}mv "$@_" "$@"
|
|
|
|
|
|
|
|
programs/cube.asm: programs/cube_data.asm programs/3d_renderer.asm
|
|
|
|
${Q}cat programs/3d_renderer.asm programs/cube_data.asm > "$@"
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
%.o:%.c
|
2024-01-29 13:03:43 +00:00
|
|
|
${QUIET_CC}
|
2024-03-02 00:23:29 +00:00
|
|
|
${Q}gcc -c $< -DUSE_AALIB=${USE_AALIB} -Wall -Wextra -Werror ${CFLAGS}
|
2024-01-22 12:11:07 +00:00
|
|
|
|
2024-02-26 19:04:54 +00:00
|
|
|
callgrind.out:first ${MAIN_ROM}
|
|
|
|
${QUIET_VALGRIND}
|
|
|
|
${Q}if ldd first |grep asan > /dev/null;\
|
|
|
|
then\
|
2024-02-26 22:11:30 +00:00
|
|
|
rm -f "$@";\
|
2024-02-26 19:04:54 +00:00
|
|
|
echo ERROR: Binary build with libasan, please rebuild without address sanitiser;\
|
|
|
|
else\
|
2024-03-02 23:26:35 +00:00
|
|
|
valgrind --tool=callgrind --dump-instr=yes --simulate-cache=yes --collect-jumps=yes --callgrind-out-file=callgrind.out ./first -i programs/utah_teapot.rom;\
|
2024-02-26 19:04:54 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
profile: callgrind.out
|
|
|
|
kcachegrind $<
|
|
|
|
|
2024-01-22 12:11:07 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2024-01-29 13:03:43 +00:00
|
|
|
${QUIET_CLEAN}
|
2024-03-02 23:26:35 +00:00
|
|
|
${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out programs/cube.asm programs/utah_teapot.asm ${AXIL_PROGS}
|