xref: /linux/tools/lib/thermal/Makefile (revision ec2e0fb07d789976c601bec19ecced7a501c3705)
1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2# Most of this file is copied from tools/lib/perf/Makefile
3
4LIBTHERMAL_VERSION = 0
5LIBTHERMAL_PATCHLEVEL = 0
6LIBTHERMAL_EXTRAVERSION = 1
7
8MAKEFLAGS += --no-print-directory
9
10ifeq ($(srctree),)
11srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12srctree := $(patsubst %/,%,$(dir $(srctree)))
13srctree := $(patsubst %/,%,$(dir $(srctree)))
14# $(info Determined 'srctree' to be $(srctree))
15endif
16
17INSTALL = 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.
23DESTDIR ?=
24DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25
26include $(srctree)/tools/scripts/Makefile.include
27include $(srctree)/tools/scripts/Makefile.arch
28
29ifeq ($(LP64), 1)
30  libdir_relative = lib64
31else
32  libdir_relative = lib
33endif
34
35prefix ?=
36libdir = $(prefix)/$(libdir_relative)
37
38# Shell quotes
39libdir_SQ = $(subst ','\'',$(libdir))
40libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41
42# Set compile option CFLAGS
43ifdef EXTRA_CFLAGS
44  CFLAGS := $(EXTRA_CFLAGS)
45else
46  CFLAGS := -g -Wall
47endif
48
49NL3_CFLAGS = $(shell pkg-config --cflags libnl-3.0 2>/dev/null)
50ifeq ($(NL3_CFLAGS),)
51NL3_CFLAGS = -I/usr/include/libnl3
52endif
53
54INCLUDES = \
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
63override CFLAGS += $(EXTRA_WARNINGS)
64override CFLAGS += -Werror -Wall
65override CFLAGS += -fPIC
66override CFLAGS += $(NL3_CFLAGS)
67override CFLAGS += $(INCLUDES)
68override CFLAGS += -fvisibility=hidden
69override CFGLAS += -Wl,-L.
70override CFGLAS += -Wl,-lthermal
71
72all:
73
74export srctree OUTPUT CC LD CFLAGS V
75export DESTDIR DESTDIR_SQ
76
77include $(srctree)/tools/build/Makefile.include
78
79VERSION_SCRIPT := libthermal.map
80
81PATCHLEVEL    = $(LIBTHERMAL_PATCHLEVEL)
82EXTRAVERSION  = $(LIBTHERMAL_EXTRAVERSION)
83VERSION       = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
84
85LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
86LIBTHERMAL_A  := $(OUTPUT)libthermal.a
87LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
88LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
89LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
90
91THERMAL_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
109libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
110
111all: fixdep
112	$(Q)$(MAKE) libs
113
114clean:
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
126define do_install_mkdir
127	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
128		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
129	fi
130endef
131
132define 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'
137endef
138
139install_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
144install_headers:
145	$(call QUIET_INSTALL, headers) \
146		$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
147
148install_pkgconfig: $(LIBTHERMAL_PC)
149	$(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
150		$(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
151
152install_doc:
153	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
154
155install: install_lib install_headers install_pkgconfig
156
157FORCE:
158
159.PHONY: all install clean FORCE
160