1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror $(CFLAGS)
9 LDLIBS ::= -L/usr/local/lib -lGL -lGLEW -lglut -lassimp $(LDLIBS)
18 engine/performance.c \
25 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
27 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
28 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
30 # Set executable name for the platform
31 # TODO Base this on target platform instead of host OS
32 #ifeq ($(OS),Windows_NT)
37 binary ::= $(BUILDDIR)/shadowclad #$(binext)
43 # Default rule: build executable
46 @echo "Linking executable"
47 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
49 # Build C translation units
50 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
53 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
59 # Initialise build environment
61 @echo "Creating build directory $(BUILDDIR)"
72 @LD_LIBRARY_PATH=/usr/local/lib $(binary)
83 # Generate C prerequisite makefiles
84 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
86 @echo "Generating prerequisites for $<"
87 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
88 # Give the same prerequisites to the prerequisite makefile,
89 # so that it is regenerated whenever any of said prerequisites change
90 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
92 # Include generated C prerequisites
93 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
95 # Do not automatically delete generated prerequisites
96 .SECONDARY: $(depfiles)
103 @echo "Removing $(BUILDDIR)"