Skip to content

Commit

Permalink
Update Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderLSF committed Nov 20, 2023
1 parent 9a90a4b commit 758b6e1
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,46 @@
CC := g++
CXXFLAGS := -std=c++20

# Build flags
BUILD_FLAGS ?= -O3

# Directories
WORKDIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
SRCDIR := $(WORKDIR)/src
INCDIRS := $(shell find $(SRCDIR) -type d)

# Source files
SRCS := $(shell find $(SRCDIR) -name "*.cpp")
# 判断处理器架构并设置相应的编译参数
ifeq ($(shell uname -m),x86_64)
DEFINES := -D_GNU_SOURCE
ifneq ($(shell grep -c avx512f /proc/cpuinfo),0)
ARCH_FLAGS := -march=native -mavx512f -mavx512bw -mavx512vl -mavx512dq
else ifneq ($(shell grep -c avx2 /proc/cpuinfo),0)
ARCH_FLAGS := -mavx2
else ifneq ($(shell grep -c sse4_2 /proc/cpuinfo),0)
ARCH_FLAGS := -march=native -msse4.2
endif
ifneq ($(shell grep -c '^physical id' /proc/cpuinfo | sort -u | wc -l),1)
LIBS += -lnuma
else
DEFINES += -DDISABLE_NUMA
endif
else ifeq ($(shell uname -m),aarch64)
ARCH_FLAGS := -march=armv8-a+simd -mcpu=native -mfpu=neon
DEFINES += -DDISABLE_NUMA
endif

CFLAGS := $(ARCH_FLAGS) $(DEFINES) -Wall

LIBS += -lpthread -lm

TARGET := ./main
SRCS := $(shell find ./src -name "*.cpp")
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)

# Includes
INCLUDES := $(addprefix -I,$(INCDIRS))

# Libraries
LIBS := -pthread -lm -lnuma

# Target
TARGET := $(WORKDIR)/main

# Compiler flags
CFLAGS := -mavx512f -mavx512bw -mavx512vl -mavx512dq -D_GNU_SOURCE -Wall $(INCLUDES)
INCLUDES := $(shell find ./src -name "*.h" -o -name "*.hpp" | xargs dirname | sort -u | awk '{printf "-I%s ", $$0}')

.PHONY: all clean

all: $(TARGET)

$(TARGET): $(OBJS)
$(CC) $(CXXFLAGS) $(CFLAGS) $(BUILD_FLAGS) -o $@ $^ $(LIBS)
$(CC) -o $@ $^ $(CXXFLAGS) $(CFLAGS) $(LIBS)

%.o: %.cpp
$(CC) $(CXXFLAGS) $(CFLAGS) $(BUILD_FLAGS) -c $< -o $@
$(CC) -c -o $@ $< $(CXXFLAGS) $(CFLAGS) $(INCLUDES)

clean:
rm -f $(OBJS) $(TARGET)

0 comments on commit 758b6e1

Please sign in to comment.