From 1122308c157a749579a62fe59e7d800af70451b3 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Sun, 16 Jul 2023 00:20:38 +0200 Subject: [PATCH] Split project into smaller Makefiles Instead of controlling all logic from the top-level Makefile, splitting into directory-specific Makefiles allows for: - Better separation of concerns - Improved compatibility with POSIX make(1) As a possible drawback, support for out-of-tree builds has been removed, in favour of simplicity and POSIX compatibility. --- Assets/Art/Makefile | 20 ++++++++++++ Documentation/Makefile | 47 +++++++++++++++++++++++++++ Makefile | 72 +++++++++++------------------------------- Source/Makefile | 39 +++++++++++++++++++++++ Tests/Makefile | 15 +++++++++ 5 files changed, 140 insertions(+), 53 deletions(-) create mode 100644 Assets/Art/Makefile create mode 100644 Documentation/Makefile create mode 100644 Source/Makefile create mode 100644 Tests/Makefile diff --git a/Assets/Art/Makefile b/Assets/Art/Makefile new file mode 100644 index 0000000..987d95a --- /dev/null +++ b/Assets/Art/Makefile @@ -0,0 +1,20 @@ +.POSIX: +.SUFFIXES: .svg .png .bmp + +DEPS = \ + Botan_Map.png \ + Botan_Map_Old.png \ + Botan_Map_Old_2.png \ + World_Map.png \ + Controller.png \ + QWERTY_keyboard_diagram.png \ + Regular_truncation_10_1000.png \ + upload.wikimedia.org_wikipedia_commons_3_3f_Placeholder_view_vector.png + +all: $(DEPS) + +clean: + rm -f $(DEPS) + +.svg.png .bmp.png: + convert $< $@ diff --git a/Documentation/Makefile b/Documentation/Makefile new file mode 100644 index 0000000..bb15364 --- /dev/null +++ b/Documentation/Makefile @@ -0,0 +1,47 @@ +# This file is part of LibreWands. +# LibreWands is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# LibreWands is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreWands. If not, see https://www.gnu.org/licenses/. + +.POSIX: + +PROJECT = LibreWands.pdf +DEPS = \ + LibreWands.tex \ + Articles/Acquiring.tex \ + Articles/ConceptArt.tex \ + Articles/Controls.tex \ + Articles/Credits.tex \ + Articles/EngineDesign.tex \ + Articles/GameDesign.tex \ + Articles/GameplayIntroduction.tex \ + Articles/Introduction.tex \ + Articles/ItemEncyclopedia.tex \ + Articles/MapEditing.tex \ + Articles/MonsterEncyclopedia.tex \ + Articles/MoveEncyclopedia.tex \ + Articles/PackagingGuide.tex \ + Articles/Support.tex \ + Articles/WorkTimeline.tex \ + Articles/WorldEncyclopedia.tex \ + +all: $(PROJECT) + +install: $(PROJECT) + mkdir -p $(PREFIX)/doc + cp $(PROJECT) $(PREFIX)/doc + +clean: + rm -f $(PROJECT) + +$(PROJECT): $(DEPS) + pdflatex LibreWands.tex diff --git a/Makefile b/Makefile index 3f08dc4..e633137 100644 --- a/Makefile +++ b/Makefile @@ -12,69 +12,35 @@ # You should have received a copy of the GNU General Public License # along with LibreWands. If not, see https://www.gnu.org/licenses/. -version = 0.0.3 +.POSIX: + +PREFIX = /usr/local/ +BUILDDIR = Build/ +ARTDIR = $(BUILDDIR)/Art all: editMaps -install: editMaps - mkdir -p $(DESTDIR)/usr/ - mkdir -p $(DESTDIR)/usr/games/ - cp Build/librewands_editmaps $(DESTDIR)/usr/games/librewands_editmaps - +install: + +cd Source/ && $(MAKE) install PREFIX=$(PREFIX) + +cd Documentation/ && $(MAKE) install PREFIX=$(PREFIX) -install-pdf: - mkdir -p $(DESTDIR)/usr/ - mkdir -p $(DESTDIR)/usr/share/ - mkdir -p $(DESTDIR)/usr/share/doc/ - mkdir -p $(DESTDIR)/usr/share/doc/librewands/ - cp Build/LibreWands.pdf $(DESTDIR)/usr/share/doc/librewands/ +assets: + +cd Assets/Art/ && $(MAKE) BUILDDIR=$(BUILDDIR)/Art -uninstall: - rm $(DESTDIR)/usr/games/librewands_editmaps - -uninstall-pdf: - rm -r $(DESTDIR)/usr/share/doc/librewands/ - -pdf: - cd Build/;mkdir -p "Art" - convert "./Assets/Art/Botan_Map.svg" "Build/Art/Botan Map.png" - convert "./Assets/Art/Botan_Map_Old.svg" "Build/Art/Botan Map Old.png" - convert "./Assets/Art/Botan_Map_Old_2.bmp" "Build/Art/Botan Map Old 2.png" - convert "./Assets/Art/World_Map.svg" "Build/Art/World Map.png" - convert "./Assets/Art/Controller.svg" "Build/Art/Controller.png" - convert "./Assets/Art/commons.wikimedia.org_wiki_File:QWERTY_keyboard_diagram.svg" "Build/Art/commons.wikimedia.org_wiki_File:QWERTY_keyboard_diagram.png" - convert "./Assets/Art/commons.wikimedia.org_wiki_File:Regular_truncation_10_1000.svg" "Build/Art/commons.wikimedia.org_wiki_File:Regular_truncation_10_1000.png" - convert "./Assets/Art/upload.wikimedia.org_wikipedia_commons_3_3f_Placeholder_view_vector.svg" "Build/Art/upload.wikimedia.org_wikipedia_commons_3_3f_Placeholder_view_vector.png" - cd Build/;pdflatex ../Documentation/LibreWands.tex - -clean: - mkdir -p Build/ - rm -r Build/* - -dist: - mkdir -p "Build/librewands-$(version)" - cp -r "Assets/" "Build/librewands-$(version)" - cp -r "Documentation/" "Build/librewands-$(version)" - cp -r "Packaging/" "Build/librewands-$(version)" - cp -r "Source/" "Build/librewands-$(version)" - cp -r "Tests/" "Build/librewands-$(version)" - cp -r "Tools/" "Build/librewands-$(version)" - cp "_clang-format" "Build/librewands-$(version)" - cp "LICENSE" "Build/librewands-$(version)" - cp "Makefile" "Build/librewands-$(version)" - cp "README.md" "Build/librewands-$(version)" - cd Build/;tar -czf "librewands-$(version).tar.gz" "librewands-$(version)" +doc: assets + +cd Documentation/ && $(MAKE) editMaps: - cd Build/;gcc ../Source/editMaps.c -lncurses -O3 -o librewands_editmaps + +cd Source/ && $(MAKE) CFLAGS="-O3 -Wall" editMaps-debug: - cd Build/;gcc ../Source/editMaps.c -lncurses -g3 -Og -Wall -fanalyzer -o librewands_editmaps + +cd Source/ && $(MAKE) \ + CFLAGS="-Og -Wall -fanalyzer" \ + PROJECT=librewands_editmaps test: - cd Build/;gcc ../Tests/main.c -lncurses -g3 -Og -Wall -fanalyzer -o tests;./tests + +cd Tests/ && $(MAKE) format: - clang-format -i Source/* - clang-format -i Tests/* - + +cd Source/ && $(MAKE) format + +cd Tests/ && $(MAKE) format diff --git a/Source/Makefile b/Source/Makefile new file mode 100644 index 0000000..c434b99 --- /dev/null +++ b/Source/Makefile @@ -0,0 +1,39 @@ +# This file is part of LibreWands. +# LibreWands is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or (at your +# option) any later version. +# +# LibreWands is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +# Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LibreWands. If not, see https://www.gnu.org/licenses/. + +.POSIX: + +PROJECT = librewands +LIBS = -lncurses + +DEPS = \ + editMaps.o \ + engineCore.o \ + engineMaps.o \ + engineSound.o \ + playJoycon.o + +SRCS = $(DEPS:.o=.c) + +all: $(PROJECT) + +install: $(PROJECT) + mkdir -p $(PREFIX)/bin + cp $(PROJECT) $(PREFIX)/bin + +format: $(SRCS) + clang-format -i $(SRCS) + +$(PROJECT): $(DEPS) + $(CC) $(DEPS) $(LDFLAGS) $(LIBS) -o $@ diff --git a/Tests/Makefile b/Tests/Makefile new file mode 100644 index 0000000..d5a7f3b --- /dev/null +++ b/Tests/Makefile @@ -0,0 +1,15 @@ +.POSIX: + +PROJECT = test +DEPS = main.o +SRCS = $(DEPS:.o=.c) +LIBS = -lncurses +CFLAGS = -Wall -fanalyzer -Og -g3 + +all: $(PROJECT) + +$(PROJECT): $(DEPS) + $(CC) $(DEPS) $(LDFLAGS) $(LIBS) -o $@ + +format: $(SRCS) + clang-format -i $(SRCS)