-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
67 lines (51 loc) · 1.4 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
# General purpose Makefile v3.0 - by Gab
# Set default target as all
.DEFAULT_GOAL := all
# Directories
MAIN_SRCDIR = src
BINDIR = bin
OBJDIR = obj
MAIN_INCDIR = include
LIBDIR = lib
# Compiler
CC = g++
# Output
EXEC = nano-nn
# Change .cpp to .o
SRC = $(wildcard $(MAIN_SRCDIR)/*.cpp)
OBJ = $(addprefix $(OBJDIR)/,$(notdir $(SRC:.cpp=.o)))
# Get all inc dirs
MULTI_INCDIR = $(wildcard $(MAIN_INCDIR)/*/)
ALL_INCDIR = -I $(MAIN_INCDIR) $(addprefix -I , $(MULTI_INCDIR))
# Flags
CFLAGS = $(ALL_INCDIR) -Wall -Wextra -pedantic -std=c++17 -fopenmp -O3 -march=native -mavx2 -mfma
DBGFLAGS = -g -fno-inline
LFLAGS = -L $(LIBDIR) -fopenmp
ifeq ($(OS),Windows_NT)
LFLAGS += -l:raylib.dll
else
LFLAGS += -l:libraylib.a -ldl
endif
ifeq ($(DEBUG),YES)
CFLAGS := $(CFLAGS) $(DBGFLAGS)
endif
# Ignore these files
.PHONY : compile all run clean valgrind
# Compile source to outputs .o
compile: $(OBJ)
$(OBJDIR)/%.o: $(MAIN_SRCDIR)/%.cpp
$(CC) -c $(CFLAGS) $< -o $@
# Link everything together
all: compile
$(CC) -o $(BINDIR)/$(EXEC) $(OBJDIR)/*.o $(LFLAGS)
# Run the program
run:
(cd $(BINDIR) && ./$(EXEC) $(ARGS))
# Delete the program and build files
clean:
rm -f $(BINDIR)/$(EXEC)
rm -f $(BINDIR)/$(EXEC).exe
rm -f $(OBJDIR)/*.o
# Run valgrind to search for memory leaks
valgrind:
(cd $(BINDIR) && valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt ./$(EXEC) $(ARGS))