QUIET=1 ADDRESS_SANITIZE=1 USE_AALIB=1 OBJECT_FILES=gui.o gui_display.o gui_internals.o main.o simdata.o assembly.o cpu.o MAIN_ROM=programs/utah_teapot.rom ROMS=test.rom ${MAIN_ROM} programs/cube.rom programs/quicksort.rom UTAH_TEAPOT_ASCII_STL=assets/Utah_teapot_ascii.stl AXIL_PROGS=auxiliary_progs/stl_to_source_code all:first ${ROMS} 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 '$@; QUIET_STL_CONV = @echo ' STL_TO_SOURCE_CODE '$@; Q = @ else Q = endif CFLAGS::=-O2 $(shell pkg-config ncursesw --cflags) ifeq "${USE_AALIB}" "1" CFLAGS::=$(shell pkg-config ncursesw --cflags) LDFLAGS::=$(shell aalib-config --libs) endif 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 $@ 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 > "$@" %.o:%.c ${QUIET_CC} ${Q}gcc -c $< -DUSE_AALIB=${USE_AALIB} -Wall -Wextra -Werror ${CFLAGS} callgrind.out:first ${MAIN_ROM} ${QUIET_VALGRIND} ${Q}if ldd first |grep asan > /dev/null;\ then\ rm -f "$@";\ 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/utah_teapot.rom;\ fi profile: callgrind.out kcachegrind $< .PHONY: clean clean: ${QUIET_CLEAN} ${Q} rm -f ${OBJECT_FILES} first ${ROMS} callgrind.out programs/cube.asm programs/utah_teapot.asm ${AXIL_PROGS}