diff --git a/Makefile b/Makefile index afaf38e..9094130 100644 --- a/Makefile +++ b/Makefile @@ -2,16 +2,61 @@ CROSS_COMPILE ?= CC := $(CROSS_COMPILE)gcc STRIP := $(CROSS_COMPILE)strip CFLAGS += -g -Wall -Iip2region -LIBS = +LIBS = -static BIN := denyip + +# 检测操作系统并设置相应的变量 +OS := $(shell if cat /etc/issue | grep -i 'ubuntu' >/dev/null 2>&1; then \ + echo ubuntu; \ + elif test -f /etc/debian_version; then \ + echo debian; \ + elif test -f /etc/centos-release; then \ + echo centos; \ + else \ + echo unsupported; \ + fi) + +OS_VER := $(shell if [ "$(OS)" = "ubuntu" ]; then \ + cat /etc/issue | head -n1 | awk '{print $$2}'; \ + elif [ "$(OS)" = "debian" ]; then \ + cat /etc/debian_version; \ + elif [ "$(OS)" = "centos" ]; then \ + cat /etc/centos-release | grep -o -E '[0-9.]{3,}' 2>/dev/null; \ + else \ + echo "N/A"; \ + fi) + +KERNEL := $(shell uname -sr) +ARCH := $(shell uname -m) + + + # 使用shell命令获取库的链接选项 -LIBPCAP := $(shell pkg-config --libs --static libpcap) +ifeq ($(OS), centos) + LIBPCAP := /usr/lib64/libpcap.so + LIBS = +else + LIBPCAP := $(shell pkg-config --libs --static libpcap) +endif LIBCAP := $(shell pkg-config --libs --static libcap) LIBIPSET := $(shell pkg-config --libs --static libipset) all: $(BIN) # 默认目标 +# 系统信息打印目标 +info: + @echo "Operating System: $(OS)" + @echo "OS Version: $(OS_VER)" + @echo "Kernel Version: $(KERNEL)" + @echo "Architecture: $(ARCH)" + @echo "Compiler: $(CC)" + @echo "CFLAGS: $(CFLAGS)" + @echo "Libraries: $(LIBS)" + @echo "LIBPCAP: $(LIBPCAP)" + @echo "LIBCAP: $(LIBCAP)" + @echo "LIBIPSET: $(LIBIPSET)" + ipquery: # Go 构建目标 cd IP_region_query && CGO_ENABLED=0 go build -ldflags '-w -s' diff --git a/README.md b/README.md index 34787d4..6c8efa7 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,12 @@ sudo apt update sudo apt install build-essential golang libpcap-dev libcap-dev libsystemd-dev ``` +在 Centos 7 系统上安装所需的开发工具和库: + +```bash +yum install ipset-devel libattr-devel libpcap-devel libcap-devel +``` + ### 下载项目 克隆项目仓库: diff --git a/cap.o b/cap.o index 1e8f84b..9c3cab1 100644 Binary files a/cap.o and b/cap.o differ diff --git a/denyip b/denyip index 399cedc..438710a 100644 Binary files a/denyip and b/denyip differ