xref: /linux/tools/lib/perf/Makefile (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
13ce311afSJiri Olsa# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
23ce311afSJiri Olsa# Most of this file is copied from tools/lib/bpf/Makefile
33ce311afSJiri Olsa
43ce311afSJiri OlsaLIBPERF_VERSION = 0
53ce311afSJiri OlsaLIBPERF_PATCHLEVEL = 0
63ce311afSJiri OlsaLIBPERF_EXTRAVERSION = 1
73ce311afSJiri Olsa
83ce311afSJiri OlsaMAKEFLAGS += --no-print-directory
93ce311afSJiri Olsa
103ce311afSJiri Olsaifeq ($(srctree),)
113ce311afSJiri Olsasrctree := $(patsubst %/,%,$(dir $(CURDIR)))
123ce311afSJiri Olsasrctree := $(patsubst %/,%,$(dir $(srctree)))
133ce311afSJiri Olsasrctree := $(patsubst %/,%,$(dir $(srctree)))
143ce311afSJiri Olsa#$(info Determined 'srctree' to be $(srctree))
153ce311afSJiri Olsaendif
163ce311afSJiri Olsa
173ce311afSJiri OlsaINSTALL = install
183ce311afSJiri Olsa
193ce311afSJiri Olsa# Use DESTDIR for installing into a different root directory.
203ce311afSJiri Olsa# This is useful for building a package. The program will be
213ce311afSJiri Olsa# installed in this directory as if it was the root directory.
223ce311afSJiri Olsa# Then the build tool can move it later.
233ce311afSJiri OlsaDESTDIR ?=
243ce311afSJiri OlsaDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
253ce311afSJiri Olsa
263ce311afSJiri Olsainclude $(srctree)/tools/scripts/Makefile.include
273ce311afSJiri Olsainclude $(srctree)/tools/scripts/Makefile.arch
283ce311afSJiri Olsa
293ce311afSJiri Olsaifeq ($(LP64), 1)
303ce311afSJiri Olsa  libdir_relative = lib64
313ce311afSJiri Olsaelse
323ce311afSJiri Olsa  libdir_relative = lib
333ce311afSJiri Olsaendif
343ce311afSJiri Olsa
353ce311afSJiri Olsaprefix ?=
363ce311afSJiri Olsalibdir = $(prefix)/$(libdir_relative)
373ce311afSJiri Olsa
383ce311afSJiri Olsa# Shell quotes
393ce311afSJiri Olsalibdir_SQ = $(subst ','\'',$(libdir))
403ce311afSJiri Olsalibdir_relative_SQ = $(subst ','\'',$(libdir_relative))
413ce311afSJiri Olsa
423ce311afSJiri Olsaifeq ("$(origin V)", "command line")
433ce311afSJiri Olsa  VERBOSE = $(V)
443ce311afSJiri Olsaendif
453ce311afSJiri Olsaifndef VERBOSE
463ce311afSJiri Olsa  VERBOSE = 0
473ce311afSJiri Olsaendif
483ce311afSJiri Olsa
493ce311afSJiri Olsaifeq ($(VERBOSE),1)
503ce311afSJiri Olsa  Q =
513ce311afSJiri Olsaelse
523ce311afSJiri Olsa  Q = @
533ce311afSJiri Olsaendif
543ce311afSJiri Olsa
553d970601SJiri OlsaTEST_ARGS := $(if $(V),-v)
563d970601SJiri Olsa
573ce311afSJiri Olsa# Set compile option CFLAGS
583ce311afSJiri Olsaifdef EXTRA_CFLAGS
593ce311afSJiri Olsa  CFLAGS := $(EXTRA_CFLAGS)
603ce311afSJiri Olsaelse
613ce311afSJiri Olsa  CFLAGS := -g -Wall
623ce311afSJiri Olsaendif
633ce311afSJiri Olsa
643ce311afSJiri OlsaINCLUDES = \
653ce311afSJiri Olsa-I$(srctree)/tools/lib/perf/include \
663ce311afSJiri Olsa-I$(srctree)/tools/lib/ \
673ce311afSJiri Olsa-I$(srctree)/tools/include \
683ce311afSJiri Olsa-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
693ce311afSJiri Olsa-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
703ce311afSJiri Olsa-I$(srctree)/tools/include/uapi
713ce311afSJiri Olsa
723ce311afSJiri Olsa# Append required CFLAGS
733ce311afSJiri Olsaoverride CFLAGS += $(EXTRA_WARNINGS)
743ce311afSJiri Olsaoverride CFLAGS += -Werror -Wall
753ce311afSJiri Olsaoverride CFLAGS += -fPIC
763ce311afSJiri Olsaoverride CFLAGS += $(INCLUDES)
773ce311afSJiri Olsaoverride CFLAGS += -fvisibility=hidden
783ce311afSJiri Olsa
793ce311afSJiri Olsaall:
803ce311afSJiri Olsa
813ce311afSJiri Olsaexport srctree OUTPUT CC LD CFLAGS V
823ce311afSJiri Olsaexport DESTDIR DESTDIR_SQ
833ce311afSJiri Olsa
843ce311afSJiri Olsainclude $(srctree)/tools/build/Makefile.include
853ce311afSJiri Olsa
863ce311afSJiri OlsaVERSION_SCRIPT := libperf.map
873ce311afSJiri Olsa
883ce311afSJiri OlsaPATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
893ce311afSJiri OlsaEXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
903ce311afSJiri OlsaVERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
913ce311afSJiri Olsa
923ce311afSJiri OlsaLIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
933ce311afSJiri OlsaLIBPERF_A  := $(OUTPUT)libperf.a
943ce311afSJiri OlsaLIBPERF_IN := $(OUTPUT)libperf-in.o
953ce311afSJiri OlsaLIBPERF_PC := $(OUTPUT)libperf.pc
963ce311afSJiri Olsa
973ce311afSJiri OlsaLIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
983ce311afSJiri Olsa
993ce311afSJiri OlsaLIB_DIR := $(srctree)/tools/lib/api/
1003ce311afSJiri Olsa
1013ce311afSJiri Olsaifneq ($(OUTPUT),)
1023ce311afSJiri Olsaifneq ($(subdir),)
1033ce311afSJiri Olsa  API_PATH=$(OUTPUT)/../lib/api/
1043ce311afSJiri Olsaelse
1053ce311afSJiri Olsa  API_PATH=$(OUTPUT)
1063ce311afSJiri Olsaendif
1073ce311afSJiri Olsaelse
1083ce311afSJiri Olsa  API_PATH=$(LIB_DIR)
1093ce311afSJiri Olsaendif
1103ce311afSJiri Olsa
1113ce311afSJiri OlsaLIBAPI = $(API_PATH)libapi.a
1123ce311afSJiri Olsaexport LIBAPI
1133ce311afSJiri Olsa
1143ce311afSJiri Olsa$(LIBAPI): FORCE
1153ce311afSJiri Olsa	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
1163ce311afSJiri Olsa
1173ce311afSJiri Olsa$(LIBAPI)-clean:
1183ce311afSJiri Olsa	$(call QUIET_CLEAN, libapi)
1193ce311afSJiri Olsa	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
1203ce311afSJiri Olsa
1213ce311afSJiri Olsa$(LIBPERF_IN): FORCE
1223ce311afSJiri Olsa	$(Q)$(MAKE) $(build)=libperf
1233ce311afSJiri Olsa
1243ce311afSJiri Olsa$(LIBPERF_A): $(LIBPERF_IN)
1253ce311afSJiri Olsa	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
1263ce311afSJiri Olsa
1273ce311afSJiri Olsa$(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
1283ce311afSJiri Olsa	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
1293ce311afSJiri Olsa                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
1303ce311afSJiri Olsa	@ln -sf $(@F) $(OUTPUT)libperf.so
1313ce311afSJiri Olsa	@ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
1323ce311afSJiri Olsa
1333ce311afSJiri Olsa
1343ce311afSJiri Olsalibs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
1353ce311afSJiri Olsa
1363ce311afSJiri Olsaall: fixdep
1373ce311afSJiri Olsa	$(Q)$(MAKE) libs
1383ce311afSJiri Olsa
1393ce311afSJiri Olsaclean: $(LIBAPI)-clean
1403ce311afSJiri Olsa	$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
1413d970601SJiri Olsa                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \
1423d970601SJiri Olsa                $(TESTS_STATIC) $(TESTS_SHARED)
1433ce311afSJiri Olsa
1443d970601SJiri OlsaTESTS_IN = tests-in.o
1453d970601SJiri Olsa
1463d970601SJiri OlsaTESTS_STATIC = $(OUTPUT)tests-static
1473d970601SJiri OlsaTESTS_SHARED = $(OUTPUT)tests-shared
1483d970601SJiri Olsa
1493d970601SJiri Olsa$(TESTS_IN): FORCE
1503d970601SJiri Olsa	$(Q)$(MAKE) $(build)=tests
1513d970601SJiri Olsa
1523d970601SJiri Olsa$(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
1533d970601SJiri Olsa	$(QUIET_LINK)$(CC) -o $@ $^
1543d970601SJiri Olsa
1553d970601SJiri Olsa$(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
1565c816641SMasahiro Yamada	$(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf
1573d970601SJiri Olsa
1583d970601SJiri Olsamake-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)
1593d970601SJiri Olsa
1603d970601SJiri Olsatests: make-tests
1613d970601SJiri Olsa	@echo "running static:"
1623d970601SJiri Olsa	@./$(TESTS_STATIC) $(TEST_ARGS)
1633d970601SJiri Olsa	@echo "running dynamic:"
1643d970601SJiri Olsa	@LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS)
1653ce311afSJiri Olsa
1663ce311afSJiri Olsa$(LIBPERF_PC):
1673ce311afSJiri Olsa	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
1683ce311afSJiri Olsa		-e "s|@LIBDIR@|$(libdir_SQ)|" \
1693ce311afSJiri Olsa		-e "s|@VERSION@|$(VERSION)|" \
1703ce311afSJiri Olsa		< libperf.pc.template > $@
1713ce311afSJiri Olsa
1723ce311afSJiri Olsadefine do_install_mkdir
1733ce311afSJiri Olsa	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
1743ce311afSJiri Olsa		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
1753ce311afSJiri Olsa	fi
1763ce311afSJiri Olsaendef
1773ce311afSJiri Olsa
1783ce311afSJiri Olsadefine do_install
17947e02b94SIan Rogers	if [ ! -d '$2' ]; then             \
18047e02b94SIan Rogers		$(INSTALL) -d -m 755 '$2'; \
1813ce311afSJiri Olsa	fi;                                \
18247e02b94SIan Rogers	$(INSTALL) $1 $(if $3,-m $3,) '$2'
1833ce311afSJiri Olsaendef
1843ce311afSJiri Olsa
1853ce311afSJiri Olsainstall_lib: libs
1863ce311afSJiri Olsa	$(call QUIET_INSTALL, $(LIBPERF_ALL)) \
1873ce311afSJiri Olsa		$(call do_install_mkdir,$(libdir_SQ)); \
1883ce311afSJiri Olsa		cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
1893ce311afSJiri Olsa
19047e02b94SIan RogersHDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h
191*da885a0eSIan RogersINTERNAL_HDRS := cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threadmap.h xyarray.h
19247e02b94SIan Rogers
19347e02b94SIan RogersINSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/perf
19447e02b94SIan RogersINSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
19547e02b94SIan RogersINSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefix)/include/internal
19647e02b94SIan RogersINSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL_INTERNAL_HDRS_PFX)/, $(INTERNAL_HDRS))
19747e02b94SIan Rogers
19847e02b94SIan Rogers$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: include/perf/%.h
19947e02b94SIan Rogers	$(call QUIET_INSTALL, $@) \
20047e02b94SIan Rogers		$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
20147e02b94SIan Rogers
20247e02b94SIan Rogers$(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_HDRS_PFX)/%.h: include/internal/%.h
20347e02b94SIan Rogers	$(call QUIET_INSTALL, $@) \
20447e02b94SIan Rogers		$(call do_install,$<,$(INSTALL_INTERNAL_HDRS_PFX)/,644)
20547e02b94SIan Rogers
20647e02b94SIan Rogersinstall_headers: $(INSTALL_HDRS) $(INSTALL_INTERNAL_HDRS)
20747e02b94SIan Rogers	$(call QUIET_INSTALL, libperf_headers)
2083ce311afSJiri Olsa
2093ce311afSJiri Olsainstall_pkgconfig: $(LIBPERF_PC)
2103ce311afSJiri Olsa	$(call QUIET_INSTALL, $(LIBPERF_PC)) \
2114ff17c44SAlexander Gordeev		$(call do_install,$(LIBPERF_PC),$(DESTDIR_SQ)$(libdir_SQ)/pkgconfig,644)
2123ce311afSJiri Olsa
21381de3bf3SJiri Olsainstall_doc:
21481de3bf3SJiri Olsa	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
21581de3bf3SJiri Olsa
21681de3bf3SJiri Olsainstall: install_lib install_headers install_pkgconfig install_doc
2173ce311afSJiri Olsa
2183ce311afSJiri OlsaFORCE:
2193ce311afSJiri Olsa
2203ce311afSJiri Olsa.PHONY: all install clean tests FORCE
221