Files
gb-emu/Makefile
Max Regan 100704eb1a common: add simple bitmap image writer
This will be useful for initial testing of the video processor.
2018-06-30 09:45:50 -07:00

115 lines
2.4 KiB
Makefile

CONFIG=config.mak
include $(CONFIG)
COV_DIR=./coverage
APP_DIR=$(SRC_DIR)apps
CC=gcc
SHELL=/bin/bash
CCFLAGS += -std=c11 -D_POSIX_C_SOURCE=200809L
CCFLAGS += -I$(SRC_DIR)
CCFLAGS += -I/usr/include/glib-2.0/ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
LDFLAGS += -lglib-2.0
CCFLAGS += $(CCFLAGS_EXTRA)
LDFLAGS += $(LDFLAGS_EXTRA)
FILTER = $(foreach v,$(2),$(if $(findstring $(1),$(v)),$(v),))
C_SOURCES = $(shell find $(SRC_DIR) -name "*.c" -type f -print)
ALL_OBJS = $(patsubst $(SRC_DIR)/%.c, %.o, $(C_SOURCES))
APP_OBJS = $(filter apps/%, $(ALL_OBJS))
TEST_OBJS = $(call FILTER,/tests/, $(ALL_OBJS))
OBJS = $(filter-out $(TEST_OBJS) $(APP_OBJS), $(ALL_OBJS))
APPS = $(patsubst %.o, %, $(APP_OBJS))
.PHONY: all
all: $(APPS)
.PHONY: gbdb gbasm
gbdb: apps/gbdb
gbasm: apps/gbasm
threading: apps/threading
bmp: apps/bmp_test
.PHONY: gbasm-test tests threading bmp
TESTS = $(patsubst %.o, %, $(filter %/test.o, $(ALL_OBJS)))
tests: $(TESTS)
$(ALL_OBJS): $(CONFIG)
.SUFFIXES:
.PHONY: info
info:
$(info SRC_DIR is ${SRC_DIR})
$(info C_SOURCES is ${C_SOURCES})
$(info OBJSs is ${OBJS})
$(info ALL_OBJS is ${ALL_OBJS})
$(info APP_OBJS is ${APP_OBJS})
$(info TEST_OBJS is ${TEST_OBJS})
$(ALL_OBJS): %.o: $(SRC_DIR)/%.c $(CONFIG)
@echo " CC $@"
$(shell mkdir -p $(@D))
@$(CC) -c $(CCFLAGS) -o $@ $<
objs: $(OBJS)
$(info OBJS=$(OBJS))
.SECONDEXPANSION:
$(APPS) $(TESTS): $(OBJS) $$@.o
@echo " LD $@"
@$(shell mkdir -p $(@D))
@$(CC) $^ $(LDFLAGS) -o $@
.PHONY: check cov-report
define run_tests =
@for i in $(TESTS); do \
echo " TEST $$i"; \
$$i | sed 's/^/ /'; \
if [ $${PIPESTATUS[0]} -ne 0 ]; then \
exit 1; \
fi; \
done;
endef
.PHONY: check coverage coverage-report
check: $(TESTS)
$(run_tests)
COV_BASE=$(COV_DIR)cov_base.info
.PHONY: $(COV_BASE)
$(COV_BASE):
@mkdir -p $(COV_DIR)
@lcov -q -c -i -d ./ -o $(COV_BASE)
$(COV_DIR)coverage.info coverage: $(TESTS) $(COV_BASE)
$(call run_tests)
@lcov -q -c -d ./ -o $(COV_DIR)results.info -t results
@lcov -q -a $(COV_DIR)results.info -o $(COV_DIR)coverage.info
@lcov --summary $(COV_DIR)coverage.info
coverage-report: coverage
@mkdir -p $(COV_DIR)html/
@genhtml -q --prefix $(PWD) \
--output-directory=$(COV_DIR)html \
$(COV_DIR)coverage.info
.PHONY: clean realclean cov-clean
cov-clean:
@find ./ \( -iname *.gcno -o -iname *.gcda \) -delete
@rm -rf $(COV_DIR)
clean: cov-clean
@rm -f $(ALL_OBJS) $(APPS) $(TESTS)
realclean: clean
@rm -f $(CONFIG)