]> git.lizzy.rs Git - shadowclad.git/blobdiff - Makefile
Also yeah divide by zero is a thing
[shadowclad.git] / Makefile
index d4307a25433418814ccb1beef6cbc8b0162a0a61..3ee9546e99e1a155e3240080867c1248b1e690cc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,45 @@
+# Copyright 2018-2020 Iwo 'Outfrost' Bujkiewicz
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
 PLATFORM ?= x86_64-linux-gnu
 
 BUILDDIR ?= target/$(PLATFORM)
 SRCDIR ?= src
 
-CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic $(CFLAGS)
+CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
+CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
+           -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
 LDFLAGS ::= $(LDFLAGS)
-LDLIBS ::= -L/usr/local/lib -lGL -lGLEW -lglut -lassimp $(LDLIBS)
+LDLIBS ::= -lm -lGL -lGLEW -lglfw -lassimp $(LDLIBS)
 
 # ######
 # Paths
 # ######
 
-vpath %.c $(SRCDIR)
-vpath %.h $(SRCDIR)
-
 sources ::= main.c \
-            asset.c \
-            level.c \
-            logger.c \
-            performance.c \
-            player.c \
-            render.c \
-            tga.c \
-            ui.c
-
-objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(sources)))
-depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(sources)))
+            engine/asset.c \
+            engine/engine.c \
+            engine/geometry.c \
+            engine/input.c \
+            engine/logger.c \
+            engine/performance.c \
+            engine/render.c \
+            engine/scene.c \
+            engine/string.c \
+            engine/tga.c \
+            engine/ui.c \
+            game/game.c \
+            game/input.c \
+            game/level.c \
+            game/player.c
+
+srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
+
+objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
+depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
 
 # Set executable name for the platform
 # TODO Base this on target platform instead of host OS
@@ -41,21 +55,26 @@ binary ::= $(BUILDDIR)/shadowclad #$(binext)
 # ######
 
 # Default rule: build executable
-$(binary): $(objects) | $(BUILDDIR)
-       @echo "###### Linking executable..."
-       $(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
+$(binary): $(objects)
+       @mkdir -p $(@D)
+       @echo "Linking executable"
+       @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
 
 # Build C translation units
-$(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk | $(BUILDDIR)
-       $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
+$(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
+       @mkdir -p $(@D)
+       @echo "Building $@"
+       @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
 
 # ######
 # Setup
 # ######
 
-# Create build directory
-$(BUILDDIR):
-       mkdir -p $(BUILDDIR)
+# Initialise build environment
+init:
+       @echo "Creating build directory $(BUILDDIR)"
+       @mkdir -p $(BUILDDIR)
+.PHONY: init
 
 # ######
 # Aliases
@@ -64,13 +83,9 @@ $(BUILDDIR):
 # Build and run
 run: $(binary)
        @echo
-       LD_LIBRARY_PATH=/usr/local/lib $(binary)
+       @$(binary)
 .PHONY: run
 
-# Initialise build environment
-init: $(BUILDDIR)
-.PHONY: init
-
 # Build executable
 shadowclad: $(binary)
 .PHONY: shadowclad
@@ -80,9 +95,12 @@ shadowclad: $(binary)
 # ######
 
 # Generate C prerequisite makefiles
-$(BUILDDIR)/%.c.mk: %.c Makefile | $(BUILDDIR)
+$(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
+       @mkdir -p $(@D)
        @echo "Generating prerequisites for $<"
        @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
+# Give the same prerequisites to the prerequisite makefile,
+# so that it is regenerated whenever any of said prerequisites change
        @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
 
 # Include generated C prerequisites
@@ -96,5 +114,6 @@ include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(d
 # ######
 
 clean:
-       rm -rf $(BUILDDIR)
+       @echo "Removing $(BUILDDIR)"
+       @rm -rf $(BUILDDIR)
 .PHONY: clean