1 #PLATFORM ?= x86_64-linux-gnu
2 PLATFORM ?= x86_64-w64-mingw32
4 CC ::= x86_64-w64-mingw32-cc
6 BUILDDIR ?= target/$(PLATFORM)
9 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
10 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
11 -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
12 LDFLAGS ::= $(LDFLAGS)
13 LDLIBS ::= -L/usr/x86_64-w64-mingw32/bin -lm -lopengl32 -lglew32 -lglfw3 -lassimp $(LDLIBS)
25 engine/performance.c \
36 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
38 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
39 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
41 # Set executable name for the platform
42 # TODO Base this on target platform instead of host OS
43 #ifeq ($(OS),Windows_NT)
48 binary ::= $(BUILDDIR)/shadowclad.exe
49 #binary ::= $(BUILDDIR)/shadowclad #$(binext)
55 # Default rule: build executable
58 @echo "Linking executable"
59 $(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
61 # Build C translation units
62 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
65 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
71 # Initialise build environment
73 @echo "Creating build directory $(BUILDDIR)"
95 # Generate C prerequisite makefiles
96 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
98 @echo "Generating prerequisites for $<"
99 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
100 # Give the same prerequisites to the prerequisite makefile,
101 # so that it is regenerated whenever any of said prerequisites change
102 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
104 # Include generated C prerequisites
105 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
107 # Do not automatically delete generated prerequisites
108 .SECONDARY: $(depfiles)
115 @echo "Removing $(BUILDDIR)"