Debian Codegraph @

tools/lib/thermal/Makefile

raw
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 # Most of this file is copied from tools/lib/perf/Makefile
3
4 LIBTHERMAL_VERSION = 0
5 LIBTHERMAL_PATCHLEVEL = 0
6 LIBTHERMAL_EXTRAVERSION = 1
7
8 MAKEFLAGS += --no-print-directory
9
10 ifeq ($(srctree),)
11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 srctree := $(patsubst %/,%,$(dir $(srctree)))
14 # $(info Determined 'srctree' to be $(srctree))
15 endif
16
17 INSTALL = install
18
19 # Use DESTDIR for installing into a different root directory.
20 # This is useful for building a package. The program will be
21 # installed in this directory as if it was the root directory.
22 # Then the build tool can move it later.
23 DESTDIR ?=
24 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25
26 include $(srctree)/tools/scripts/Makefile.include
27 include $(srctree)/tools/scripts/Makefile.arch
28
29 ifeq ($(LP64), 1)
30 libdir_relative = lib64
31 else
32 libdir_relative = lib
33 endif
34
35 prefix ?=
36 libdir = $(prefix)/$(libdir_relative)
37
38 # Shell quotes
39 libdir_SQ = $(subst ','\'',$(libdir))
40 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41
42 # Set compile option CFLAGS
43 ifdef EXTRA_CFLAGS
44 CFLAGS := $(EXTRA_CFLAGS)
45 else
46 CFLAGS := -g -Wall
47 endif
48
49 NL3_CFLAGS = $(shell pkg-config --cflags libnl-3.0 2>/dev/null)
50 ifeq ($(NL3_CFLAGS),)
51 NL3_CFLAGS = -I/usr/include/libnl3
52 endif
53
54 INCLUDES = \
55 -I$(srctree)/tools/lib/thermal/include \
56 -I$(srctree)/tools/lib/ \
57 -I$(srctree)/tools/include \
58 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
59 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
60 -I$(srctree)/tools/include/uapi
61
62 # Append required CFLAGS
63 override CFLAGS += $(EXTRA_WARNINGS)
64 override CFLAGS += -Werror -Wall
65 override CFLAGS += -fPIC
66 override CFLAGS += $(NL3_CFLAGS)
67 override CFLAGS += $(INCLUDES)
68 override CFLAGS += -fvisibility=hidden
69 override CFGLAS += -Wl,-L.
70 override CFGLAS += -Wl,-lthermal
71
72 all:
73
74 export srctree OUTPUT CC LD CFLAGS V
75 export DESTDIR DESTDIR_SQ
76
77 include $(srctree)/tools/build/Makefile.include
78
79 VERSION_SCRIPT := libthermal.map
80
81 PATCHLEVEL = $(LIBTHERMAL_PATCHLEVEL)
82 EXTRAVERSION = $(LIBTHERMAL_EXTRAVERSION)
83 VERSION = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
84
85 LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
86 LIBTHERMAL_A := $(OUTPUT)libthermal.a
87 LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
88 LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
89 LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
90
91 THERMAL_UAPI := include/uapi/linux/thermal.h
92
93 $(THERMAL_UAPI): FORCE
94 ln -sf $(srctree)/$@ $(srctree)/tools/$@
95
96 $(LIBTHERMAL_IN): FORCE
97 $(Q)$(MAKE) $(build)=libthermal
98
99 $(LIBTHERMAL_A): $(LIBTHERMAL_IN)
100 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
101
102 $(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
103 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
104 -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
105 @ln -sf $(@F) $(OUTPUT)libthermal.so
106 @ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
107
108
109 libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
110
111 all: fixdep
112 $(Q)$(MAKE) libs
113
114 clean:
115 $(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
116 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) \
117 .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC) \
118 $(srctree)/tools/$(THERMAL_UAPI)
119
120 $(LIBTHERMAL_PC):
121 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
122 -e "s|@LIBDIR@|$(libdir_SQ)|" \
123 -e "s|@VERSION@|$(VERSION)|" \
124 < libthermal.pc.template > $@
125
126 define do_install_mkdir
127 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
128 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
129 fi
130 endef
131
132 define do_install
133 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
134 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
135 fi; \
136 $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
137 endef
138
139 install_lib: libs
140 $(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
141 $(call do_install_mkdir,$(libdir_SQ)); \
142 cp -fR --preserve=mode,timestamp $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
143
144 install_headers:
145 $(call QUIET_INSTALL, headers) \
146 $(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
147
148 install_pkgconfig: $(LIBTHERMAL_PC)
149 $(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
150 $(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
151
152 install_doc:
153 $(Q)$(MAKE) -C Documentation install-man install-html install-examples
154
155 install: install_lib install_headers install_pkgconfig
156
157 FORCE:
158
159 .PHONY: all install clean FORCE