-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
75 lines (58 loc) · 1.85 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
.ONESHELL:
# .SHELLFLAGS = -e
SHELL = /bin/sh
GIT = $(shell which git || /bin/false)
OUTPUT = ./output
BPF_SRC = ./bpf
LIBPCAP = ./libpcap
LIBPCAP_SRC = $(abspath $(LIBPCAP))
LIBPCAP_DIST_DIR ?= $(abspath $(OUTPUT)/libpcap)
LIBPCAP_HEADER_DIR = $(abspath $(LIBPCAP_DIST_DIR)/include)
LIBPCAP_OBJ_DIR = $(abspath $(LIBPCAP_DIST_DIR)/lib)
LIBPCAP_OBJ = $(abspath $(LIBPCAP_OBJ_DIR)/libpcap.a)
GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
VERSION ?= $(shell git describe --tags --abbrev=0)
CGO_CFLAGS_STATIC = "-I$(LIBPCAP_HEADER_DIR)"
CGO_LDFLAGS_STATIC = "-L$(LIBPCAP_OBJ_DIR) -lpcap $(LIBPCAP_OBJ)"
CGO_ENABLED ?= 1
GOARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)
LDFLAGS := -linkmode "external" -extldflags "-static"
CARCH ?= $(shell uname -m)
LIBPCAP_ARCH = $(CARCH)-unknown-linux-gnu
LIBPCAP_CC ?= gcc
.PHONY: libpcap
libpcap: $(LIBPCAP_OBJ)
$(LIBPCAP_OBJ): $(LIBPCAP_SRC)/pcap.h $(wildcard $(LIBPCAP_SRC)/*.[ch]) | $(LIBPCAP_DIST_DIR)
cd $(LIBPCAP_SRC) && \
sh autogen.sh && \
CC=$(LIBPCAP_CC) ./configure --disable-shared --disable-usb --disable-netmap --disable-bluetooth --disable-dbus --without-libnl \
--disable-rdma --host=$(LIBPCAP_ARCH) && \
$(MAKE) && \
$(MAKE) install prefix=$(LIBPCAP_DIST_DIR)
$(LIBPCAP_SRC)/pcap.h:
ifeq ($(wildcard $@), )
echo "INFO: updating submodule 'libpcap'"
$(GIT) submodule update --init --recursive
endif
$(LIBPCAP_DIST_DIR): $(LIBPCAP_SRC)
$(OUTPUT):
mkdir -p $(OUTPUT)
.PHONY: build
build: libpcap
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
CGO_ENABLED=1 go build -tags static -ldflags "$(LDFLAGS)"
.PHONY: test
test:
CGO_CFLAGS=$(CGO_CFLAGS_STATIC) \
CGO_LDFLAGS=$(CGO_LDFLAGS_STATIC) \
CGO_ENABLED=1 go test -v ./...
.PHONY: build-bpf
build-bpf:
go generate ./...
.PHONY: clean
clean:
$(MAKE) -C $(LIBPCAP_SRC) clean
rm -rf $(OUTPUT)
rm -f ./ktcpdump