Files
libbpf/src/Makefile

147 lines
3.8 KiB
Makefile
Raw Normal View History

# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
LIBBPF_VERSION := $(shell \
grep -oE '^LIBBPF_([0-9.]+)' libbpf.map | \
sort -rV | head -n1 | cut -d'_' -f2)
LIBBPF_MAJOR_VERSION := $(firstword $(subst ., ,$(LIBBPF_VERSION)))
TOPDIR = ..
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
INCLUDES := -I. -I$(TOPDIR)/include -I$(TOPDIR)/include/uapi
ALL_CFLAGS := $(INCLUDES)
FEATURE_REALLOCARRAY := $(shell $(TOPDIR)/scripts/check-reallocarray.sh)
ifneq ($(FEATURE_REALLOCARRAY),)
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
ALL_CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
endif
SHARED_CFLAGS += -fPIC -fvisibility=hidden -DSHARED
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
CFLAGS ?= -g -O2 -Werror -Wall
ALL_CFLAGS += $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
ALL_LDFLAGS += $(LDFLAGS)
ifdef NO_PKG_CONFIG
ALL_LDFLAGS += -lelf
else
PKG_CONFIG ?= pkg-config
ALL_CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf)
ALL_LDFLAGS += $(shell $(PKG_CONFIG) --libs libelf)
endif
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
OBJDIR ?= .
SHARED_OBJDIR := $(OBJDIR)/sharedobjs
STATIC_OBJDIR := $(OBJDIR)/staticobjs
OBJS := bpf.o btf.o libbpf.o libbpf_errno.o netlink.o \
nlattr.o str_error.o libbpf_probes.o bpf_prog_linfo.o xsk.o \
btf_dump.o hashmap.o
SHARED_OBJS := $(addprefix $(SHARED_OBJDIR)/,$(OBJS))
STATIC_OBJS := $(addprefix $(STATIC_OBJDIR)/,$(OBJS))
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
STATIC_LIBS := $(OBJDIR)/libbpf.a
ifndef BUILD_STATIC_ONLY
SHARED_LIBS := $(OBJDIR)/libbpf.so \
$(OBJDIR)/libbpf.so.$(LIBBPF_MAJOR_VERSION) \
$(OBJDIR)/libbpf.so.$(LIBBPF_VERSION)
VERSION_SCRIPT := libbpf.map
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
endif
HEADERS := bpf.h libbpf.h btf.h xsk.h libbpf_util.h \
bpf_helpers.h bpf_helper_defs.h bpf_tracing.h \
bpf_endian.h bpf_core_read.h
UAPI_HEADERS := $(addprefix $(TOPDIR)/include/uapi/linux/,\
bpf.h bpf_common.h btf.h)
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
PC_FILE := $(OBJDIR)/libbpf.pc
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
INSTALL = install
DESTDIR ?=
ifeq ($(shell uname -m),x86_64)
LIBSUBDIR := lib64
else
LIBSUBDIR := lib
endif
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
PREFIX ?= /usr
LIBDIR ?= $(PREFIX)/$(LIBSUBDIR)
INCLUDEDIR ?= $(PREFIX)/include
UAPIDIR ?= $(PREFIX)/include
TAGS_PROG := $(if $(shell which etags 2>/dev/null),etags,ctags)
all: $(STATIC_LIBS) $(SHARED_LIBS) $(PC_FILE)
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
$(OBJDIR)/libbpf.a: $(STATIC_OBJS)
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
$(AR) rcs $@ $^
$(OBJDIR)/libbpf.so: $(OBJDIR)/libbpf.so.$(LIBBPF_MAJOR_VERSION)
ln -sf $(^F) $@
$(OBJDIR)/libbpf.so.$(LIBBPF_MAJOR_VERSION): $(OBJDIR)/libbpf.so.$(LIBBPF_VERSION)
ln -sf $(^F) $@
$(OBJDIR)/libbpf.so.$(LIBBPF_VERSION): $(SHARED_OBJS)
$(CC) -shared -Wl,--version-script=$(VERSION_SCRIPT) \
-Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
$^ $(ALL_LDFLAGS) -o $@
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
$(OBJDIR)/libbpf.pc:
sed -e "s|@PREFIX@|$(PREFIX)|" \
-e "s|@LIBDIR@|$(LIBDIR)|" \
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
< libbpf.pc.template > $@
$(STATIC_OBJDIR):
mkdir -p $(STATIC_OBJDIR)
$(SHARED_OBJDIR):
mkdir -p $(SHARED_OBJDIR)
$(STATIC_OBJDIR)/%.o: %.c | $(STATIC_OBJDIR)
$(CC) $(ALL_CFLAGS) $(CPPFLAGS) -c $< -o $@
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
$(SHARED_OBJDIR)/%.o: %.c | $(SHARED_OBJDIR)
$(CC) $(ALL_CFLAGS) $(SHARED_CFLAGS) $(CPPFLAGS) -c $< -o $@
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
define do_install
if [ ! -d '$(DESTDIR)$2' ]; then \
$(INSTALL) -d -m 755 '$(DESTDIR)$2'; \
fi; \
$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR)$2'
endef
# Preserve symlinks at installation.
define do_s_install
if [ ! -d '$(DESTDIR)$2' ]; then \
$(INSTALL) -d -m 755 '$(DESTDIR)$2'; \
fi; \
cp -fpR $1 '$(DESTDIR)$2'
endef
install: all install_headers install_pkgconfig
$(call do_s_install,$(STATIC_LIBS) $(SHARED_LIBS),$(LIBDIR))
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
install_headers:
$(call do_install,$(HEADERS),$(INCLUDEDIR)/bpf,644)
Extend build and add install rules to Makefile Introduce multiple improvements to Makefile to make the build more flexible and support install: * Support overriding CFLAGS by user but keep required flags in place. ALL_FLAGS is used in Makefile as recommended in [1]. * Add additional BUILD_SHARED flag to build dynamically linked flavor of the library. If the flag is set, -fPIC is also passed to make it possible to build .so. * Support building in a separate directory provided by OBJDIR variable. * Add multiple install targets. By default the library itself and libbpf headers are installed (install target). UAPI headers can be optionally installed by user. * All installation paths, including PREFIX, library and include directories can be overridden. UAPI can be made different from include directory for libbpf headers. That makes it possible to keep latest <linux/bpf.h> in a place that doesn't conflict with the one installed e.g. by kernel-headers package and use it in user's build system. * Support DESTDIR (see [2]). * Support overriding LDFLAGS. * Use utilities such as rm directly as recommended in [3]. * Use compiler and related programs (such as ar) via make variables as recommended in [3]. * In clean rule remove all possible build artifacts not to rely on passed options (e.g. if build was done w/ BUILD_SHARED, but clean w/o it). * Document new build options in README. [1] https://www.gnu.org/software/make/manual/html_node/Command-Variables.html#Command-Variables [2] https://www.gnu.org/prep/standards/html_node/DESTDIR.html [3] https://www.gnu.org/software/make/manual/html_node/Utilities-in-Makefiles.html#Utilities-in-Makefiles Signed-off-by: Andrey Ignatov <rdna@fb.com>
2018-10-11 14:58:49 -07:00
# UAPI headers can be installed by a different package so they're not installed
# in by install rule.
install_uapi_headers:
$(call do_install,$(UAPI_HEADERS),$(UAPIDIR)/linux,644)
install_pkgconfig: $(PC_FILE)
$(call do_install,$(PC_FILE),$(LIBDIR)/pkgconfig,644)
clean:
rm -rf *.o *.a *.so *.so.* *.pc $(SHARED_OBJDIR) $(STATIC_OBJDIR)
.PHONY: cscope tags
cscope:
ls *.c *.h > cscope.files
cscope -b -q -f cscope.out
tags:
rm -f TAGS tags
ls *.c *.h | xargs $(TAGS_PROG) -a