-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
72 lines (49 loc) · 1.52 KB
/
Makefile
File metadata and controls
72 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
DC = gdc
LD = gdc
RM = rm -f
MKDIR = mkdir -p
LIBS = sdl SDL_image SDL_ttf
#DEBUGOPT = -O3 -frelease
DEBUGOPT = -ggdb3
DFLAGS = -Wall -Wextra -Wno-uninitialized -Wdeprecated -pedantic $(DEBUGOPT)
LDFLAGS = -use-ld=gold $(DEBUGOPT)
LIBFLAGS = $(shell pkg-config --libs $(LIBS))
DEPSDIR = .deps/
DEPEXT = dep
# Functions to generate a dependency file name or directory from a source or
# object file
depdir = $(dir $(1))$(DEPSDIR)
depfile = $(call depdir,$(1))$(basename $(notdir $(1))).$(DEPEXT)
SRC = $(wildcard *.d heap/*.d sdl/*.d)
OBJ = $(patsubst %.d,%.o,$(SRC))
DEPSDIRS = $(sort $(foreach DIR,$(SRC),$(call depdir,$(DIR))))
DEPSFILES = $(foreach DIR,$(SRC),$(call depfile,$(DIR)))
BIN = mazesolver
.PHONY: all
all: $(BIN)
$(BIN): $(OBJ) Makefile
$(LD) $(LDFLAGS) -o $@ $(OBJ) $(LIBFLAGS)
.SECONDEXPANSION:
%.o: DEPFILE = $(call depfile,$@)
%.o: DEPDIR = $(call depdir,$@)
%.o: %.d Makefile | $$(DEPDIR)
$(DC) -M -MF $(DEPFILE) -MT $@ -MT $(DEPFILE) $(DFLAGS) -o $@ -c $<
.PRECIOUS: $(DEPSDIR) %$(DEPSDIR)
$(DEPSDIR):
$(MKDIR) $@
%$(DEPSDIR):
$(MKDIR) $@
# Fix for gdc failing to detect transitive dependencies
gui.o: $(wildcard sdl/*.d)
# Use wildcards in order to only include the existing .dep files. This will
# prevent make from trying to rebuild them uselessly.
# Trying to rebuild them explicitely would fail as we don't have a rule for
# that.
-include $(wildcard $(addsuffix *.$(DEPEXT),$(DEPSDIRS)))
.PHONY: clean mrproper
clean:
$(RM) $(OBJ)
$(RM) $(DEPSFILES)
mrproper: clean
$(RM) $(BIN)
$(RM) -r $(DEPSDIRS)