Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. # Set compile option CFLAGS
  33. ifdef EXTRA_CFLAGS
  34. CFLAGS := $(EXTRA_CFLAGS)
  35. else
  36. CFLAGS := -g -Wall
  37. endif
  38. NL3_CFLAGS = $(shell pkg-config --cflags libnl-3.0 2>/dev/null)
  39. ifeq ($(NL3_CFLAGS),)
  40. NL3_CFLAGS = -I/usr/include/libnl3
  41. endif
  42. INCLUDES = \
  43. -I$(srctree)/tools/lib/thermal/include \
  44. -I$(srctree)/tools/lib/ \
  45. -I$(srctree)/tools/include \
  46. -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
  47. -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
  48. -I$(srctree)/tools/include/uapi
  49. # Append required CFLAGS
  50. override CFLAGS += $(EXTRA_WARNINGS)
  51. override CFLAGS += -Werror -Wall
  52. override CFLAGS += -fPIC
  53. override CFLAGS += $(NL3_CFLAGS)
  54. override CFLAGS += $(INCLUDES)
  55. override CFLAGS += -fvisibility=hidden
  56. override CFGLAS += -Wl,-L.
  57. override CFGLAS += -Wl,-lthermal
  58. all:
  59. export srctree OUTPUT CC LD CFLAGS V
  60. export DESTDIR DESTDIR_SQ
  61. include $(srctree)/tools/build/Makefile.include
  62. VERSION_SCRIPT := libthermal.map
  63. PATCHLEVEL = $(LIBTHERMAL_PATCHLEVEL)
  64. EXTRAVERSION = $(LIBTHERMAL_EXTRAVERSION)
  65. VERSION = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
  66. LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
  67. LIBTHERMAL_A := $(OUTPUT)libthermal.a
  68. LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
  69. LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
  70. LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
  71. THERMAL_UAPI := include/uapi/linux/thermal.h
  72. $(THERMAL_UAPI): FORCE
  73. ln -sf $(srctree)/$@ $(srctree)/tools/$@
  74. $(LIBTHERMAL_IN): FORCE
  75. $(Q)$(MAKE) $(build)=libthermal
  76. $(LIBTHERMAL_A): $(LIBTHERMAL_IN)
  77. $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
  78. $(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
  79. $(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
  80. -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
  81. @ln -sf $(@F) $(OUTPUT)libthermal.so
  82. @ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
  83. libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
  84. all: fixdep
  85. $(Q)$(MAKE) libs
  86. clean:
  87. $(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
  88. *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) \
  89. .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC) \
  90. $(srctree)/tools/$(THERMAL_UAPI)
  91. $(LIBTHERMAL_PC):
  92. $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
  93. -e "s|@LIBDIR@|$(libdir_SQ)|" \
  94. -e "s|@VERSION@|$(VERSION)|" \
  95. < libthermal.pc.template > $@
  96. define do_install_mkdir
  97. if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
  98. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
  99. fi
  100. endef
  101. define do_install
  102. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  103. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  104. fi; \
  105. $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
  106. endef
  107. install_lib: libs
  108. $(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
  109. $(call do_install_mkdir,$(libdir_SQ)); \
  110. cp -fR --preserve=mode,timestamp $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
  111. install_headers:
  112. $(call QUIET_INSTALL, headers) \
  113. $(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
  114. install_pkgconfig: $(LIBTHERMAL_PC)
  115. $(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
  116. $(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
  117. install_doc:
  118. $(Q)$(MAKE) -C Documentation install-man install-html install-examples
  119. install: install_lib install_headers install_pkgconfig
  120. FORCE:
  121. .PHONY: all install clean FORCE