HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage()
[linux/fpc-iii.git] / tools / lib / bpf / Makefile
bloba3caaf3eafbdbc6c7afda606cbf35b6888324ef4
1 # Most of this file is copied from tools/lib/traceevent/Makefile
3 BPF_VERSION = 0
4 BPF_PATCHLEVEL = 0
5 BPF_EXTRAVERSION = 1
7 MAKEFLAGS += --no-print-directory
10 # Makefiles suck: This macro sets a default value of $(2) for the
11 # variable named by $(1), unless the variable has been set by
12 # environment or command line. This is necessary for CC and AR
13 # because make sets default values, so the simpler ?= approach
14 # won't work as expected.
15 define allow-override
16 $(if $(or $(findstring environment,$(origin $(1))),\
17 $(findstring command line,$(origin $(1)))),,\
18 $(eval $(1) = $(2)))
19 endef
21 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
22 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
23 $(call allow-override,AR,$(CROSS_COMPILE)ar)
25 INSTALL = install
27 # Use DESTDIR for installing into a different root directory.
28 # This is useful for building a package. The program will be
29 # installed in this directory as if it was the root directory.
30 # Then the build tool can move it later.
31 DESTDIR ?=
32 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
34 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
35 ifeq ($(LP64), 1)
36 libdir_relative = lib64
37 else
38 libdir_relative = lib
39 endif
41 prefix ?= /usr/local
42 libdir = $(prefix)/$(libdir_relative)
43 man_dir = $(prefix)/share/man
44 man_dir_SQ = '$(subst ','\'',$(man_dir))'
46 export man_dir man_dir_SQ INSTALL
47 export DESTDIR DESTDIR_SQ
49 include ../../scripts/Makefile.include
51 # copy a bit from Linux kbuild
53 ifeq ("$(origin V)", "command line")
54 VERBOSE = $(V)
55 endif
56 ifndef VERBOSE
57 VERBOSE = 0
58 endif
60 ifeq ($(srctree),)
61 srctree := $(patsubst %/,%,$(dir $(shell pwd)))
62 srctree := $(patsubst %/,%,$(dir $(srctree)))
63 srctree := $(patsubst %/,%,$(dir $(srctree)))
64 #$(info Determined 'srctree' to be $(srctree))
65 endif
67 FEATURE_USER = .libbpf
68 FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf
69 FEATURE_DISPLAY = libelf bpf
71 INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
72 FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
74 include $(srctree)/tools/build/Makefile.feature
76 export prefix libdir src obj
78 # Shell quotes
79 libdir_SQ = $(subst ','\'',$(libdir))
80 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
81 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
83 LIB_FILE = libbpf.a libbpf.so
85 VERSION = $(BPF_VERSION)
86 PATCHLEVEL = $(BPF_PATCHLEVEL)
87 EXTRAVERSION = $(BPF_EXTRAVERSION)
89 OBJ = $@
90 N =
92 LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
94 # Set compile option CFLAGS
95 ifdef EXTRA_CFLAGS
96 CFLAGS := $(EXTRA_CFLAGS)
97 else
98 CFLAGS := -g -Wall
99 endif
101 ifeq ($(feature-libelf-mmap), 1)
102 override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
103 endif
105 ifeq ($(feature-libelf-getphdrnum), 1)
106 override CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
107 endif
109 # Append required CFLAGS
110 override CFLAGS += $(EXTRA_WARNINGS)
111 override CFLAGS += -Werror -Wall
112 override CFLAGS += -fPIC
113 override CFLAGS += $(INCLUDES)
115 ifeq ($(VERBOSE),1)
117 else
118 Q = @
119 endif
121 # Disable command line variables (CFLAGS) overide from top
122 # level Makefile (perf), otherwise build Makefile will get
123 # the same command line setup.
124 MAKEOVERRIDES=
126 all:
128 export srctree OUTPUT CC LD CFLAGS V
129 include $(srctree)/tools/build/Makefile.include
131 BPF_IN := $(OUTPUT)libbpf-in.o
132 LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
134 CMD_TARGETS = $(LIB_FILE)
136 TARGETS = $(CMD_TARGETS)
138 all: fixdep $(VERSION_FILES) all_cmd
140 all_cmd: $(CMD_TARGETS)
142 $(BPF_IN): force elfdep bpfdep
143 $(Q)$(MAKE) $(build)=libbpf
145 $(OUTPUT)libbpf.so: $(BPF_IN)
146 $(QUIET_LINK)$(CC) --shared $^ -o $@
148 $(OUTPUT)libbpf.a: $(BPF_IN)
149 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
151 define update_dir
152 (echo $1 > $@.tmp; \
153 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
154 rm -f $@.tmp; \
155 else \
156 echo ' UPDATE $@'; \
157 mv -f $@.tmp $@; \
158 fi);
159 endef
161 define do_install
162 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
163 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
164 fi; \
165 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
166 endef
168 install_lib: all_cmd
169 $(call QUIET_INSTALL, $(LIB_FILE)) \
170 $(call do_install,$(LIB_FILE),$(libdir_SQ))
172 install: install_lib
174 ### Cleaning rules
176 config-clean:
177 $(call QUIET_CLEAN, config)
178 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
180 clean:
181 $(call QUIET_CLEAN, libbpf) $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
182 $(RM) LIBBPF-CFLAGS
183 $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf
187 PHONY += force elfdep bpfdep
188 force:
190 elfdep:
191 @if [ "$(feature-libelf)" != "1" ]; then echo "No libelf found"; exit -1 ; fi
193 bpfdep:
194 @if [ "$(feature-bpf)" != "1" ]; then echo "BPF API too old"; exit -1 ; fi
196 # Declare the contents of the .PHONY variable as phony. We keep that
197 # information in a variable so we can use it in if_changed and friends.
198 .PHONY: $(PHONY)