-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (61 loc) · 2.3 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
69
70
71
72
73
74
75
CC := g++ -std=c++11
CFLAGS := -D WIN32_LEAN_AND_MEAN -Wall -Wextra -Iinclude -Wno-unused-parameter -Wno-write-strings -Wno-char-subscripts -Wno-unused-but-set-variable -Wno-unused-variable
SRC=./
SRCS=$(wildcard $(SRC)/*.cpp)
OBJS=$(patsubst %.cpp,%.o,$(SRCS))
DEPS=$(patsubst %.cpp,%.d,$(SRCS))
RCSS=$(wildcard $(SRC)/*.rc)
RCOS=$(patsubst %.rc,%.o,$(RCSS))
RCTS=$(patsubst %.rc,%.rct,$(RCSS))
EXECUTABLE := organyaa
LIBRARIES:= -L. -lWinMM -ldsound -mwindows -static-libgcc -static-libstdc++ -static
ifeq ($(shell uname),Linux)
LIBRARIES += -lm
endif
.PHONY: clean all
# Default behaviour is to make the executable
all: $(EXECUTABLE)
# This is the final compile step:
# take all the object files in $(SRC)/*.o and link them with the libraries
$(EXECUTABLE): $(OBJS) $(RCTS)
$(CC) $(OBJS) $(RCOS) $(LIBRARIES) -o $(EXECUTABLE)
# To generate the .d files, I use the -M* options.
DEPFLAGS = -MT $@ -MMD -MP -MF $(SRC)/$*.d
COMPILE.cpp = $(CC) $(DEPFLAGS) $(CFLAGS)
# To create a .o file, take the source code and create 2 files: the .o with the
# compiled code, and the .d with the dependency info
$(SRC)/%.o: $(SRC)/%.cpp
$(COMPILE.cpp) -c $< -o $@
$(SRC)/%.rct: $(SRC)/%.rc
windres $< $(SRC)/$*.o
cp $(SRC)/$*.o $(SRC)/$*.rct
# if the dependency doesnt exist, we dont have to worry because that means the
# corresponding object also doesnt exist. if the .d does exist then it will
# contain info about dependant header files. It will look something like this:
#
# $(SRC)/main.o: $(SRC)/main.cpp include/global.h include/graphics.h
# include/global.h:
# include/graphics.h:
# include/renderScene.h:
# include/input.h:
#
# meaning that if include/global.h, or include/graphics.h were updated (newer
# modified time than the .o file) then the above rule will need to be re run
# again, causing a recompile, then the recompile causes a relink and the new
# program is generated.
#
# Because the deps are optional, it may seem correct to use
#
# -include $(DEPS)
#
# but this is wrong becuase it will search in system directores for it as
# well. You can see this with `strace make -n 2>&1 | grep /include/src`.
# Wildcard will only include them if they exist.
#
include $(wildcard $(DEPS))
clean:
rm -f $(SRC)/*.o
rm -f $(SRC)/*.d
rm -f $(SRC)/*.rct
rm -f $(EXECUTABLE).exe
rm -f $(EXECUTABLE)