xref: /linux/tools/lib/bpf/Makefile (revision dbb2a7a986971ef43d5a60d235c05491647e16f4)
11bc38b8fSAlexei Starovoitov# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
21b76c13eSWang Nan# Most of this file is copied from tools/lib/traceevent/Makefile
31b76c13eSWang Nan
4d71fa5c9SAlexei StarovoitovRM ?= rm
5e2bad142SMasahiro Yamadasrctree := $(realpath $(srctree))
6d71fa5c9SAlexei Starovoitov
761c7aa50SAndrii NakryikoVERSION_SCRIPT := libbpf.map
8dadb81d0SAndrii NakryikoLIBBPF_VERSION := $(shell \
961c7aa50SAndrii Nakryiko	grep -oE '^LIBBPF_([0-9.]+)' $(VERSION_SCRIPT) | \
10dadb81d0SAndrii Nakryiko	sort -rV | head -n1 | cut -d'_' -f2)
110b46b755SQuentin MonnetLIBBPF_MAJOR_VERSION := $(word 1,$(subst ., ,$(LIBBPF_VERSION)))
120b46b755SQuentin MonnetLIBBPF_MINOR_VERSION := $(word 2,$(subst ., ,$(LIBBPF_VERSION)))
131b76c13eSWang Nan
141b76c13eSWang NanMAKEFLAGS += --no-print-directory
151b76c13eSWang Nan
1655d554f5SShuah Khan# This will work when bpf is built in tools env. where srctree
1755d554f5SShuah Khan# isn't set and when invoked from selftests build, where srctree
1855d554f5SShuah Khan# is a ".". building_out_of_srctree is undefined for in srctree
1955d554f5SShuah Khan# builds
2055d554f5SShuah Khanifndef building_out_of_srctree
21e19b7ceeSUwe Kleine-Königsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
22d5ef3140SNaveen N. Raosrctree := $(patsubst %/,%,$(dir $(srctree)))
23d5ef3140SNaveen N. Raosrctree := $(patsubst %/,%,$(dir $(srctree)))
24d5ef3140SNaveen N. Rao#$(info Determined 'srctree' to be $(srctree))
25d5ef3140SNaveen N. Raoendif
261b76c13eSWang Nan
271b76c13eSWang NanINSTALL = install
281b76c13eSWang Nan
291b76c13eSWang Nan# Use DESTDIR for installing into a different root directory.
301b76c13eSWang Nan# This is useful for building a package. The program will be
311b76c13eSWang Nan# installed in this directory as if it was the root directory.
321b76c13eSWang Nan# Then the build tool can move it later.
331b76c13eSWang NanDESTDIR ?=
341b76c13eSWang NanDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
351b76c13eSWang Nan
36d5ef3140SNaveen N. Raoinclude $(srctree)/tools/scripts/Makefile.arch
37d5ef3140SNaveen N. Rao
381b76c13eSWang Nanifeq ($(LP64), 1)
391b76c13eSWang Nan  libdir_relative = lib64
401b76c13eSWang Nanelse
411b76c13eSWang Nan  libdir_relative = lib
421b76c13eSWang Nanendif
431b76c13eSWang Nan
441b76c13eSWang Nanprefix ?= /usr/local
451b76c13eSWang Nanlibdir = $(prefix)/$(libdir_relative)
461b76c13eSWang Nanman_dir = $(prefix)/share/man
471b76c13eSWang Nanman_dir_SQ = '$(subst ','\'',$(man_dir))'
481b76c13eSWang Nan
491b76c13eSWang Nanexport man_dir man_dir_SQ INSTALL
501b76c13eSWang Nanexport DESTDIR DESTDIR_SQ
511b76c13eSWang Nan
52eeedd352SStanislav Fomichevinclude $(srctree)/tools/scripts/Makefile.include
531b76c13eSWang Nan
541b76c13eSWang Nan# copy a bit from Linux kbuild
551b76c13eSWang Nan
561b76c13eSWang Nanifeq ("$(origin V)", "command line")
571b76c13eSWang Nan  VERBOSE = $(V)
581b76c13eSWang Nanendif
591b76c13eSWang Nanifndef VERBOSE
601b76c13eSWang Nan  VERBOSE = 0
611b76c13eSWang Nanendif
621b76c13eSWang Nan
635c816641SMasahiro YamadaINCLUDES = -I$(or $(OUTPUT),.) \
640b46b755SQuentin Monnet	   -I$(srctree)/tools/include -I$(srctree)/tools/include/uapi
651b76c13eSWang Nan
661b76c13eSWang Nanexport prefix libdir src obj
671b76c13eSWang Nan
681b76c13eSWang Nan# Shell quotes
691b76c13eSWang Nanlibdir_SQ = $(subst ','\'',$(libdir))
701b76c13eSWang Nanlibdir_relative_SQ = $(subst ','\'',$(libdir_relative))
711b76c13eSWang Nan
721b76c13eSWang NanOBJ		= $@
731b76c13eSWang NanN		=
741b76c13eSWang Nan
751d382264SDaniel BorkmannLIB_TARGET	= libbpf.a libbpf.so.$(LIBBPF_VERSION)
761d382264SDaniel BorkmannLIB_FILE	= libbpf.a libbpf.so*
77dd399ac9SLuca BoccassiPC_FILE		= libbpf.pc
781d382264SDaniel Borkmann
791b76c13eSWang Nan# Set compile option CFLAGS
801b76c13eSWang Nanifdef EXTRA_CFLAGS
811b76c13eSWang Nan  CFLAGS := $(EXTRA_CFLAGS)
821b76c13eSWang Nanelse
830a62291dSAndrii Nakryiko  CFLAGS := -g -O2
841b76c13eSWang Nanendif
851b76c13eSWang Nan
861b76c13eSWang Nan# Append required CFLAGS
873a74ac2dSKumar Kartikeya Dwivedioverride CFLAGS += -std=gnu89
888d708236SAndrii Nakryikooverride CFLAGS += $(EXTRA_WARNINGS) -Wno-switch-enum
891b76c13eSWang Nanoverride CFLAGS += -Werror -Wall
901b76c13eSWang Nanoverride CFLAGS += $(INCLUDES)
91ab9e0848SAndrey Ignatovoverride CFLAGS += -fvisibility=hidden
9271dd77fdSIvan Khoronzhukoverride CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
934980beb4SJean-Philippe Bruckeroverride CFLAGS += $(CLANG_CROSS_FLAGS)
941b76c13eSWang Nan
951bd63524SYonghong Song# flags specific for shared library
96b0efc216SAndrii NakryikoSHLIB_FLAGS := -DSHARED -fPIC
971bd63524SYonghong Song
981b76c13eSWang Nanifeq ($(VERBOSE),1)
991b76c13eSWang Nan  Q =
1001b76c13eSWang Nanelse
1011b76c13eSWang Nan  Q = @
1021b76c13eSWang Nanendif
1031b76c13eSWang Nan
104505d3085SMasahiro Yamada# Disable command line variables (CFLAGS) override from top
1051b76c13eSWang Nan# level Makefile (perf), otherwise build Makefile will get
1061b76c13eSWang Nan# the same command line setup.
1071b76c13eSWang NanMAKEOVERRIDES=
1081b76c13eSWang Nan
1097c422f55SJiri Olsaall:
1107c422f55SJiri Olsa
111*dbb2a7a9SBrian NorrisOUTPUT ?= ./
112*dbb2a7a9SBrian NorrisOUTPUT := $(abspath $(OUTPUT))/
1131b76c13eSWang Nanexport srctree OUTPUT CC LD CFLAGS V
114ab6201d0SJiri Olsainclude $(srctree)/tools/build/Makefile.include
1151b76c13eSWang Nan
1161bd63524SYonghong SongSHARED_OBJDIR	:= $(OUTPUT)sharedobjs/
1171bd63524SYonghong SongSTATIC_OBJDIR	:= $(OUTPUT)staticobjs/
1181bd63524SYonghong SongBPF_IN_SHARED	:= $(SHARED_OBJDIR)libbpf-in.o
1191bd63524SYonghong SongBPF_IN_STATIC	:= $(STATIC_OBJDIR)libbpf-in.o
120fa633a0fSNamhyung KimBPF_HELPER_DEFS	:= $(OUTPUT)bpf_helper_defs.h
1212f383041SAndrii NakryikoBPF_GENERATED	:= $(BPF_HELPER_DEFS)
1221b76c13eSWang Nan
1231d382264SDaniel BorkmannLIB_TARGET	:= $(addprefix $(OUTPUT),$(LIB_TARGET))
1241d382264SDaniel BorkmannLIB_FILE	:= $(addprefix $(OUTPUT),$(LIB_FILE))
125dd399ac9SLuca BoccassiPC_FILE		:= $(addprefix $(OUTPUT),$(PC_FILE))
1261d382264SDaniel Borkmann
127a9eb048dSToke Høiland-JørgensenTAGS_PROG := $(if $(shell which etags 2>/dev/null),etags,ctags)
128a9eb048dSToke Høiland-Jørgensen
1291bd63524SYonghong SongGLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
13010d30e30SKevin Laatz			   cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' | \
131aa915931SThadeu Lima de Souza Cascardo			   sed 's/\[.*\]//' | \
132056431aeSAndrii Nakryiko			   awk '/GLOBAL/ && /DEFAULT/ && !/UND|ABS/ {print $$NF}' | \
13310d30e30SKevin Laatz			   sort -u | wc -l)
13455983299SYauheni KaliutaVERSIONED_SYM_COUNT = $(shell readelf --dyn-syms --wide $(OUTPUT)libbpf.so | \
1351fd6cee1SJiri Olsa			      sed 's/\[.*\]//' | \
1360908a66aSYonghong Song			      awk '/GLOBAL/ && /DEFAULT/ && !/UND|ABS/ {print $$NF}' | \
137306b267cSAndrey Ignatov			      grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
138306b267cSAndrey Ignatov
1396bf6affeSStanislav FomichevCMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
1401b76c13eSWang Nan
1418e268887SStanislav Fomichevall: fixdep
1428e268887SStanislav Fomichev	$(Q)$(MAKE) all_cmd
1431b76c13eSWang Nan
144306b267cSAndrey Ignatovall_cmd: $(CMD_TARGETS) check
1451b76c13eSWang Nan
146*dbb2a7a9SBrian Norris$(SHARED_OBJDIR) $(STATIC_OBJDIR):
147*dbb2a7a9SBrian Norris	$(Q)mkdir -p $@
148*dbb2a7a9SBrian Norris
149*dbb2a7a9SBrian Norris$(BPF_IN_SHARED): force $(BPF_GENERATED) | $(SHARED_OBJDIR)
150f15d5e6dSDaniel Díaz	@(test -f ../../include/uapi/linux/bpf.h -a -f ../../../include/uapi/linux/bpf.h && ( \
151971e827bSArnaldo Carvalho de Melo	(diff -B ../../include/uapi/linux/bpf.h ../../../include/uapi/linux/bpf.h >/dev/null) || \
1528255e1efSIngo Molnar	echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h'" >&2 )) || true
153f15d5e6dSDaniel Díaz	@(test -f ../../include/uapi/linux/bpf_common.h -a -f ../../../include/uapi/linux/bpf_common.h && ( \
154971e827bSArnaldo Carvalho de Melo	(diff -B ../../include/uapi/linux/bpf_common.h ../../../include/uapi/linux/bpf_common.h >/dev/null) || \
1558255e1efSIngo Molnar	echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf_common.h' differs from latest version at 'include/uapi/linux/bpf_common.h'" >&2 )) || true
1561cad0788SMagnus Karlsson	@(test -f ../../include/uapi/linux/if_xdp.h -a -f ../../../include/uapi/linux/if_xdp.h && ( \
1571cad0788SMagnus Karlsson	(diff -B ../../include/uapi/linux/if_xdp.h ../../../include/uapi/linux/if_xdp.h >/dev/null) || \
1581cad0788SMagnus Karlsson	echo "Warning: Kernel ABI header at 'tools/include/uapi/linux/if_xdp.h' differs from latest version at 'include/uapi/linux/if_xdp.h'" >&2 )) || true
159*dbb2a7a9SBrian Norris	$(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(SHARED_OBJDIR) $(SHARED_OBJDIR)fixdep
1601bd63524SYonghong Song	$(Q)$(MAKE) $(build)=libbpf OUTPUT=$(SHARED_OBJDIR) CFLAGS="$(CFLAGS) $(SHLIB_FLAGS)"
1611bd63524SYonghong Song
162*dbb2a7a9SBrian Norris$(BPF_IN_STATIC): force $(BPF_GENERATED) | $(STATIC_OBJDIR)
163*dbb2a7a9SBrian Norris	$(SILENT_MAKE) -C $(srctree)/tools/build CFLAGS= LDFLAGS= OUTPUT=$(STATIC_OBJDIR) $(STATIC_OBJDIR)fixdep
1641bd63524SYonghong Song	$(Q)$(MAKE) $(build)=libbpf OUTPUT=$(STATIC_OBJDIR)
1651b76c13eSWang Nan
166fa633a0fSNamhyung Kim$(BPF_HELPER_DEFS): $(srctree)/tools/include/uapi/linux/bpf.h
167923a932cSJoe Stringer	$(QUIET_GEN)$(srctree)/scripts/bpf_doc.py --header \
168fa633a0fSNamhyung Kim		--file $(srctree)/tools/include/uapi/linux/bpf.h > $(BPF_HELPER_DEFS)
169e01a75c1SAndrii Nakryiko
1701d382264SDaniel Borkmann$(OUTPUT)libbpf.so: $(OUTPUT)libbpf.so.$(LIBBPF_VERSION)
1711d382264SDaniel Borkmann
17261c7aa50SAndrii Nakryiko$(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED) $(VERSION_SCRIPT)
1734980beb4SJean-Philippe Brucker	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) \
174793a349cSIvan Khoronzhuk		--shared -Wl,-soname,libbpf.so.$(LIBBPF_MAJOR_VERSION) \
17561c7aa50SAndrii Nakryiko		-Wl,--version-script=$(VERSION_SCRIPT) $< -lelf -lz -o $@
1761d382264SDaniel Borkmann	@ln -sf $(@F) $(OUTPUT)libbpf.so
177dadb81d0SAndrii Nakryiko	@ln -sf $(@F) $(OUTPUT)libbpf.so.$(LIBBPF_MAJOR_VERSION)
1781b76c13eSWang Nan
1791bd63524SYonghong Song$(OUTPUT)libbpf.a: $(BPF_IN_STATIC)
180d71fa5c9SAlexei Starovoitov	$(QUIET_LINK)$(RM) -f $@; $(AR) rcs $@ $^
1811b76c13eSWang Nan
182dd399ac9SLuca Boccassi$(OUTPUT)libbpf.pc:
183dd399ac9SLuca Boccassi	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
184dd399ac9SLuca Boccassi		-e "s|@LIBDIR@|$(libdir_SQ)|" \
185dd399ac9SLuca Boccassi		-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
186dd399ac9SLuca Boccassi		< libbpf.pc.template > $@
187dd399ac9SLuca Boccassi
1882f383041SAndrii Nakryikocheck: check_abi check_version
189306b267cSAndrey Ignatov
19061c7aa50SAndrii Nakryikocheck_abi: $(OUTPUT)libbpf.so $(VERSION_SCRIPT)
191306b267cSAndrey Ignatov	@if [ "$(GLOBAL_SYM_COUNT)" != "$(VERSIONED_SYM_COUNT)" ]; then	 \
1921bd63524SYonghong Song		echo "Warning: Num of global symbols in $(BPF_IN_SHARED)"	 \
193306b267cSAndrey Ignatov		     "($(GLOBAL_SYM_COUNT)) does NOT match with num of"	 \
194306b267cSAndrey Ignatov		     "versioned symbols in $^ ($(VERSIONED_SYM_COUNT))." \
195306b267cSAndrey Ignatov		     "Please make sure all LIBBPF_API symbols are"	 \
196306b267cSAndrey Ignatov		     "versioned in $(VERSION_SCRIPT)." >&2;		 \
197b5684058SAndrii Nakryiko		readelf -s --wide $(BPF_IN_SHARED) |			 \
19810d30e30SKevin Laatz		    cut -d "@" -f1 | sed 's/_v[0-9]_[0-9]_[0-9].*//' |	 \
199aa915931SThadeu Lima de Souza Cascardo		    sed 's/\[.*\]//' |					 \
2003464afdfSAurelien Jarno		    awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {print $$NF}'|  \
2019efc7794SAndrii Nakryiko		    sort -u > $(OUTPUT)libbpf_global_syms.tmp;		 \
20255983299SYauheni Kaliuta		readelf --dyn-syms --wide $(OUTPUT)libbpf.so |		 \
2031fd6cee1SJiri Olsa		    sed 's/\[.*\]//' |					 \
2040908a66aSYonghong Song		    awk '/GLOBAL/ && /DEFAULT/ && !/UND|ABS/ {print $$NF}'|  \
2059efc7794SAndrii Nakryiko		    grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 |		 \
2069efc7794SAndrii Nakryiko		    sort -u > $(OUTPUT)libbpf_versioned_syms.tmp; 	 \
2079efc7794SAndrii Nakryiko		diff -u $(OUTPUT)libbpf_global_syms.tmp			 \
2089efc7794SAndrii Nakryiko		     $(OUTPUT)libbpf_versioned_syms.tmp;		 \
2099efc7794SAndrii Nakryiko		rm $(OUTPUT)libbpf_global_syms.tmp			 \
2109efc7794SAndrii Nakryiko		   $(OUTPUT)libbpf_versioned_syms.tmp;			 \
211306b267cSAndrey Ignatov		exit 1;							 \
212306b267cSAndrey Ignatov	fi
213306b267cSAndrey Ignatov
214929bef46SQuentin MonnetHDR_MAJ_VERSION := $(shell grep -oE '^$(pound)define LIBBPF_MAJOR_VERSION ([0-9]+)$$' libbpf_version.h | cut -d' ' -f3)
215929bef46SQuentin MonnetHDR_MIN_VERSION := $(shell grep -oE '^$(pound)define LIBBPF_MINOR_VERSION ([0-9]+)$$' libbpf_version.h | cut -d' ' -f3)
2162f383041SAndrii Nakryiko
2172f383041SAndrii Nakryikocheck_version: $(VERSION_SCRIPT) libbpf_version.h
2182f383041SAndrii Nakryiko	@if [ "$(HDR_MAJ_VERSION)" != "$(LIBBPF_MAJOR_VERSION)" ]; then        \
2192f383041SAndrii Nakryiko		echo "Error: libbpf major version mismatch detected: "	       \
2202f383041SAndrii Nakryiko		     "'$(HDR_MAJ_VERSION)' != '$(LIBBPF_MAJOR_VERSION)'" >&2;  \
2212f383041SAndrii Nakryiko		exit 1;							       \
2222f383041SAndrii Nakryiko	fi
2232f383041SAndrii Nakryiko	@if [ "$(HDR_MIN_VERSION)" != "$(LIBBPF_MINOR_VERSION)" ]; then	       \
2242f383041SAndrii Nakryiko		echo "Error: libbpf minor version mismatch detected: "	       \
2252f383041SAndrii Nakryiko		     "'$(HDR_MIN_VERSION)' != '$(LIBBPF_MINOR_VERSION)'" >&2;  \
2262f383041SAndrii Nakryiko		exit 1;							       \
2272f383041SAndrii Nakryiko	fi
2282f383041SAndrii Nakryiko
2291d382264SDaniel Borkmanndefine do_install_mkdir
2301d382264SDaniel Borkmann	if [ ! -d '$(DESTDIR_SQ)$1' ]; then		\
2311d382264SDaniel Borkmann		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1';	\
2321d382264SDaniel Borkmann	fi
2331d382264SDaniel Borkmannendef
2341d382264SDaniel Borkmann
2351b76c13eSWang Nandefine do_install
2361b76c13eSWang Nan	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\
2371b76c13eSWang Nan		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2';	\
2381b76c13eSWang Nan	fi;						\
239e7fb6465SGeorgi Valkov	$(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
2401b76c13eSWang Nanendef
2411b76c13eSWang Nan
2421b76c13eSWang Naninstall_lib: all_cmd
2431d382264SDaniel Borkmann	$(call QUIET_INSTALL, $(LIB_TARGET)) \
2441d382264SDaniel Borkmann		$(call do_install_mkdir,$(libdir_SQ)); \
2451d382264SDaniel Borkmann		cp -fpR $(LIB_FILE) $(DESTDIR)$(libdir_SQ)
2461b76c13eSWang Nan
247f3660063SAndrii NakryikoSRC_HDRS := bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h	     \
248b79c2ce3SQuentin Monnet	    bpf_helpers.h bpf_tracing.h bpf_endian.h bpf_core_read.h	     \
249d72e2968SAndrii Nakryiko	    skel_internal.h libbpf_version.h usdt.bpf.h
250b79c2ce3SQuentin MonnetGEN_HDRS := $(BPF_GENERATED)
251232c9e8bSAndrii Nakryiko
252b79c2ce3SQuentin MonnetINSTALL_PFX := $(DESTDIR)$(prefix)/include/bpf
253b79c2ce3SQuentin MonnetINSTALL_SRC_HDRS := $(addprefix $(INSTALL_PFX)/, $(SRC_HDRS))
254b79c2ce3SQuentin MonnetINSTALL_GEN_HDRS := $(addprefix $(INSTALL_PFX)/, $(notdir $(GEN_HDRS)))
255b79c2ce3SQuentin Monnet
256b79c2ce3SQuentin Monnet$(INSTALL_SRC_HDRS): $(INSTALL_PFX)/%.h: %.h
257b79c2ce3SQuentin Monnet	$(call QUIET_INSTALL, $@) \
258b79c2ce3SQuentin Monnet		$(call do_install,$<,$(prefix)/include/bpf,644)
259b79c2ce3SQuentin Monnet
260b79c2ce3SQuentin Monnet$(INSTALL_GEN_HDRS): $(INSTALL_PFX)/%.h: $(OUTPUT)%.h
261b79c2ce3SQuentin Monnet	$(call QUIET_INSTALL, $@) \
262b79c2ce3SQuentin Monnet		$(call do_install,$<,$(prefix)/include/bpf,644)
263b79c2ce3SQuentin Monnet
264b79c2ce3SQuentin Monnetinstall_headers: $(BPF_GENERATED) $(INSTALL_SRC_HDRS) $(INSTALL_GEN_HDRS)
265daa45f3fSIan Rogers	$(call QUIET_INSTALL, libbpf_headers)
266eb54e522SJakub Kicinski
267dd399ac9SLuca Boccassiinstall_pkgconfig: $(PC_FILE)
268dd399ac9SLuca Boccassi	$(call QUIET_INSTALL, $(PC_FILE)) \
269dd399ac9SLuca Boccassi		$(call do_install,$(PC_FILE),$(libdir_SQ)/pkgconfig,644)
270dd399ac9SLuca Boccassi
27193581359SNikolay Borisovinstall: install_lib install_pkgconfig install_headers
2721b76c13eSWang Nan
273*dbb2a7a9SBrian Norrisclean: fixdep-clean
2742f184393SDavid S. Miller	$(call QUIET_CLEAN, libbpf) $(RM) -rf $(CMD_TARGETS)		     \
2750b46b755SQuentin Monnet		*~ .*.d .*.cmd LIBBPF-CFLAGS $(BPF_GENERATED)		     \
2762031af28SAndrii Nakryiko		$(SHARED_OBJDIR) $(STATIC_OBJDIR)			     \
2772031af28SAndrii Nakryiko		$(addprefix $(OUTPUT),					     \
2782031af28SAndrii Nakryiko			    *.o *.a *.so *.so.$(LIBBPF_MAJOR_VERSION) *.pc)
2791b76c13eSWang Nan
2802f383041SAndrii NakryikoPHONY += force cscope tags check check_abi check_version
2811b76c13eSWang Nanforce:
2821b76c13eSWang Nan
283a9eb048dSToke Høiland-Jørgensencscope:
284a9eb048dSToke Høiland-Jørgensen	ls *.c *.h > cscope.files
285a9eb048dSToke Høiland-Jørgensen	cscope -b -q -I $(srctree)/include -f cscope.out
286a9eb048dSToke Høiland-Jørgensen
287a9eb048dSToke Høiland-Jørgensentags:
288d71fa5c9SAlexei Starovoitov	$(RM) -f TAGS tags
289a9eb048dSToke Høiland-Jørgensen	ls *.c *.h | xargs $(TAGS_PROG) -a
290a9eb048dSToke Høiland-Jørgensen
2911b76c13eSWang Nan# Declare the contents of the .PHONY variable as phony.  We keep that
2921b76c13eSWang Nan# information in a variable so we can use it in if_changed and friends.
2931b76c13eSWang Nan.PHONY: $(PHONY)
294ab81e203SJakub Sitnicki
295ab81e203SJakub Sitnicki# Delete partially updated (corrupted) files on error
296ab81e203SJakub Sitnicki.DELETE_ON_ERROR:
29770681949SXin Liu
29870681949SXin Liuhelp:
29970681949SXin Liu	@echo 'libbpf common targets:'
30070681949SXin Liu	@echo '  HINT: use "V=1" to enable verbose build'
30170681949SXin Liu	@echo '  all     - build libraries and pkgconfig'
30270681949SXin Liu	@echo '  clean   - remove all generated files'
30394e38c95SRandy Dunlap	@echo '  check   - check ABI and version info'
30470681949SXin Liu	@echo ''
30570681949SXin Liu	@echo 'libbpf install targets:'
30670681949SXin Liu	@echo '  HINT: use "prefix"(defaults to "/usr/local") or "DESTDIR" (defaults to "/")'
30794e38c95SRandy Dunlap	@echo '        to adjust target destination, e.g. "make prefix=/usr/local install"'
30870681949SXin Liu	@echo '  install          - build and install all headers, libraries and pkgconfig'
30970681949SXin Liu	@echo '  install_headers  - install only headers to include/bpf'
31070681949SXin Liu	@echo ''
31170681949SXin Liu	@echo 'libbpf make targets:'
31270681949SXin Liu	@echo '  tags    - use ctags to make tag information for source code browsing'
31370681949SXin Liu	@echo '  cscope  - use cscope to make interactive source code browsing database'
314