Merge tag 'modules-for-v5.4' of git://git.kernel.org/pub/scm/linux/kernel/git/jeyu...
[linux-2.6-microblaze.git] / tools / perf / lib / Makefile
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 # Most of this file is copied from tools/lib/bpf/Makefile
3
4 LIBPERF_VERSION = 0
5 LIBPERF_PATCHLEVEL = 0
6 LIBPERF_EXTRAVERSION = 1
7
8 MAKEFLAGS += --no-print-directory
9
10 ifeq ($(srctree),)
11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 srctree := $(patsubst %/,%,$(dir $(srctree)))
14 #$(info Determined 'srctree' to be $(srctree))
15 endif
16
17 INSTALL = 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.
23 DESTDIR ?=
24 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25
26 include $(srctree)/tools/scripts/Makefile.include
27 include $(srctree)/tools/scripts/Makefile.arch
28
29 ifeq ($(LP64), 1)
30   libdir_relative = lib64
31 else
32   libdir_relative = lib
33 endif
34
35 prefix ?=
36 libdir = $(prefix)/$(libdir_relative)
37
38 # Shell quotes
39 libdir_SQ = $(subst ','\'',$(libdir))
40 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41
42 ifeq ("$(origin V)", "command line")
43   VERBOSE = $(V)
44 endif
45 ifndef VERBOSE
46   VERBOSE = 0
47 endif
48
49 ifeq ($(VERBOSE),1)
50   Q =
51 else
52   Q = @
53 endif
54
55 # Set compile option CFLAGS
56 ifdef EXTRA_CFLAGS
57   CFLAGS := $(EXTRA_CFLAGS)
58 else
59   CFLAGS := -g -Wall
60 endif
61
62 INCLUDES = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/ -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
63
64 # Append required CFLAGS
65 override CFLAGS += $(EXTRA_WARNINGS)
66 override CFLAGS += -Werror -Wall
67 override CFLAGS += -fPIC
68 override CFLAGS += $(INCLUDES)
69 override CFLAGS += -fvisibility=hidden
70
71 all:
72
73 export srctree OUTPUT CC LD CFLAGS V
74 export DESTDIR DESTDIR_SQ
75
76 include $(srctree)/tools/build/Makefile.include
77
78 VERSION_SCRIPT := libperf.map
79
80 PATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
81 EXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
82 VERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
83
84 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
85 LIBPERF_A  := $(OUTPUT)libperf.a
86 LIBPERF_IN := $(OUTPUT)libperf-in.o
87 LIBPERF_PC := $(OUTPUT)libperf.pc
88
89 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
90
91 $(LIBPERF_IN): FORCE
92         $(Q)$(MAKE) $(build)=libperf
93
94 $(LIBPERF_A): $(LIBPERF_IN)
95         $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
96
97 $(LIBPERF_SO): $(LIBPERF_IN)
98         $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
99                                     -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
100         @ln -sf $(@F) $(OUTPUT)libperf.so
101         @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
102
103
104 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
105
106 all: fixdep
107         $(Q)$(MAKE) libs
108
109 clean:
110         $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
111                 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
112         $(Q)$(MAKE) -C tests clean
113
114 tests:
115         $(Q)$(MAKE) -C tests
116         $(Q)$(MAKE) -C tests run
117
118 $(LIBPERF_PC):
119         $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
120                 -e "s|@LIBDIR@|$(libdir_SQ)|" \
121                 -e "s|@VERSION@|$(VERSION)|" \
122                 < libperf.pc.template > $@
123
124 define do_install_mkdir
125         if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
126                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
127         fi
128 endef
129
130 define do_install
131         if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
132                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
133         fi;                                             \
134         $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
135 endef
136
137 install_lib: libs
138         $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
139                 $(call do_install_mkdir,$(libdir_SQ)); \
140                 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
141
142 install_headers:
143         $(call QUIET_INSTALL, headers) \
144                 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
145                 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
146                 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
147                 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
148                 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644);
149
150 install_pkgconfig: $(LIBPERF_PC)
151         $(call QUIET_INSTALL, $(LIBPERF_PC)) \
152                 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
153
154 install: install_lib install_headers install_pkgconfig
155
156 FORCE:
157
158 .PHONY: all install clean tests FORCE