-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
84 lines (75 loc) · 2.08 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
CC := clang
OPT := -O0
OPTPROD := -O3 -Ofast
SRCDIR := src
BUILDDIR := build
INCLUDEDIR := include
TARGET := bin/cpu
SRCEXT := cpp
HEADEREXT := h
HEADERS := $(shell find $(INCLUDEDIR) -type f -name *.$(HEADEREXT))
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/$(basename $(notdir %)),$(SOURCES:.$(SRCEXT)=.o))
CPPSTD := c++17
CFLAGS := -std=$(CPPSTD) \
-g \
-Wall \
-Wextra \
-Werror \
-Wno-unused-private-field \
-ferror-limit=50 \
-ffast-math
CFLAGSPROD := -std=$(CPPSTD) \
-Wall \
-Wextra \
-Werror \
-Wno-unused-private-field \
-ferror-limit=1 \
-flto \
-ffast-math
LFLAGS_OSX := -lm \
-F/Library/Frameworks \
-framework sfml-window \
-framework sfml-audio \
-framework sfml-graphics \
-framework sfml-system
LFLAGS_LINUX := -lX11 -lm -lpthread -lsfml -lsfml-window -lsfml-audio -lsfml-graphics -lsfml-system
INC := -I libs -I $(INCLUDEDIR) -I/usr/local/Cellar/sfml/2.5.1/include -F/Library/Frameworks
LIB := -lstdc++
OS = $(shell uname -s)
ifeq ("$(OS)","Linux")
LFLAGS = $(LFLAGS_LINUX)
CFLAGS += -D LINUX
CFLAGS += -pthread
else
LFLAGS = $(LFLAGS_OSX)
CFLAGS += -D OSX
endif
$(TARGET): $(OBJECTS)
$(call colorecho, " Linking...", 2)
@$(CC) $(OBJECTS) $(CFLAGS) $(OPT) $(LIB) $(LFLAGS) -o $(TARGET)
$(call colorecho, " Built executable $(TARGET)", 2)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(dir $@)
$(call colorecho, " Building $@", 3)
@$(CC) $(CFLAGS) $(OPT) $(INC) -c -o $@ $<
$(call colorecho, " Built $@", 2)
production:
$(call colorecho, " Building production binary $(TARGET)", 2)
@$(CC) $(SOURCES) $(CFLAGSPROD) $(OPTPROD) $(INC) $(LIB) $(LFLAGS) -o $(TARGET)
clean:
$(call colorecho, " Cleaning...", 2)
@rm -rf $(BUILDDIR) $(TARGET)
rebuild:
@make clean
@make -j
format:
$(call colorecho, " Formatting...", 2)
@clang-format -i $(SOURCES) $(HEADERS) -style=file
.PHONY: whole clean rebuild format
# Create colored output
define colorecho
@tput setaf $2
@echo $1
@tput sgr0
endef