-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
87 lines (69 loc) · 2.25 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
# Default to using GCC
CC = gcc
CXX = g++
# Compiler flags
RELEASE_CFLAGS = -O2 -pipe
DEBUG_CFLAGS = -g -pipe
RELEASE_CXXFLAGS = $(RELEASE_CFLAGS) -std=c++20
DEBUG_CXXFLAGS = $(DEBUG_CFLAGS) -std=c++20
# Directory containing source files
SRC_DIR = tools
# Source files (which should be not compiled)
SRCS_C = $(filter-out $(SRC_DIR)/rewritten-original-dll/%.c, $(shell find $(SRC_DIR) -name '*.c'))
SRCS_CPP = $(filter-out $(SRC_DIR)/rewritten-original-dll/%.cpp, $(shell find $(SRC_DIR) -name '*.cpp'))
# Object files
OBJS_C = $(patsubst $(SRC_DIR)/%.c,binaries/%.o,$(SRCS_C))
OBJS_CPP = $(patsubst $(SRC_DIR)/%.cpp,binaries/%.o,$(SRCS_CPP))
# Executables
TARGETS_C = $(patsubst $(SRC_DIR)/%.c,binaries/%,$(SRCS_C))
TARGETS_CPP = $(patsubst $(SRC_DIR)/%.cpp,binaries/%,$(SRCS_CPP))
# Default rule
all: release
# Release target
release: CFLAGS = $(RELEASE_CFLAGS)
release: CXXFLAGS = $(RELEASE_CXXFLAGS)
release: $(TARGETS_C) $(TARGETS_CPP)
# Debug target
debug: CFLAGS = $(DEBUG_CFLAGS)
debug: CXXFLAGS = $(DEBUG_CXXFLAGS)
debug: $(TARGETS_C) $(TARGETS_CPP)
# Rule to compile each C source file to object file
binaries/%.o: $(SRC_DIR)/%.c
@mkdir -p $(@D)
@echo "-------------------------------------------------------------"
@echo "| Compiling C $(@D) |"
@echo "-------------------------------------------------------------"
@$(CC) $(CFLAGS) -c -o $@ $<
@echo
# Rule to compile each C++ source file to object file
binaries/%.o: $(SRC_DIR)/%.cpp
@mkdir -p $(@D)
@echo "-------------------------------------------------------------"
@echo "| Compiling C++ $(@D) |"
@echo "-------------------------------------------------------------"
@$(CXX) $(CXXFLAGS) -c -o $@ $<
@echo
# Rule to build each C program
$(TARGETS_C): binaries/%: binaries/%.o
@$(CC) $(CFLAGS) -o $@ $^
# Rule to build each C++ program
$(TARGETS_CPP): binaries/%: binaries/%.o
@$(CXX) $(CXXFLAGS) -o $@ $^
# Clean rule
clean:
@rm -f $(OBJS_C) $(OBJS_CPP)
@rm -rf binaries
@echo "Cleanup is done"
.PHONY: clean all
# Rule to use Clang
clang: CC = clang
clang: CXX = clang++
clang: release
# Rule to use Clang for debug
clang_debug: CC = clang
clang_debug: CXX = clang++
clang_debug: debug
recompile:
make clean
make
@echo "Recompilation is done"