1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
8 -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
10 LDLIBS ::= -lm -lGL -lGLEW -lglfw -lassimp $(LDLIBS)
22 engine/performance.c \
33 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
35 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
36 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
38 # Set executable name for the platform
39 # TODO Base this on target platform instead of host OS
40 #ifeq ($(OS),Windows_NT)
45 binary ::= $(BUILDDIR)/shadowclad #$(binext)
51 # Default rule: build executable
54 @echo "Linking executable"
55 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
57 # Build C translation units
58 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
61 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
67 # Initialise build environment
69 @echo "Creating build directory $(BUILDDIR)"
91 # Generate C prerequisite makefiles
92 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
94 @echo "Generating prerequisites for $<"
95 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
96 # Give the same prerequisites to the prerequisite makefile,
97 # so that it is regenerated whenever any of said prerequisites change
98 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
100 # Include generated C prerequisites
101 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
103 # Do not automatically delete generated prerequisites
104 .SECONDARY: $(depfiles)
111 @echo "Removing $(BUILDDIR)"