musique/Makefile
2022-08-18 22:03:47 +02:00

115 lines
3.0 KiB
Makefile

MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)"
CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result -Wno-maybe-uninitialized
CPPFLAGS:=$(CPPFLAGS) \
-Ilib/bestline/ \
-Ilib/expected/ \
-Ilib/midi/include \
-Ilib/scheduler \
-Ilib/ut/ \
-Isrc/
RELEASE_FLAGS=-O3
DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug
CXX=g++
LDFLAGS=-L./lib/midi/ -L./lib/scheduler/
LDLIBS=-lscheduler -lmidi-alsa -lasound -lpthread
Bestline_Dependency = bin/bestline.o
Scheduler_Dependency = lib/scheduler/libscheduler.a
Midi_Dependency = lib/midi/libmidi-alsa.a
External_Dependencies = $(Scheduler_Dependency) $(Midi_Dependency) $(Bestline_Dependency)
Obj= \
context.o \
environment.o \
errors.o \
interpreter.o \
lexer.o \
lines.o \
location.o \
number.o \
parser.o \
pretty.o \
unicode.o \
unicode_tables.o \
value.o
Tests= \
context.o \
environment.o \
interpreter.o \
lex.o \
main.o \
number.o \
parser.o \
unicode.o \
value.o
Release_Obj=$(addprefix bin/,$(Obj))
Debug_Obj=$(addprefix bin/debug/,$(Obj))
Test_Obj=$(addprefix bin/debug/tests/,$(Tests))
all: bin/musique
test: unit-tests
etc/tools/test.py test examples
debug: bin/debug/musique
bin/%.o: src/%.cc src/*.hh
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c
lib/%.a:
(cd $(shell dirname $@); make)
bin/musique: $(Release_Obj) bin/main.o src/*.hh $(External_Dependencies)
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/bestline.o bin/main.o $(LDFLAGS) $(LDLIBS)
bin/debug/musique: $(Debug_Obj) bin/debug/main.o src/*.hh $(External_Dependencies)
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $(Debug_Obj) bin/bestline.o bin/debug/main.o $(LDFLAGS) $(LDLIBS)
bin/debug/%.o: src/%.cc src/*.hh
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $< -c
bin/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h
@echo "CC $@"
@$(CC) $< -c -O3 -o $@
unit-tests: bin/unit-tests
./$<
unit-test-coverage:
@which gcov >/dev/null || ( echo "[ERROR] gcov is required for test coverage report"; false )
@which gcovr >/dev/null || ( echo "[ERROR] gcovr is required for test coverage report"; false )
CXXFLAGS=--coverage $(MAKE) bin/unit-tests -B
bin/unit-tests
rm -rf coverage
mkdir coverage
gcovr -e '.*\.hpp' -e 'src/tests/.*' -e 'src/pretty.cc' --html --html-details -o coverage/index.html
rm -rf bin/debug
xdg-open coverage/index.html
doc: Doxyfile src/*.cc src/*.hh
doxygen
doc-open: doc
xdg-open ./doc/build/html/index.html
bin/unit-tests: $(Test_Obj) $(Debug_Obj)
@echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(DEBUG_FLAGS) -o $@ $^
clean: clean-dependencies
rm -rf bin coverage
clean-dependencies:
rm -f $(External_Dependencies)
.PHONY: clean clean-dependencies doc doc-open all test unit-tests
$(shell mkdir -p bin/debug/tests)