CROSS_COMPILE ?= 
CC := $(CROSS_COMPILE)gcc
STRIP := $(CROSS_COMPILE)strip
CFLAGS += -g -Wall -Iip2region
LIBS = -static
BIN := denyip

# 使用shell命令获取库的链接选项
LIBPCAP := $(shell pkg-config --libs --static libpcap)
LIBCAP := $(shell pkg-config --libs --static libcap)
LIBIPSET := $(shell pkg-config --libs --static libipset)

all: $(BIN)  # 默认目标

ipquery:  # Go 构建目标
	cd IP_region_query && CGO_ENABLED=0 go build -ldflags '-w -s'

$(BIN): cap.o common.o ip2region/ip2region.o ip2region/xdb_searcher.o libipset.o
	$(CC) $(CFLAGS) -o $(BIN) $^ $(LIBPCAP) $(LIBCAP) $(LIBIPSET) $(LIBS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -rf $(BIN) ipquery
	rm -rf cap.o common.o ip2region/ip2region.o ip2region/xdb_searcher.o libipset.o
