-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
38 lines (38 loc) · 1.16 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
CXX = clang++
SOURCE = main.cpp
NAME = $(basename $(SOURCE))
BUILD_DIR = build
VERSION = $(shell git describe --tags --always --dirty="-dev" 2>/dev/null || echo "unknown")
MACHINE = $(shell $(CXX) -dumpmachine)
STACK_SIZE = 4294967296
CXXFLAGS = -std=c++20 -O3 -DSTACK_SIZE=$(STACK_SIZE)
ifeq ($(findstring linux,$(MACHINE)), linux)
EXE_EXT =
LDFLAGS = -Wl,-z,stack-size=$(STACK_SIZE)
else ifeq ($(findstring windows-msvc,$(MACHINE)), windows-msvc)
EXE_EXT = .exe
LDFLAGS = -Wl,/STACK:$(STACK_SIZE) -lUser32
else ifeq ($(findstring windows-gnu,$(MACHINE)), windows-gnu)
EXE_EXT = .exe
LDFLAGS = -Wl,--stack,$(STACK_SIZE) -static
else
$(error Unsupported platform: $(MACHINE))
endif
ifeq ($(DEBUG), 1)
CXXFLAGS += -g -fsanitize=address -fsanitize=undefined
VERSION := $(VERSION)-debug
endif
ifeq ($(USE_GMP), 1)
CXXFLAGS += -DUSE_GMP
LDFLAGS += -lgmp
TARGET = $(BUILD_DIR)/$(NAME)-$(VERSION)-$(MACHINE)-gmp$(EXE_EXT)
else
TARGET = $(BUILD_DIR)/$(NAME)-$(VERSION)-$(MACHINE)-nat$(EXE_EXT)
endif
.PHONY: all clean
all: $(TARGET)
$(TARGET) : $(SOURCE)
mkdir -p $(BUILD_DIR)
$(CXX) $(CXXFLAGS) $< -o $@ $(LDFLAGS)
clean:
rm -rf $(BUILD_DIR)