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 -lglut -lassimp $(LDLIBS)
20 engine/performance.c \
28 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
30 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
31 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
33 # Set executable name for the platform
34 # TODO Base this on target platform instead of host OS
35 #ifeq ($(OS),Windows_NT)
40 binary ::= $(BUILDDIR)/shadowclad #$(binext)
46 # Default rule: build executable
49 @echo "Linking executable"
50 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
52 # Build C translation units
53 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
56 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
62 # Initialise build environment
64 @echo "Creating build directory $(BUILDDIR)"
86 # Generate C prerequisite makefiles
87 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
89 @echo "Generating prerequisites for $<"
90 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
91 # Give the same prerequisites to the prerequisite makefile,
92 # so that it is regenerated whenever any of said prerequisites change
93 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
95 # Include generated C prerequisites
96 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
98 # Do not automatically delete generated prerequisites
99 .SECONDARY: $(depfiles)
106 @echo "Removing $(BUILDDIR)"