xref: /openbmc/linux/tools/lib/perf/Makefile (revision fc772314)
1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2# Most of this file is copied from tools/lib/bpf/Makefile
3
4LIBPERF_VERSION = 0
5LIBPERF_PATCHLEVEL = 0
6LIBPERF_EXTRAVERSION = 1
7
8MAKEFLAGS += --no-print-directory
9
10ifeq ($(srctree),)
11srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12srctree := $(patsubst %/,%,$(dir $(srctree)))
13srctree := $(patsubst %/,%,$(dir $(srctree)))
14#$(info Determined 'srctree' to be $(srctree))
15endif
16
17INSTALL = install
18
19# Use DESTDIR for installing into a different root directory.
20# This is useful for building a package. The program will be
21# installed in this directory as if it was the root directory.
22# Then the build tool can move it later.
23DESTDIR ?=
24DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25
26include $(srctree)/tools/scripts/Makefile.include
27include $(srctree)/tools/scripts/Makefile.arch
28
29ifeq ($(LP64), 1)
30  libdir_relative = lib64
31else
32  libdir_relative = lib
33endif
34
35prefix ?=
36libdir = $(prefix)/$(libdir_relative)
37
38# Shell quotes
39libdir_SQ = $(subst ','\'',$(libdir))
40libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41
42ifeq ("$(origin V)", "command line")
43  VERBOSE = $(V)
44endif
45ifndef VERBOSE
46  VERBOSE = 0
47endif
48
49ifeq ($(VERBOSE),1)
50  Q =
51else
52  Q = @
53endif
54
55# Set compile option CFLAGS
56ifdef EXTRA_CFLAGS
57  CFLAGS := $(EXTRA_CFLAGS)
58else
59  CFLAGS := -g -Wall
60endif
61
62INCLUDES = \
63-I$(srctree)/tools/lib/perf/include \
64-I$(srctree)/tools/lib/ \
65-I$(srctree)/tools/include \
66-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
67-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
68-I$(srctree)/tools/include/uapi
69
70# Append required CFLAGS
71override CFLAGS += $(EXTRA_WARNINGS)
72override CFLAGS += -Werror -Wall
73override CFLAGS += -fPIC
74override CFLAGS += $(INCLUDES)
75override CFLAGS += -fvisibility=hidden
76
77all:
78
79export srctree OUTPUT CC LD CFLAGS V
80export DESTDIR DESTDIR_SQ
81
82include $(srctree)/tools/build/Makefile.include
83
84VERSION_SCRIPT := libperf.map
85
86PATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
87EXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
88VERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
89
90LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
91LIBPERF_A  := $(OUTPUT)libperf.a
92LIBPERF_IN := $(OUTPUT)libperf-in.o
93LIBPERF_PC := $(OUTPUT)libperf.pc
94
95LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
96
97LIB_DIR := $(srctree)/tools/lib/api/
98
99ifneq ($(OUTPUT),)
100ifneq ($(subdir),)
101  API_PATH=$(OUTPUT)/../lib/api/
102else
103  API_PATH=$(OUTPUT)
104endif
105else
106  API_PATH=$(LIB_DIR)
107endif
108
109LIBAPI = $(API_PATH)libapi.a
110export LIBAPI
111
112$(LIBAPI): FORCE
113	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
114
115$(LIBAPI)-clean:
116	$(call QUIET_CLEAN, libapi)
117	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
118
119$(LIBPERF_IN): FORCE
120	$(Q)$(MAKE) $(build)=libperf
121
122$(LIBPERF_A): $(LIBPERF_IN)
123	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
124
125$(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
126	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
127                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
128	@ln -sf $(@F) $(OUTPUT)libperf.so
129	@ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
130
131
132libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
133
134all: fixdep
135	$(Q)$(MAKE) libs
136
137clean: $(LIBAPI)-clean
138	$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
139                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
140	$(Q)$(MAKE) -C tests clean
141
142tests: libs
143	$(Q)$(MAKE) -C tests
144	$(Q)$(MAKE) -C tests run
145
146$(LIBPERF_PC):
147	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
148		-e "s|@LIBDIR@|$(libdir_SQ)|" \
149		-e "s|@VERSION@|$(VERSION)|" \
150		< libperf.pc.template > $@
151
152define do_install_mkdir
153	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
154		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
155	fi
156endef
157
158define do_install
159	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
160		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
161	fi;                                             \
162	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
163endef
164
165install_lib: libs
166	$(call QUIET_INSTALL, $(LIBPERF_ALL)) \
167		$(call do_install_mkdir,$(libdir_SQ)); \
168		cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
169
170install_headers:
171	$(call QUIET_INSTALL, headers) \
172		$(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
173		$(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
174		$(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
175		$(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
176		$(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
177		$(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
178		$(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
179
180install_pkgconfig: $(LIBPERF_PC)
181	$(call QUIET_INSTALL, $(LIBPERF_PC)) \
182		$(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
183
184install_doc:
185	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
186
187install: install_lib install_headers install_pkgconfig install_doc
188
189FORCE:
190
191.PHONY: all install clean tests FORCE
192