forked from turing-machines/mentals-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
86 lines (67 loc) · 2.34 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
TARGET_EXEC := mentals
BUILD_DIR := ./build
SRC_DIRS := ./src
LOGS_DIR := ./logs
VERBOSE ?= 0
# Find all the C and C++ files we want to compile
SRCS := $(shell find $(SRC_DIRS) -name '*.cpp' -or -name '*.c' -or -name '*.s')
# Prepends BUILD_DIR and appends .o to every src file
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
# String substitution for dependency files
DEPS := $(OBJS:.o=.d)
# Every folder in ./src will need to be passed to the compiler so that it can find header files
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
# Add Poppler include directory
POPPLER_INCLUDE := $(shell pkg-config --cflags-only-I poppler-cpp)
INC_FLAGS += $(POPPLER_INCLUDE)
# Conditional configuration for OS-specific flags
OS := $(shell uname -s)
ifeq ($(OS),Linux)
CPPFLAGS += -DLINUX
LDFLAGS := -lrt -lpthread -lcurl -lfmt -lpqxx -lpq $(shell pkg-config --libs poppler-cpp)
endif
ifeq ($(OS),Darwin)
CPPFLAGS += -DMACOS
LDFLAGS := -lpthread -lcurl -lfmt -lpqxx -lpq $(shell pkg-config --libs poppler-cpp)
endif
ifeq ($(OS),Windows_NT)
CPPFLAGS += -DWIN32
LDFLAGS := -lws2_32 -lcurl -lfmt -lpqxx -lpq
endif
ifeq ($(VERBOSE),1)
CXXFLAGS += -v
LDFLAGS += -v
endif
# The -MMD and -MP flags together generate Makefiles for us!
CPPFLAGS += $(INC_FLAGS) -MMD -MP #-D__PGVECTOR__
CXXFLAGS := -std=c++20 -Wall -Wextra -O3 -march=native # -Werror
# Default to clang if available and version is >= 14, otherwise use gcc
CXX := $(shell which clang++ || which g++)
CXX_VERSION := $(shell $(CXX) --version | grep -Po '(?<=version )[\d.]+' | head -n 1 | cut -d. -f1)
ifeq ($(CXX),$(shell which clang++))
ifneq ($(shell expr $(CXX_VERSION) \>= 14),1)
CXX := g++
endif
else
CXX := g++
endif
CC := $(CXX)
# Output chosen compiler and version
$(info $(shell echo "\033[0;33mUsing compiler: $(CXX) version $(CXX_VERSION)\033[0m"))
# The final build step.
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
# Build step for C++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean cleanlogs
clean:
rm -rf $(BUILD_DIR)
cleanlogs:
rm -rf $(LOGS_DIR)/*
# Include the .d makefiles. The - at the front suppresses errors of missing
# Makefiles. Initially, all the .d files will be missing, and we don't want those
# errors to show up.
-include $(DEPS)