This repository has been archived by the owner on Sep 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMakefile
171 lines (143 loc) · 3.38 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
Q=@
QQ=@
LD=$(CC)
TARGET_TETRIS:=tetris
TARGET_TEST:=test
CJSON:=deps/cJSON
MUNIT:=deps/munit
LIBF8:=deps/libf8
ifeq ($(wildcard $(MUNIT)/*),)
NOTEST=1
endif
SRC:=src
BUILD:=build
TARGET:=$(BUILD)/target
MEDIA:=media
SOURCES:=$(wildcard $(SRC)/*.c)
SOURCES+=$(wildcard $(SRC)/$(MEDIA)/*.c)
OBJECTS:=$(SOURCES:$(SRC)/%.c=$(BUILD)/%.c.o)
DEPENDS:=$(OBJECTS:.o=.d)
ifdef PREFIX
INCLUDE+=$(PREFIX)/include
endif
INCLUDE+=include
INCLUDE+=$(CJSON)
INCLUDE+=$(MUNIT)
INCLUDE+=$(LIBF8)
INCLUDE:=$(INCLUDE:%=-I%)
#COMMON+=-fsanitize=address
CFLAGS+=$(COMMON)
CFLAGS+=$(INCLUDE)
CFLAGS+=-Wall
CFLAGS+=-Wextra
CFLAGS+=-Wpedantic
CFLAGS+=-Wno-microsoft-anon-tag
# CSFML headers used SFML 2.5.1 have some deprecated structs involved
CFLAGS+=-Wno-deprecated-declarations
CFLAGS+=-std=c11
CFLAGS+=-fms-extensions
CFLAGS+=-g3
CFLAGS+=-Og
CFLAGS+=-MD
CFLAGS+=$(EXTRA_CFLAGS)
ifdef PREFIX
LDFLAGS+=-L$(PREFIX)/lib
endif
LDFLAGS+=$(COMMON)
LDFLAGS+=$(EXTRA_LDFLAGS)
ifdef SFML_STATIC
LDFLAGS+=-lsfml-graphics-s
LDFLAGS+=-lsfml-window-s
LDFLAGS+=-lsfml-system-s
ifeq ($(OS),Windows_NT)
CFLAGS+=-DCSFML_STATIC
LDFLAGS+=-lstdc++
LDFLAGS+=-static
LDFLAGS+=-static-libgcc
LDFLAGS+=-static-libstdc++
LDFLAGS+=-lfreetype
LDFLAGS+=-lopengl32
LDFLAGS+=-lgdi32
LDFLAGS+=-lwinmm
LDFLAGS+=-mwindows
else
UNAME_S:=$(shell uname -s)
ifeq ($(UNAME_S),Linux)
LDFLAGS+=-pthread
LDFLAGS+=-lstdc++
LDFLAGS+=-lm
LDFLAGS+=-lfreetype
LDFLAGS+=-lX11
LDFLAGS+=-lXrandr
LDFLAGS+=-ldl
LDFLAGS+=-lGL
LDFLAGS+=-ludev
endif
ifeq ($(UNAME_S),Darwin)
LDFLAGS+=-framework OpenGL
LDFLAGS+=-framework AppKit
LDFLAGS+=-framework IOKit
LDFLAGS+=-framework Carbon
LDFLAGS+=-lfreetype
LDFLAGS+=-lc++
LDFLAGS+=-ObjC
endif
endif # ($(OS),Windows_NT)
else # SFML_STATIC
ifdef PREFIX
LDFLAGS+=-Wl,-rpath=$(PREFIX)/lib
endif
endif # SFML_STATIC
LDFLAGS_TETRIS+=-lcsfml-graphics
LDFLAGS_TETRIS+=-lcsfml-window
LDFLAGS_TETRIS+=-lcsfml-system
LDFLAGS_TETRIS+=$(LDFLAGS)
LDFLAGS_TEST+=$(LDFLAGS)
#======================================================================
all:
all: $(TARGET_TETRIS)
ifndef NOTEST
all: $(TARGET_TEST)
endif
.PHONY: pg
pg:
$(MAKE) -f pg.mk $@ PREFIX=$(PREFIX)
$(TARGET_TETRIS): $(OBJECTS) $(TARGET)/$(TARGET_TETRIS).c.o $(LIBF8)/libf8.a \
$(CJSON)/cJSON.o
$(QQ) echo " LD $@"
$(Q) $(LD) -o $@ $^ $(LDFLAGS_TETRIS)
$(TARGET_TEST): $(TARGET)/$(TARGET_TEST).c.o $(MUNIT)/munit.c.o
$(QQ) echo " LD $@"
$(Q) $(LD) -o $@ $^ $(LDFLAGS_TEST)
$(DEPENDS): | $(BUILD)/ $(TARGET)/
$(OBJECTS): | $(BUILD)/ $(TARGET)/ $(BUILD)/$(MEDIA)/
$(BUILD)/$(MEDIA)/:
$(Q) mkdir -p $@
$(BUILD)/:
$(Q) mkdir -p $@
$(TARGET)/:
$(Q) mkdir -p $@
$(LIBF8)/libf8.a: $(LIBF8)
$(MAKE) -C $< NOTEST=1
$(CJSON)/cJSON.c.o: $(CJSON)/cJSON.c
$(QQ) echo " CC $@"
$(Q) $(CC) -c $(CFLAGS) -o $@ $<
$(MUNIT)/munit.c.o: $(MUNIT)/munit.c
$(QQ) echo " CC $@"
$(Q) $(CC) -c $(CFLAGS) -o $@ $<
$(BUILD)/%.c.o: $(SRC)/%.c
$(QQ) echo " CC $@"
$(Q) $(CC) -c $(CFLAGS) -o $@ $<
-include $(DEPENDS)
clean:
$(Q) $(RM) -rfv $(OBJECTS) $(DEPENDS) \
$(TARGET_TETRIS) $(TARGET_TEST) \
$(TARGET)/$(TARGET_TETRIS).c.o $(TARGET)/$(TARGET_TETRIS).c.d \
$(TARGET)/$(TARGET_TEST).c.o $(TARGET)/$(TARGET_TEST).c.d
$(MAKE) -f pg.mk $@
mrproper: clean
$(Q) $(RM) -rfv $(BUILD) \
$(MUNIT)/*.d $(MUNIT)/*.o \
$(CJSON)/*.d $(CJSON)/*.o
$(MAKE) -C $(LIBF8) clean
.PHONY: all clean mrproper