xref: /linux/tools/lib/thermal/Makefile (revision de69d56daac6d9b98fa384184078751db1288144)
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
49INCLUDES = \
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
58# Append required CFLAGS
59override CFLAGS += $(EXTRA_WARNINGS)
60override CFLAGS += -Werror -Wall
61override CFLAGS += -fPIC
62override CFLAGS += $(INCLUDES)
63override CFLAGS += -fvisibility=hidden
64override CFGLAS += -Wl,-L.
65override CFGLAS += -Wl,-lthermal
66
67all:
68
69export srctree OUTPUT CC LD CFLAGS V
70export DESTDIR DESTDIR_SQ
71
72include $(srctree)/tools/build/Makefile.include
73
74VERSION_SCRIPT := libthermal.map
75
76PATCHLEVEL    = $(LIBTHERMAL_PATCHLEVEL)
77EXTRAVERSION  = $(LIBTHERMAL_EXTRAVERSION)
78VERSION       = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
79
80LIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
81LIBTHERMAL_A  := $(OUTPUT)libthermal.a
82LIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
83LIBTHERMAL_PC := $(OUTPUT)libthermal.pc
84LIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
85
86THERMAL_UAPI := include/uapi/linux/thermal.h
87
88$(THERMAL_UAPI): FORCE
89	ln -sf $(srctree)/$@ $(srctree)/tools/$@
90
91$(LIBTHERMAL_IN): FORCE
92	$(Q)$(MAKE) $(build)=libthermal
93
94$(LIBTHERMAL_A): $(LIBTHERMAL_IN)
95	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
96
97$(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
98	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
99                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
100	@ln -sf $(@F) $(OUTPUT)libthermal.so
101	@ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
102
103
104libs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
105
106all: fixdep
107	$(Q)$(MAKE) libs
108
109clean:
110	$(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
111                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) \
112                .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC) \
113                $(srctree)/tools/$(THERMAL_UAPI)
114
115$(LIBTHERMAL_PC):
116	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
117		-e "s|@LIBDIR@|$(libdir_SQ)|" \
118		-e "s|@VERSION@|$(VERSION)|" \
119		< libthermal.pc.template > $@
120
121define do_install_mkdir
122	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
123		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
124	fi
125endef
126
127define do_install
128	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
129		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
130	fi;                                             \
131	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
132endef
133
134install_lib: libs
135	$(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
136		$(call do_install_mkdir,$(libdir_SQ)); \
137		cp -fpR $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
138
139install_headers:
140	$(call QUIET_INSTALL, headers) \
141		$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
142
143install_pkgconfig: $(LIBTHERMAL_PC)
144	$(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
145		$(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
146
147install_doc:
148	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
149
150install: install_lib install_headers install_pkgconfig
151
152FORCE:
153
154.PHONY: all install clean FORCE
155