-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
185 lines (142 loc) · 5 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# SPDX-License-Identifier: BSD-2-Clause
# Copyright (c) 2019 Netronome Systems, Inc.
KEFIR_VERSION = 0
KEFIR_PATCHLEVEL = 1
KEFIR_EXTRAVERSION = 0
KEFIR_FULLVERSION = $(KEFIR_VERSION).$(KEFIR_PATCHLEVEL).$(KEFIR_EXTRAVERSION)
SRC = src/
DOC = doc/
TESTS = tests/
OUTPUT = build/
PREFIX ?= /usr/local
OBJECTS := $(wildcard $(SRC)*.c)
OBJECTS := $(patsubst %.c,%.o,$(OBJECTS))
OBJECTS := $(patsubst $(SRC)%,$(OUTPUT)%,$(OBJECTS))
LIBBPF_DIR = libbpf/src
LIBBPF_OBJECT = $(LIBBPF_DIR)/libbpf.a
LIBBPF_HDR_DIR = $(OUTPUT)headers
LIBBPF_HDRS = $(LIBBPF_HDR_DIR)$(PREFIX)/include/bpf/bpf.h
LIBKEFIR_A = $(OUTPUT)libkefir.a
LIBKEFIR_SO = $(OUTPUT)libkefir.so
PC_FILE = $(OUTPUT)libkefir.pc
W ?= 1
ifeq ($(W), 1)
EXTRA_WARNINGS += -Wbad-function-cast
EXTRA_WARNINGS += -Wdeclaration-after-statement
EXTRA_WARNINGS += -Wformat-security
EXTRA_WARNINGS += -Wformat-y2k
EXTRA_WARNINGS += -Winit-self
EXTRA_WARNINGS += -Wmissing-declarations
EXTRA_WARNINGS += -Wmissing-prototypes
EXTRA_WARNINGS += -Wnested-externs
EXTRA_WARNINGS += -Wno-system-headers
EXTRA_WARNINGS += -Wold-style-definition
EXTRA_WARNINGS += -Wpacked
EXTRA_WARNINGS += -Wredundant-decls
EXTRA_WARNINGS += -Wshadow
EXTRA_WARNINGS += -Wstrict-prototypes
EXTRA_WARNINGS += -Wundef
EXTRA_WARNINGS += -Wwrite-strings
EXTRA_WARNINGS += -Wformat
# EXTRA_WARNINGS += -Wswitch-default # Warning from src/jsmn.c
# EXTRA_WARNINGS += -Wswitch-enum
endif
CFLAGS ?= -g -Wall -Wextra -Wpedantic $(EXTRA_WARNINGS)
CFLAGS += -fPIC
CFLAGS += -I$(LIBBPF_HDR_DIR)$(PREFIX)/include/
CFLAGS += -fvisibility=hidden
all: $(LIBKEFIR_A) $(LIBKEFIR_SO) $(PC_FILE)
ifeq ($(Q), @)
SILENCE = -s
endif
$(LIBBPF_OBJECT):
@if [ ! -d $(LIBBPF_DIR) ]; then \
echo "Error: Need libbpf submodule"; \
echo "May need to run git submodule update --init"; \
exit 1; \
fi
$(Q)$(MAKE) $(SILENCE) -C $(LIBBPF_DIR) all
$(LIBBPF_HDRS): $(LIBBPF_OBJECT)
@mkdir -p $(LIBBPF_HDR_DIR)
$(Q)DESTDIR=../../$(LIBBPF_HDR_DIR) PREFIX=$(PREFIX) \
$(MAKE) $(SILENCE) -C $(LIBBPF_DIR) install_headers
$(LIBKEFIR_SO): $(LIBKEFIR_SO).$(KEFIR_FULLVERSION)
$(Q)ln -sf $(^F) $@
$(Q)ln -sf $(^F) $(OUTPUT)libkefir.so.$(KEFIR_VERSION)
$(LIBKEFIR_SO).$(KEFIR_FULLVERSION): $(OBJECTS)
$(Q)$(CC) $(CFLAGS) -shared \
-Wl,-soname,libkefir.so.$(KEFIR_FULLVERSION) -o $@ $^
$(LIBKEFIR_A): $(OBJECTS)
$(Q)$(RM) -- $@; $(AR) rcs $@ $^
$(OUTPUT)%.o: $(SRC)%.c $(LIBBPF_OBJECT) $(LIBBPF_HDRS)
@mkdir -p $(OUTPUT)
$(Q)$(CC) $(CFLAGS) $(LDFLAGS) -c -o $@ $< \
-DKEFIR_VERSION=$(KEFIR_VERSION) \
-DKEFIR_PATCHLEVEL=$(KEFIR_PATCHLEVEL) \
-DKEFIR_EXTRAVERSION=$(KEFIR_EXTRAVERSION)
kefir-clean:
$(Q)$(RM) -r -- $(OUTPUT)
$(Q)$(RM) -- $(wildcard $(SRC)*.gch)
clean: kefir-clean
$(Q)$(MAKE) -C $(LIBBPF_DIR) clean
.PHONY: all kefir-clean clean
# Documentation
doc:
$(Q)$(MAKE) -C $(DOC) html
doc-clean:
$(Q)$(MAKE) -C $(DOC) clean
.PHONY: doc doc-clean
# Code checks
IWYU_DEP := $(shell command -v include-what-you-use 2>/dev/null)
iwyu-dep:
ifndef IWYU_DEP
$(error "include-what-you-use not found, cannot check included headers")
endif
iwyu: CC = include-what-you-use
iwyu: iwyu-dep kefir-clean all
.PHONY: iwyu-dep iwyu
azan: CC = $(CLANG) -fsanitize=address -fno-omit-frame-pointer
azan: kefir-clean all
.PHONY: azan
# Tests
tests: $(LIBKEFIR_A) $(LIBBPF_OBJECT) $(LIBBPF_HDRS)
$(Q)$(MAKE) -C $(TESTS)
tests-clean:
$(Q)$(MAKE) -C $(TESTS) clean
.PHONY: tests tests-clean
# Package config file
$(PC_FILE):
@mkdir -p $(OUTPUT)
$(Q)sed -e "s|@PREFIX@|$(PREFIX)|" \
-e "s|@LIBDIR@|$(PREFIX)/$(LIBDIR)|" \
-e "s|@VERSION@|$(KEFIR_VERSION)|" \
< $(SRC)libkefir.pc.template > $@
# Installation
INSTALL = install
DESTDIR ?= ''
DESTPREF = $(DESTDIR)$(PREFIX)
LIBDIR = lib
install_headers:
$(Q)$(INSTALL) -d -m 755 $(DESTPREF)/include/kefir
$(Q)$(INSTALL) -t $(DESTPREF)/include/kefir -m 644 $(SRC)libkefir.h
install_lib: all
@if ! pkg-config --libs libbpf >/dev/null 2>&1; then \
>&2 echo "WARNING: libkefir requires libbpf, you may want to install it as well"; fi
$(Q)$(INSTALL) -d -m 755 $(DESTPREF)/$(LIBDIR)
$(Q)cp -fpt $(DESTPREF)/$(LIBDIR) $(LIBKEFIR_A) $(LIBKEFIR_SO).$(KEFIR_FULLVERSION)
$(Q)ln -sf $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO)).$(KEFIR_FULLVERSION) \
$(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO)).$(KEFIR_VERSION)
$(Q)ln -sf $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO)).$(KEFIR_FULLVERSION) \
$(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO))
install_pkgconfig: $(PC_FILE)
$(Q)$(INSTALL) -d -m 755 $(DESTPREF)/$(LIBDIR)/pkgconfig
$(Q)$(INSTALL) -m 644 -t $(DESTPREF)/$(LIBDIR)/pkgconfig $<
install: install_headers install_lib install_pkgconfig
uninstall:
$(Q)$(RM) -r -- $(DESTPREF)/include/kefir
$(Q)$(RM) -- $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO))
$(Q)$(RM) -- $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO).$(KEFIR_VERSION))
$(Q)$(RM) -- $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_SO).$(KEFIR_FULLVERSION))
$(Q)$(RM) -- $(DESTPREF)/$(LIBDIR)/$(notdir $(LIBKEFIR_A))
$(Q)$(RM) -- $(DESTPREF)/$(LIBDIR)/pkgconfig/$(notdir $(PC_FILE))
.PHONY: install install_headers install_lib install_pkgconfig uninstall