-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
68 lines (53 loc) · 1.55 KB
/
Makefile
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
# Written by DJ Edmonson
# Warnings frequently signal eventual errors:
CXXFLAGS=`sdl-config --cflags` -g -W -Wall -Weffc++ -Wextra -pedantic -O0
# Linker flags for both OS X and Linux
LDFLAGS = `sdl-config --libs` -lSDL_ttf -lSDL_image -lexpat -lSDL_gfx -lSDL_mixer
# Generates list of object files from all the
# source files in directory
OBJS = $(addsuffix .o, $(basename $(shell find *.cpp)))
DEPS = $(OBJS:.o=.d)
# Set executable name
EXEC = run
# Declare the phony targets
.PHONY: echo clean r clang gcc setclang setgcc vg
# Phony targets to run dependencies in order
gcc: | setgcc $(EXEC)
clang: | setclang $(EXEC)
# For use with the clang static analyzer by
# using the environment variable for CXX
sb: | $(clean) $(EXEC)
vg: $(EXEC)
valgrind ./$(EXEC)
# Run the executable
r:
./$(EXEC)
clean:
rm -rf $(OBJS)
rm -rf $(DEPS)
rm -rf $(EXEC)
# Phony target to use clang for compile and linking
setclang:
@echo "Setting clang"
$(eval CXX = clang++)
$(eval CXX_LINK = clang++)
# Phony target to use g++ for compile and linking
setgcc:
@echo "Setting g++"
$(eval CXX = g++)
$(eval CXX_LINK = g++)
# $< refers to the first dependency
# Uses static pattern rule to keep from compiling all
# objects every time.
$(OBJS): %.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
$(DEPS): %.d: %.cpp
@echo "Generating "$@
@set -e; rm -f $@; \
g++ -MM $(CPPFLAGS) $< > $@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
# $@ refers to the target
$(EXEC): $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJS) $(LDFLAGS)
include $(DEPS)