Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
  2. # Most of this file is copied from tools/lib/perf/Makefile
  3. LIBTHERMAL_TOOLS_VERSION = 0
  4. LIBTHERMAL_TOOLS_PATCHLEVEL = 0
  5. LIBTHERMAL_TOOLS_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/usr/include/libnl3 \
  51. -I$(srctree)/tools/lib/thermal/include \
  52. -I$(srctree)/tools/lib/ \
  53. -I$(srctree)/tools/include \
  54. -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
  55. -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
  56. -I$(srctree)/tools/include/uapi
  57. # Append required CFLAGS
  58. override CFLAGS += $(EXTRA_WARNINGS)
  59. override CFLAGS += -Werror -Wall
  60. override CFLAGS += -fPIC
  61. override CFLAGS += $(INCLUDES)
  62. override CFGLAS += -Wl,-L.
  63. override CFGLAS += -Wl,-lthermal
  64. all:
  65. export srctree OUTPUT CC LD CFLAGS V
  66. export DESTDIR DESTDIR_SQ
  67. include $(srctree)/tools/build/Makefile.include
  68. PATCHLEVEL = $(LIBTHERMAL_TOOLS_PATCHLEVEL)
  69. EXTRAVERSION = $(LIBTHERMAL_TOOLS_EXTRAVERSION)
  70. VERSION = $(LIBTHERMAL_TOOLS_VERSION).$(LIBTHERMAL_TOOLS_PATCHLEVEL).$(LIBTHERMAL_TOOLS_EXTRAVERSION)
  71. LIBTHERMAL_TOOLS_SO := $(OUTPUT)libthermal_tools.so.$(VERSION)
  72. LIBTHERMAL_TOOLS_A := $(OUTPUT)libthermal_tools.a
  73. LIBTHERMAL_TOOLS_IN := $(OUTPUT)libthermal_tools-in.o
  74. LIBTHERMAL_TOOLS_PC := $(OUTPUT)libthermal_tools.pc
  75. LIBTHERMAL_TOOLS_ALL := $(LIBTHERMAL_TOOLS_A) $(OUTPUT)libthermal_tools.so*
  76. $(LIBTHERMAL_TOOLS_IN): FORCE
  77. $(Q)$(MAKE) $(build)=libthermal_tools
  78. $(LIBTHERMAL_TOOLS_A): $(LIBTHERMAL_TOOLS_IN)
  79. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_TOOLS_IN)
  80. $(LIBTHERMAL_TOOLS_SO): $(LIBTHERMAL_TOOLS_IN)
  81. $(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal_tools.so $^ -o $@
  82. @ln -sf $(@F) $(OUTPUT)libthermal_tools.so
  83. @ln -sf $(@F) $(OUTPUT)libthermal_tools.so.$(LIBTHERMAL_TOOLS_VERSION)
  84. libs: $(LIBTHERMAL_TOOLS_A) $(LIBTHERMAL_TOOLS_SO) $(LIBTHERMAL_TOOLS_PC)
  85. all: fixdep
  86. $(Q)$(MAKE) libs
  87. clean:
  88. $(call QUIET_CLEAN, libthermal_tools) $(RM) $(LIBTHERMAL_TOOLS_A) \
  89. *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_TOOLS_VERSION) .*.d .*.cmd LIBTHERMAL_TOOLS-CFLAGS $(LIBTHERMAL_TOOLS_PC)
  90. $(LIBTHERMAL_TOOLS_PC):
  91. $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
  92. -e "s|@LIBDIR@|$(libdir_SQ)|" \
  93. -e "s|@VERSION@|$(VERSION)|" \
  94. < libthermal_tools.pc.template > $@
  95. define do_install_mkdir
  96. if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
  97. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
  98. fi
  99. endef
  100. define do_install
  101. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  102. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  103. fi; \
  104. $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
  105. endef
  106. install_lib: libs
  107. $(call QUIET_INSTALL, $(LIBTHERMAL_TOOLS_ALL)) \
  108. $(call do_install_mkdir,$(libdir_SQ)); \
  109. cp -fpR $(LIBTHERMAL_TOOLS_ALL) $(DESTDIR)$(libdir_SQ)
  110. install_headers:
  111. $(call QUIET_INSTALL, headers) \
  112. $(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
  113. install_pkgconfig: $(LIBTHERMAL_TOOLS_PC)
  114. $(call QUIET_INSTALL, $(LIBTHERMAL_TOOLS_PC)) \
  115. $(call do_install,$(LIBTHERMAL_TOOLS_PC),$(libdir_SQ)/pkgconfig,644)
  116. install_doc:
  117. $(Q)$(MAKE) -C Documentation install-man install-html install-examples
  118. #install: install_lib install_headers install_pkgconfig install_doc
  119. install: install_lib install_headers install_pkgconfig
  120. FORCE:
  121. .PHONY: all install clean FORCE