Makefile 4.7 KB

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