2019-07-21 13:24:10 +02:00
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
# Most of this file is copied from tools/lib/bpf/Makefile
2019-07-21 13:24:11 +02:00
LIBPERF_VERSION = 0
LIBPERF_PATCHLEVEL = 0
LIBPERF_EXTRAVERSION = 1
2019-07-21 13:24:10 +02:00
MAKEFLAGS += --no-print-directory
i f e q ( $( srctree ) , )
srctree := $( patsubst %/,%,$( dir $( CURDIR) ) )
srctree := $( patsubst %/,%,$( dir $( srctree) ) )
srctree := $( patsubst %/,%,$( dir $( srctree) ) )
#$(info Determined 'srctree' to be $(srctree))
e n d i f
2019-07-21 13:24:58 +02:00
INSTALL = install
# Use DESTDIR for installing into a different root directory.
# This is useful for building a package. The program will be
# installed in this directory as if it was the root directory.
# Then the build tool can move it later.
DESTDIR ?=
DESTDIR_SQ = '$(subst ' ,'\' ',$(DESTDIR))'
2019-07-21 13:24:10 +02:00
i n c l u d e $( srctree ) / t o o l s / s c r i p t s / M a k e f i l e . i n c l u d e
i n c l u d e $( srctree ) / t o o l s / s c r i p t s / M a k e f i l e . a r c h
2019-07-21 13:24:58 +02:00
i f e q ( $( LP 64) , 1 )
libdir_relative = lib64
e l s e
libdir_relative = lib
e n d i f
prefix ?=
libdir = $( prefix) /$( libdir_relative)
# Shell quotes
libdir_SQ = $( subst ',' \' ' ,$( libdir) )
libdir_relative_SQ = $( subst ',' \' ' ,$( libdir_relative) )
2019-07-21 13:24:10 +02:00
i f e q ( "$(origin V)" , "command line" )
VERBOSE = $( V)
e n d i f
i f n d e f V E R B O S E
VERBOSE = 0
e n d i f
i f e q ( $( VERBOSE ) , 1 )
Q =
e l s e
Q = @
e n d i f
2021-07-06 17:16:58 +02:00
TEST_ARGS := $( if $( V) ,-v)
2019-07-21 13:24:10 +02:00
# Set compile option CFLAGS
i f d e f E X T R A _ C F L A G S
CFLAGS := $( EXTRA_CFLAGS)
e l s e
CFLAGS := -g -Wall
e n d i f
2019-08-18 23:02:58 +02:00
INCLUDES = \
2019-12-06 22:06:11 +01:00
- I $( srctree ) / t o o l s / l i b / p e r f / i n c l u d e \
2019-08-18 23:02:58 +02:00
- I $( srctree ) / t o o l s / l i b / \
- I $( srctree ) / t o o l s / i n c l u d e \
- I $( srctree ) / t o o l s / a r c h / $( SRCARCH ) / i n c l u d e / \
- I $( srctree ) / t o o l s / a r c h / $( SRCARCH ) / i n c l u d e / u a p i \
- I $( srctree ) / t o o l s / i n c l u d e / u a p i
2019-07-21 13:24:10 +02:00
# Append required CFLAGS
o v e r r i d e CFLAGS += $( EXTRA_WARNINGS)
o v e r r i d e CFLAGS += -Werror -Wall
o v e r r i d e CFLAGS += -fPIC
o v e r r i d e CFLAGS += $( INCLUDES)
o v e r r i d e CFLAGS += -fvisibility= hidden
all :
export srctree OUTPUT CC LD CFLAGS V
2019-07-21 13:24:58 +02:00
export DESTDIR DESTDIR_SQ
2019-07-21 13:24:10 +02:00
i n c l u d e $( srctree ) / t o o l s / b u i l d / M a k e f i l e . i n c l u d e
2019-07-21 13:24:11 +02:00
VERSION_SCRIPT := libperf.map
PATCHLEVEL = $( LIBPERF_PATCHLEVEL)
EXTRAVERSION = $( LIBPERF_EXTRAVERSION)
VERSION = $( LIBPERF_VERSION) .$( LIBPERF_PATCHLEVEL) .$( LIBPERF_EXTRAVERSION)
LIBPERF_SO := $( OUTPUT) libperf.so.$( VERSION)
2019-07-21 13:24:10 +02:00
LIBPERF_A := $( OUTPUT) libperf.a
LIBPERF_IN := $( OUTPUT) libperf-in.o
2019-07-21 13:24:58 +02:00
LIBPERF_PC := $( OUTPUT) libperf.pc
LIBPERF_ALL := $( LIBPERF_A) $( OUTPUT) libperf.so*
2019-07-21 13:24:10 +02:00
2019-08-18 23:02:58 +02:00
LIB_DIR := $( srctree) /tools/lib/api/
i f n e q ( $( OUTPUT ) , )
i f n e q ( $( subdir ) , )
API_PATH = $( OUTPUT) /../lib/api/
e l s e
API_PATH = $( OUTPUT)
e n d i f
e l s e
API_PATH = $( LIB_DIR)
e n d i f
LIBAPI = $( API_PATH) libapi.a
2019-10-17 12:59:12 +02:00
export LIBAPI
2019-08-18 23:02:58 +02:00
$(LIBAPI) : FORCE
$( Q) $( MAKE) -C $( LIB_DIR) O = $( OUTPUT) $( OUTPUT) libapi.a
$(LIBAPI)-clean :
$( call QUIET_CLEAN, libapi)
$( Q) $( MAKE) -C $( LIB_DIR) O = $( OUTPUT) clean >/dev/null
2019-07-21 13:24:10 +02:00
$(LIBPERF_IN) : FORCE
$( Q) $( MAKE) $( build) = libperf
$(LIBPERF_A) : $( LIBPERF_IN )
$( QUIET_AR) $( RM) $@ && $( AR) rcs $@ $( LIBPERF_IN)
2019-08-18 23:02:58 +02:00
$(LIBPERF_SO) : $( LIBPERF_IN ) $( LIBAPI )
2019-07-21 13:24:11 +02:00
$( QUIET_LINK) $( CC) --shared -Wl,-soname,libperf.so \
-Wl,--version-script= $( VERSION_SCRIPT) $^ -o $@
@ln -sf $( @F) $( OUTPUT) libperf.so
@ln -sf $( @F) $( OUTPUT) libperf.so.$( LIBPERF_VERSION)
2019-07-21 13:24:10 +02:00
2019-07-21 13:24:58 +02:00
libs : $( LIBPERF_A ) $( LIBPERF_SO ) $( LIBPERF_PC )
2019-07-21 13:24:10 +02:00
all : fixdep
$( Q) $( MAKE) libs
2019-08-18 23:02:58 +02:00
clean : $( LIBAPI ) -clean
2019-07-21 13:24:10 +02:00
$( call QUIET_CLEAN, libperf) $( RM) $( LIBPERF_A) \
2021-07-06 17:16:58 +02:00
*.o *~ *.a *.so *.so.$( VERSION) *.so.$( LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $( LIBPERF_PC) \
$( TESTS_STATIC) $( TESTS_SHARED)
TESTS_IN = tests-in.o
TESTS_STATIC = $( OUTPUT) tests-static
TESTS_SHARED = $( OUTPUT) tests-shared
$(TESTS_IN) : FORCE
$( Q) $( MAKE) $( build) = tests
$(TESTS_STATIC) : $( TESTS_IN ) $( LIBPERF_A ) $( LIBAPI )
$( QUIET_LINK) $( CC) -o $@ $^
$(TESTS_SHARED) : $( TESTS_IN ) $( LIBAPI )
$( QUIET_LINK) $( CC) -o $@ -L$( if $( OUTPUT) ,$( OUTPUT) ,.) $^ -lperf
make-tests : libs $( TESTS_SHARED ) $( TESTS_STATIC )
2019-07-21 13:24:59 +02:00
2021-07-06 17:16:58 +02:00
tests : make -tests
@echo "running static:"
@./$( TESTS_STATIC) $( TEST_ARGS)
@echo "running dynamic:"
@LD_LIBRARY_PATH= . ./$( TESTS_SHARED) $( TEST_ARGS)
2019-07-21 13:24:58 +02:00
$(LIBPERF_PC) :
$( QUIET_GEN) sed -e " s|@PREFIX@| $( prefix) | " \
-e " s|@LIBDIR@| $( libdir_SQ) | " \
-e " s|@VERSION@| $( VERSION) | " \
< libperf.pc.template > $@
d e f i n e d o _ i n s t a l l _ m k d i r
if [ ! -d '$(DESTDIR_SQ)$1' ] ; then \
$( INSTALL) -d -m 755 '$(DESTDIR_SQ)$1' ; \
fi
e n d e f
d e f i n e d o _ i n s t a l l
if [ ! -d '$(DESTDIR_SQ)$2' ] ; then \
$( INSTALL) -d -m 755 '$(DESTDIR_SQ)$2' ; \
fi ; \
$( INSTALL) $1 $( if $3 ,-m $3 ,) '$(DESTDIR_SQ)$2'
e n d e f
install_lib : libs
$( call QUIET_INSTALL, $( LIBPERF_ALL) ) \
$( call do_install_mkdir,$( libdir_SQ) ) ; \
cp -fpR $( LIBPERF_ALL) $( DESTDIR) $( libdir_SQ)
install_headers :
$( call QUIET_INSTALL, headers) \
$( call do_install,include/perf/core.h,$( prefix) /include/perf,644) ; \
$( call do_install,include/perf/cpumap.h,$( prefix) /include/perf,644) ; \
$( call do_install,include/perf/threadmap.h,$( prefix) /include/perf,644) ; \
$( call do_install,include/perf/evlist.h,$( prefix) /include/perf,644) ; \
2019-10-07 14:53:17 +02:00
$( call do_install,include/perf/evsel.h,$( prefix) /include/perf,644) ; \
$( call do_install,include/perf/event.h,$( prefix) /include/perf,644) ; \
$( call do_install,include/perf/mmap.h,$( prefix) /include/perf,644) ;
2019-07-21 13:24:58 +02:00
install_pkgconfig : $( LIBPERF_PC )
$( call QUIET_INSTALL, $( LIBPERF_PC) ) \
$( call do_install,$( LIBPERF_PC) ,$( libdir_SQ) /pkgconfig,644)
2019-12-06 22:06:12 +01:00
install_doc :
$( Q) $( MAKE) -C Documentation install-man install-html install-examples
install : install_lib install_headers install_pkgconfig install_doc
2019-07-21 13:24:10 +02:00
FORCE :
2019-07-21 13:24:59 +02:00
.PHONY : all install clean tests FORCE