-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
91 lines (74 loc) · 2.12 KB
/
Makefile
File metadata and controls
91 lines (74 loc) · 2.12 KB
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
# Lishex (codename 1F98A), a UCI chess engine built in C++
# Copyright (C) 2023 Michal Kurek
#
# Lishex is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Lishex is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
CXX ?= g++
CXXFLAGS ?= -Wall -Wextra -Wpedantic -Wshadow -std=c++20 -mpopcnt -m64 -mbmi2
# For faster compilation
CPUS := $(shell nproc)
MAKEFLAGS += --jobs=$(CPUS)
SRC_DIR = src
BUILD_DIR = build
TARGET = lishex
ifeq ($(OS), Windows_NT)
SUFFIX := .exe
CXXFLAGS += -static
CXX = x86_64-w64-mingw32-c++.exe
else
SUFFIX :=
endif
EXE := $(TARGET)$(SUFFIX)
### Debugging (gdb)
debug ?= no
ifeq ($(debug),yes)
CXXFLAGS += -ggdb -DDEBUG -w
endif
### Sanitizers
sanitize ?= no
ifeq ($(sanitize),yes)
CXXFLAGS += -fsanitize=thread
endif
### Optimizations (on by default)
optimize ?= yes
ifeq ($(optimize),yes)
ifneq ($(debug),yes)
CXXFLAGS += -Ofast -fno-exceptions -pipe -flto=auto
endif
endif
# List of source files
SRCS = $(wildcard $(SRC_DIR)/*.cpp)
# List of object files
OBJS = $(patsubst $(SRC_DIR)/%.cpp,$(BUILD_DIR)/%.o,$(SRCS))
all: $(TARGET)
# Compile source files into object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
### $(CXX) $(CXXFLAGS) $(INC_DIRS) -c $< -o $@
# Link object files into executable
$(TARGET): $(OBJS)
$(CXX) $(CXXFLAGS) $^ -o $(EXE)
.PHONY: help run clean
# Clean the build directory
clean:
rm -f $(BUILD_DIR)/*.o $(EXE)
# Run the executable
run: $(TARGET)
./$(TARGET)
help:
@echo "To compile LiSHeX, type: "
@echo "make"
@echo "To compile with debug options, type: "
@echo "make debug=yes"
@echo "To compile without optimizations, type: "
@echo "make optimize=no"