perf tools: Rename the 'single_dep' target to 'prepare'
[deliverable/linux.git] / tools / lib / bpf / Makefile
CommitLineData
1b76c13e
WN
1# Most of this file is copied from tools/lib/traceevent/Makefile
2
3BPF_VERSION = 0
4BPF_PATCHLEVEL = 0
5BPF_EXTRAVERSION = 1
6
7MAKEFLAGS += --no-print-directory
8
9
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.
15define allow-override
16 $(if $(or $(findstring environment,$(origin $(1))),\
17 $(findstring command line,$(origin $(1)))),,\
18 $(eval $(1) = $(2)))
19endef
20
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)
24
25INSTALL = install
26
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.
31DESTDIR ?=
32DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
33
34LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
35ifeq ($(LP64), 1)
36 libdir_relative = lib64
37else
38 libdir_relative = lib
39endif
40
41prefix ?= /usr/local
42libdir = $(prefix)/$(libdir_relative)
43man_dir = $(prefix)/share/man
44man_dir_SQ = '$(subst ','\'',$(man_dir))'
45
46export man_dir man_dir_SQ INSTALL
47export DESTDIR DESTDIR_SQ
48
49include ../../scripts/Makefile.include
50
51# copy a bit from Linux kbuild
52
53ifeq ("$(origin V)", "command line")
54 VERBOSE = $(V)
55endif
56ifndef VERBOSE
57 VERBOSE = 0
58endif
59
60ifeq ($(srctree),)
61srctree := $(patsubst %/,%,$(dir $(shell pwd)))
62srctree := $(patsubst %/,%,$(dir $(srctree)))
63srctree := $(patsubst %/,%,$(dir $(srctree)))
64#$(info Determined 'srctree' to be $(srctree))
65endif
66
65f041be 67FEATURE_USER = .libbpf
20517cd9
ACM
68FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf
69FEATURE_DISPLAY = libelf bpf
1b76c13e
WN
70
71INCLUDES = -I. -I$(srctree)/tools/include -I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
72FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
73
74include $(srctree)/tools/build/Makefile.feature
75
76export prefix libdir src obj
77
78# Shell quotes
79libdir_SQ = $(subst ','\'',$(libdir))
80libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
81plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
82
83LIB_FILE = libbpf.a libbpf.so
84
85VERSION = $(BPF_VERSION)
86PATCHLEVEL = $(BPF_PATCHLEVEL)
87EXTRAVERSION = $(BPF_EXTRAVERSION)
88
89OBJ = $@
90N =
91
92LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
93
94# Set compile option CFLAGS
95ifdef EXTRA_CFLAGS
96 CFLAGS := $(EXTRA_CFLAGS)
97else
98 CFLAGS := -g -Wall
99endif
100
101ifeq ($(feature-libelf-mmap), 1)
102 override CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
103endif
104
105ifeq ($(feature-libelf-getphdrnum), 1)
106 override CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
107endif
108
109# Append required CFLAGS
110override CFLAGS += $(EXTRA_WARNINGS)
111override CFLAGS += -Werror -Wall
112override CFLAGS += -fPIC
113override CFLAGS += $(INCLUDES)
114
115ifeq ($(VERBOSE),1)
116 Q =
117else
118 Q = @
119endif
120
121# Disable command line variables (CFLAGS) overide from top
122# level Makefile (perf), otherwise build Makefile will get
123# the same command line setup.
124MAKEOVERRIDES=
125
126export srctree OUTPUT CC LD CFLAGS V
ab6201d0 127include $(srctree)/tools/build/Makefile.include
1b76c13e
WN
128
129BPF_IN := $(OUTPUT)libbpf-in.o
130LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
131
132CMD_TARGETS = $(LIB_FILE)
133
134TARGETS = $(CMD_TARGETS)
135
136all: $(VERSION_FILES) all_cmd
137
138all_cmd: $(CMD_TARGETS)
139
140$(BPF_IN): force elfdep bpfdep
141 $(Q)$(MAKE) $(build)=libbpf
142
143$(OUTPUT)libbpf.so: $(BPF_IN)
144 $(QUIET_LINK)$(CC) --shared $^ -o $@
145
146$(OUTPUT)libbpf.a: $(BPF_IN)
147 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
148
149define update_dir
150 (echo $1 > $@.tmp; \
151 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
152 rm -f $@.tmp; \
153 else \
154 echo ' UPDATE $@'; \
155 mv -f $@.tmp $@; \
156 fi);
157endef
158
159define do_install
160 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
161 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
162 fi; \
163 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
164endef
165
166install_lib: all_cmd
167 $(call QUIET_INSTALL, $(LIB_FILE)) \
168 $(call do_install,$(LIB_FILE),$(libdir_SQ))
169
170install: install_lib
171
172### Cleaning rules
173
174config-clean:
175 $(call QUIET_CLEAN, config)
176 $(Q)$(MAKE) -C $(srctree)/tools/build/feature/ clean >/dev/null
177
178clean:
179 $(call QUIET_CLEAN, libbpf) $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
180 $(RM) LIBBPF-CFLAGS
181 $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP
182
183
184
185PHONY += force elfdep bpfdep
186force:
187
188elfdep:
189 @if [ "$(feature-libelf)" != "1" ]; then echo "No libelf found"; exit -1 ; fi
190
191bpfdep:
192 @if [ "$(feature-bpf)" != "1" ]; then echo "BPF API too old"; exit -1 ; fi
193
194# Declare the contents of the .PHONY variable as phony. We keep that
195# information in a variable so we can use it in if_changed and friends.
196.PHONY: $(PHONY)
This page took 0.064273 seconds and 5 git commands to generate.