From e16a28dfdcd5797b3e28e76425e436ed8ffdb8f8 Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Thu, 18 Aug 2022 22:58:41 +0200 Subject: [PATCH] Separated makefile into smaller scripts to improve readability --- Makefile | 65 +++------------------------------------------- config.mk | 12 +++++++++ scripts/debug.mk | 11 ++++++++ scripts/release.mk | 9 +++++++ scripts/test.mk | 33 +++++++++++++++++++++++ 5 files changed, 69 insertions(+), 61 deletions(-) create mode 100644 config.mk create mode 100644 scripts/debug.mk create mode 100644 scripts/release.mk create mode 100644 scripts/test.mk diff --git a/Makefile b/Makefile index e1ec4cb..40e9964 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,4 @@ -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/expected/ -Ilib/ut/ -Ilib/midi/include -Iinclude/ -Ilib/bestline/ -RELEASE_FLAGS=-O3 -DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug -CXX=g++ - -LDFLAGS=-L./lib/midi/ -LDLIBS=-lmidi-alsa -lasound -lpthread +include config.mk Obj= \ builtin_functions.o \ @@ -25,72 +17,23 @@ Obj= \ 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 include/*.hh - @echo "CXX $@" - @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c - -bin/musique: $(Release_Obj) bin/main.o bin/bestline.o include/*.hh lib/midi/libmidi-alsa.a - @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 bin/bestline.o include/*.hh - @echo "CXX $@" - @$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $(Debug_Obj) bin/bestline.o bin/debug/main.o $(LDFLAGS) $(LDLIBS) - -bin/debug/%.o: src/%.cc include/*.hh - @echo "CXX $@" - @$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $< -c +include scripts/debug.mk +include scripts/release.mk +include scripts/test.mk 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 include/*.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: rm -rf bin coverage diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..1f01122 --- /dev/null +++ b/config.mk @@ -0,0 +1,12 @@ +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/expected/ -Ilib/ut/ -Ilib/midi/include -Iinclude/ -Ilib/bestline/ + +RELEASE_FLAGS=-O3 +DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug + +CXX=g++ + +LDFLAGS=-L./lib/midi/ +LDLIBS=-lmidi-alsa -lasound -lpthread diff --git a/scripts/debug.mk b/scripts/debug.mk new file mode 100644 index 0000000..d6b5dd5 --- /dev/null +++ b/scripts/debug.mk @@ -0,0 +1,11 @@ +Debug_Obj=$(addprefix bin/debug/,$(Obj)) + +debug: bin/debug/musique + +bin/debug/musique: $(Debug_Obj) bin/debug/main.o bin/bestline.o include/*.hh + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $(Debug_Obj) bin/bestline.o bin/debug/main.o $(LDFLAGS) $(LDLIBS) + +bin/debug/%.o: src/%.cc include/*.hh + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) $(DEBUG_FLAGS) $(CPPFLAGS) -o $@ $< -c diff --git a/scripts/release.mk b/scripts/release.mk new file mode 100644 index 0000000..b6e66c1 --- /dev/null +++ b/scripts/release.mk @@ -0,0 +1,9 @@ +Release_Obj=$(addprefix bin/,$(Obj)) + +bin/%.o: src/%.cc include/*.hh + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c + +bin/musique: $(Release_Obj) bin/main.o bin/bestline.o include/*.hh lib/midi/libmidi-alsa.a + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/bestline.o bin/main.o $(LDFLAGS) $(LDLIBS) diff --git a/scripts/test.mk b/scripts/test.mk new file mode 100644 index 0000000..17c6283 --- /dev/null +++ b/scripts/test.mk @@ -0,0 +1,33 @@ +Tests= \ + context.o \ + environment.o \ + interpreter.o \ + lex.o \ + main.o \ + number.o \ + parser.o \ + unicode.o \ + value.o + +Test_Obj=$(addprefix bin/debug/tests/,$(Tests)) + +test: unit-tests + etc/tools/test.py test examples + +unit-tests: bin/unit-tests + ./$< + +bin/unit-tests: $(Test_Obj) $(Debug_Obj) + @echo "CXX $@" + @$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(DEBUG_FLAGS) -o $@ $^ + +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