rabbitizer/Makefile

85 lines
2.2 KiB
Makefile
Raw Normal View History

# Build options can be changed by modifying the makefile or by building with 'make SETTING=value'.
DEBUG ?= 0
WERROR ?= 0
ASAN ?= 0
EXPERIMENTAL ?= 0
CC := clang
IINC := -I include
CSTD := -std=c11
CFLAGS :=
LDFLAGS :=
2022-08-23 19:12:55 +00:00
WARNINGS := -Wall -Wextra -Wpedantic
# WARNINGS := -Wall -Wextra -Wpedantic -Wpadded
WARNINGS += -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werror=unused-function -Werror=unused-parameter -Werror=shadow
2022-07-10 20:04:39 +00:00
ifeq ($(CC),gcc)
WARNINGS += -Wno-cast-function-type
endif
ifeq ($(DEBUG),0)
OPTFLAGS := -O2 -g
else
OPTFLAGS := -O0 -g3
CFLAGS += -DDEVELOPMENT=1
endif
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
endif
ifneq ($(EXPERIMENTAL),0)
CFLAGS += -DEXPERIMENTAL
endif
2022-07-09 21:13:37 +00:00
SRC_DIRS := $(shell find src -type d)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c))
H_FILES := $(foreach dir,$(IINC),$(wildcard $(dir)/**/*.h))
O_FILES := $(foreach f,$(C_FILES:.c=.o),build/$f)
DEP_FILES := $(O_FILES:%.o=%.d)
# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
#### Main Targets ###
all: tests
clean:
$(RM) -rf build
distclean: clean
$(RM) -rf dist rabbitizer.egg-info .mypy_cache
format:
clang-format-11 -i -style=file $(C_FILES)
2022-07-09 21:13:37 +00:00
tidy:
2022-07-09 21:55:57 +00:00
clang-tidy-11 -p . --fix --fix-errors $(C_FILES) $(H_FILES) -- $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS)
2022-07-09 21:13:37 +00:00
tests: build/test.elf build/rsptest.elf build/r5900test.elf build/registersTrackerTest.elf
2022-07-09 21:13:37 +00:00
.PHONY: all clean distclean format tidy tests
.DEFAULT_GOAL := all
.SECONDARY:
#### Various Recipes ####
build/%.elf: %.c $(O_FILES)
2022-07-09 21:13:37 +00:00
$(CC) -MMD $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) $(LDFLAGS) -o $@ $^
build/%.o: %.c
2022-07-09 21:13:37 +00:00
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
$(CC) -MMD -c $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(CFLAGS) -o $@ $<
-include $(DEP_FILES)