Files

164 lines
4.9 KiB
Makefile
Raw Permalink Normal View History

# Build options can be changed by modifying the makefile or by building with 'make SETTING=value'.
2024-04-13 15:04:04 -04:00
# It is also possible to override the settings in Defaults in a file called .make_options as 'SETTING=value'.
-include .make_options
DEBUG ?= 0
WERROR ?= 0
ASAN ?= 0
EXPERIMENTAL ?= 0
2022-10-09 17:51:47 -03:00
SANITY_CHECKS ?= 1
CC := clang
2022-10-09 17:51:47 -03:00
CXX := clang++
AR := ar
2023-05-02 19:01:54 -04:00
IINC := -I tables -I include
IINC_XX := -I tables -I include -I cplusplus/include
CSTD := -std=c11
2022-10-09 17:51:47 -03:00
CXXSTD := -std=c++17
2023-05-01 20:59:01 -04:00
CFLAGS := -fPIC -fno-common
CXXFLAGS := -fPIC -fno-common
LDFLAGS := -Lbuild -lrabbitizer
2022-10-09 17:51:47 -03:00
LDXXFLAGS := -Lbuild -lrabbitizerpp
2023-11-11 13:19:56 -03:00
WARNINGS := -Wall -Wextra -Wpedantic -Wunused-value
2023-05-01 20:59:01 -04:00
WARNINGS += -Wformat=2 -Wundef
# WARNINGS += -Wconversion
WARNINGS += -Werror=vla -Werror=switch -Werror=implicit-fallthrough -Werror=unused-function
WARNINGS += -Werror=unused-parameter -Werror=shadow -Werror=switch -Werror=double-promotion
2022-10-10 20:23:18 -03:00
WARNINGS_C := -Werror=implicit-function-declaration -Werror=incompatible-pointer-types
2023-12-25 15:02:15 -03:00
WARNINGS += -Werror=type-limits
2022-10-10 20:23:18 -03:00
WARNINGS_CXX :=
2024-04-11 10:50:31 -04:00
WARNINGS_ELFS := -Wno-override-init
2022-07-10 16:04:39 -04:00
ifeq ($(CC),gcc)
2024-04-03 12:43:12 -03:00
WARNINGS += -Wno-cast-function-type -Wformat-truncation -Wformat-overflow -Wno-nonnull-compare
2022-07-10 16:04:39 -04:00
endif
ifeq ($(DEBUG),0)
2022-10-09 17:51:47 -03:00
OPTFLAGS := -Os -g
else
OPTFLAGS := -O0 -g3
CFLAGS += -DDEVELOPMENT=1
2022-10-09 17:51:47 -03:00
CXXFLAGS += -DDEVELOPMENT=1
endif
ifneq ($(WERROR),0)
WARNINGS += -Werror
endif
ifneq ($(ASAN),0)
CFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
2022-10-09 17:51:47 -03:00
CXXFLAGS += -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined
endif
ifneq ($(EXPERIMENTAL),0)
CFLAGS += -DEXPERIMENTAL
2022-10-09 17:51:47 -03:00
CXXFLAGS += -DEXPERIMENTAL
endif
ifneq ($(SANITY_CHECKS),0)
CFLAGS += -DRAB_SANITY_CHECKS=1
CXXFLAGS += -DRAB_SANITY_CHECKS=1
endif
2022-07-09 17:13:37 -04: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)
2022-10-09 17:51:47 -03:00
SRCXX_DIRS := $(shell find cplusplus/src -type d)
CXX_FILES := $(foreach dir,$(SRCXX_DIRS),$(wildcard $(dir)/*.cpp))
HXX_FILES := $(foreach dir,$(IINC_XX),$(wildcard $(dir)/**/*.hpp))
OXX_FILES := $(foreach f,$(CXX_FILES:.cpp=.o),build/$f)
2024-04-22 13:15:58 -04:00
TESTS_DIRS := $(shell find tests -mindepth 1 -type d -not -path "tests/asm*")
2022-10-12 11:26:28 -03:00
TESTS_C := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.c))
TESTS_CXX := $(foreach dir,$(TESTS_DIRS),$(wildcard $(dir)/*.cpp))
TESTS_ELFS := $(foreach f,$(TESTS_C:.c=.elf) $(TESTS_CXX:.cpp=.elf),build/$f)
2024-04-11 10:27:57 -04:00
DEP_FILES := $(O_FILES:%.o=%.d) $(OXX_FILES:%.o=%.d) $(TESTS_ELFS:%.elf=%.d)
STATIC_LIB := build/librabbitizer.a
DYNAMIC_LIB := build/librabbitizer.so
2022-10-09 17:51:47 -03:00
STATIC_LIB_XX := build/librabbitizerpp.a
DYNAMIC_LIB_XX := build/librabbitizerpp.so
# create build directories
2022-10-09 17:51:47 -03:00
$(shell mkdir -p $(foreach dir,$(SRC_DIRS) $(SRCXX_DIRS) $(TESTS_DIRS),build/$(dir)))
# Dependencies of libraries
$(STATIC_LIB): $(O_FILES)
$(DYNAMIC_LIB): $(O_FILES)
$(STATIC_LIB_XX): $(O_FILES) $(OXX_FILES)
$(DYNAMIC_LIB_XX): $(O_FILES) $(OXX_FILES)
#### Main Targets ###
all: static tests
2022-10-09 17:51:47 -03:00
static: $(STATIC_LIB) $(STATIC_LIB_XX)
dynamic: $(DYNAMIC_LIB) $(DYNAMIC_LIB_XX)
2023-05-02 19:01:54 -04:00
tables:
make -C tables
2023-04-30 08:48:47 -04:00
2024-03-11 09:17:29 -03:00
cleantables:
make -C tables distclean
clean:
$(RM) -rf build
distclean: clean
2022-12-16 11:04:16 -03:00
$(RM) -rf dist *.egg-info .mypy_cache
2023-05-02 19:01:54 -04:00
$(RM) -rf $(DEP_FILES)
2022-12-23 21:41:45 -03:00
$(RM) -rf target/
2023-05-02 19:01:54 -04:00
make -C tables distclean
format:
clang-format-11 -i -style=file $(C_FILES)
2022-10-09 17:51:47 -03:00
clang-format-11 -i -style=file $(CXX_FILES)
2022-07-09 17:13:37 -04:00
tidy:
2022-12-19 15:12:12 -03:00
clang-tidy-11 -p . --fix --fix-errors $(C_FILES) -- $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(WARNINGS_C) $(CFLAGS)
2022-07-09 17:13:37 -04:00
2022-10-12 11:26:28 -03:00
tests: $(TESTS_ELFS)
2024-03-17 11:19:32 -03:00
.PHONY: all static dynamic tables cleantables clean distclean format tidy tests
.DEFAULT_GOAL := all
.SECONDARY:
#### Various Recipes ####
2022-12-15 16:55:31 -03:00
build/%.elf: %.c $(STATIC_LIB)
2024-04-11 10:50:31 -04:00
$(CC) -MMD -MP $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(WARNINGS_C) $(WARNINGS_ELFS) $(CFLAGS) -o $@ $< $(LDFLAGS)
2022-12-15 16:55:31 -03:00
build/%.elf: %.cpp $(STATIC_LIB_XX)
2024-04-11 10:50:31 -04:00
$(CXX) -MMD -MP $(CXXSTD) $(OPTFLAGS) $(IINC_XX) $(WARNINGS) $(WARNINGS_CXX) $(WARNINGS_ELFS) $(CXXFLAGS) -o $@ $< $(LDXXFLAGS)
2022-10-09 17:51:47 -03:00
build/%.a:
$(AR) rcs $@ $^
2022-10-09 17:51:47 -03:00
build/%.so:
$(CC) -shared -o $@ $^
2023-05-02 19:01:54 -04:00
build/%.o: %.c
2022-07-09 17:13:37 -04:00
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
2022-12-15 16:55:31 -03:00
$(CC) -MMD -MP -c $(CSTD) $(OPTFLAGS) $(IINC) $(WARNINGS) $(WARNINGS_C) $(CFLAGS) -o $@ $<
2022-07-09 17:13:37 -04:00
2023-05-02 19:01:54 -04:00
build/%.o: %.cpp
2022-10-09 17:51:47 -03:00
# The -MMD flags additionaly creates a .d file with the same name as the .o file.
2022-12-15 16:55:31 -03:00
$(CXX) -MMD -MP -c $(CXXSTD) $(OPTFLAGS) $(IINC_XX) $(WARNINGS) $(WARNINGS_CXX) $(CXXFLAGS) -o $@ $<
2022-10-09 17:51:47 -03:00
2022-07-09 17:13:37 -04:00
-include $(DEP_FILES)
2022-10-12 11:26:28 -03:00
# Print target for debugging
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true