mirror of
https://github.com/Mercantec-GHC/h5-projekt-mst.git
synced 2026-08-27 05:37:39 +02:00
77 lines
1.7 KiB
Makefile
77 lines
1.7 KiB
Makefile
|
|
MAKEFLAGS += -j16
|
|
|
|
CXX=g++
|
|
LD=g++
|
|
CLANG_FORMAT=clang-format
|
|
|
|
CXXFLAGS = -std=c++23 -pedantic-errors -Wall -Wextra -Wconversion
|
|
LDFLAGS =
|
|
|
|
# libraries = ""
|
|
|
|
# CXXFLAGS += $(shell pkg-config $(libraries) --cflags)
|
|
# LDFLAGS += $(shell pkg-config $(libraries) --libs)
|
|
|
|
RELEASE = 0
|
|
GDB = 0
|
|
|
|
ifeq ($(RELEASE),1)
|
|
CXXFLAGS += -O3
|
|
else
|
|
CXXFLAGS += -g -Wno-unused
|
|
|
|
ifeq ($(GDB),1)
|
|
CXXFLAGS += -ggdb
|
|
else
|
|
CXXFLAGS += -fsanitize=address
|
|
endif
|
|
endif
|
|
|
|
build_dir = build
|
|
obj_dir = $(build_dir)/obj
|
|
src_dir = src
|
|
test_dir = tests
|
|
|
|
sources_without_main = $(shell find $(src_dir) -name '*.cpp' -and -not -name 'main.cpp')
|
|
main_source = src/main.cpp
|
|
sources = $(sources_without_main) $(main_source)
|
|
|
|
objects_without_main = $(sources_without_main:%.cpp=$(obj_dir)/%.o)
|
|
main_object = $(main_source:%.cpp=$(obj_dir)/%.o)
|
|
objects = $(objects_without_main) $(main_object)
|
|
|
|
target = $(build_dir)/backend
|
|
|
|
test_sources = $(shell find $(test_dir) -name '*.cpp')
|
|
test_objects = $(test_sources:$(test_dir)/%.cpp=$(obj_dir)/$(test_dir)/%.o)
|
|
test_targets = $(test_sources:$(test_dir)/%.cpp=$(build_dir)/$(test_dir)/test_%)
|
|
|
|
all: $(target) $(test_targets)
|
|
|
|
$(target): $(objects)
|
|
$(LD) -o $@ $(CXXFLAGS) $(LDFLAGS) $^
|
|
|
|
$(obj_dir)/%.o:%.cpp
|
|
@mkdir -p $(dir $@)
|
|
$(CXX) $< -c -o $@ -MMD -MP $(CXXFLAGS)
|
|
|
|
test: $(test_targets)
|
|
printf "%s\n" $^ | xargs -I % sh -c 'echo "- %..." && ./% && echo "- %: OK" || (echo "- %: FAILED" && exit 1)'
|
|
|
|
$(build_dir)/$(test_dir)/test_%: $(test_objects) $(objects_without_main)
|
|
@mkdir -p $(dir $@)
|
|
$(LD) -o $@ $(CXXFLAGS) $(LDFLAGS) $^
|
|
|
|
format:
|
|
$(CLANG_FORMAT) -style=file -i src/*
|
|
|
|
check:
|
|
$(CLANG_FORMAT) --dry-run --Werror -style=file src/*
|
|
|
|
clean:
|
|
rm -rf $(build_dir)
|
|
|
|
-include $(sources:%.cpp=$(obj_dir)/%.d) $(tests:%.cpp=$(obj_dir)/%.d)
|
|
|