Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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_VERSION = 0
  4. LIBTHERMAL_PATCHLEVEL = 0
  5. LIBTHERMAL_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 CFLAGS += -fvisibility=hidden
  63. override CFGLAS += -Wl,-L.
  64. override CFGLAS += -Wl,-lthermal
  65. all:
  66. export srctree OUTPUT CC LD CFLAGS V
  67. export DESTDIR DESTDIR_SQ
  68. include $(srctree)/tools/build/Makefile.include
  69. VERSION_SCRIPT := libthermal.map
  70. PATCHLEVEL = $(LIBTHERMAL_PATCHLEVEL)
  71. EXTRAVERSION = $(LIBTHERMAL_EXTRAVERSION)
  72. VERSION = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
  73. LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
  74. LIBTHERMAL_A := $(OUTPUT)libthermal.a
  75. LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
  76. LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
  77. LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
  78. THERMAL_UAPI := include/uapi/linux/thermal.h
  79. $(THERMAL_UAPI): FORCE
  80. ln -sf $(srctree)/$@ $(srctree)/tools/$@
  81. $(LIBTHERMAL_IN): FORCE
  82. $(Q)$(MAKE) $(build)=libthermal
  83. $(LIBTHERMAL_A): $(LIBTHERMAL_IN)
  84. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
  85. $(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
  86. $(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
  87. -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
  88. @ln -sf $(@F) $(OUTPUT)libthermal.so
  89. @ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
  90. libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
  91. all: fixdep
  92. $(Q)$(MAKE) libs
  93. clean:
  94. $(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
  95. *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) \
  96. .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC) \
  97. $(srctree)/tools/$(THERMAL_UAPI)
  98. $(LIBTHERMAL_PC):
  99. $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
  100. -e "s|@LIBDIR@|$(libdir_SQ)|" \
  101. -e "s|@VERSION@|$(VERSION)|" \
  102. < libthermal.pc.template > $@
  103. define do_install_mkdir
  104. if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
  105. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
  106. fi
  107. endef
  108. define do_install
  109. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  110. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  111. fi; \
  112. $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
  113. endef
  114. install_lib: libs
  115. $(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
  116. $(call do_install_mkdir,$(libdir_SQ)); \
  117. cp -fpR $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
  118. install_headers:
  119. $(call QUIET_INSTALL, headers) \
  120. $(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
  121. install_pkgconfig: $(LIBTHERMAL_PC)
  122. $(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
  123. $(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
  124. install_doc:
  125. $(Q)$(MAKE) -C Documentation install-man install-html install-examples
  126. install: install_lib install_headers install_pkgconfig
  127. FORCE:
  128. .PHONY: all install clean FORCE