1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror -Wno-error=unused-function $(CFLAGS)
9 LDLIBS ::= -lGL -lGLEW -lglut -lassimp $(LDLIBS)
19 engine/performance.c \
27 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
29 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
30 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
32 # Set executable name for the platform
33 # TODO Base this on target platform instead of host OS
34 #ifeq ($(OS),Windows_NT)
39 binary ::= $(BUILDDIR)/shadowclad #$(binext)
45 # Default rule: build executable
48 @echo "Linking executable"
49 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
51 # Build C translation units
52 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
55 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
61 # Initialise build environment
63 @echo "Creating build directory $(BUILDDIR)"
85 # Generate C prerequisite makefiles
86 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
88 @echo "Generating prerequisites for $<"
89 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
90 # Give the same prerequisites to the prerequisite makefile,
91 # so that it is regenerated whenever any of said prerequisites change
92 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
94 # Include generated C prerequisites
95 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
97 # Do not automatically delete generated prerequisites
98 .SECONDARY: $(depfiles)
105 @echo "Removing $(BUILDDIR)"