xref: /linux/tools/thermal/lib/Makefile (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*3b7c5e8aSDaniel Lezcano# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2*3b7c5e8aSDaniel Lezcano# Most of this file is copied from tools/lib/perf/Makefile
3*3b7c5e8aSDaniel Lezcano
4*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_VERSION = 0
5*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_PATCHLEVEL = 0
6*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_EXTRAVERSION = 1
7*3b7c5e8aSDaniel Lezcano
8*3b7c5e8aSDaniel LezcanoMAKEFLAGS += --no-print-directory
9*3b7c5e8aSDaniel Lezcano
10*3b7c5e8aSDaniel Lezcanoifeq ($(srctree),)
11*3b7c5e8aSDaniel Lezcanosrctree := $(patsubst %/,%,$(dir $(CURDIR)))
12*3b7c5e8aSDaniel Lezcanosrctree := $(patsubst %/,%,$(dir $(srctree)))
13*3b7c5e8aSDaniel Lezcanosrctree := $(patsubst %/,%,$(dir $(srctree)))
14*3b7c5e8aSDaniel Lezcano# $(info Determined 'srctree' to be $(srctree))
15*3b7c5e8aSDaniel Lezcanoendif
16*3b7c5e8aSDaniel Lezcano
17*3b7c5e8aSDaniel LezcanoINSTALL = install
18*3b7c5e8aSDaniel Lezcano
19*3b7c5e8aSDaniel Lezcano# Use DESTDIR for installing into a different root directory.
20*3b7c5e8aSDaniel Lezcano# This is useful for building a package. The program will be
21*3b7c5e8aSDaniel Lezcano# installed in this directory as if it was the root directory.
22*3b7c5e8aSDaniel Lezcano# Then the build tool can move it later.
23*3b7c5e8aSDaniel LezcanoDESTDIR ?=
24*3b7c5e8aSDaniel LezcanoDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25*3b7c5e8aSDaniel Lezcano
26*3b7c5e8aSDaniel Lezcanoinclude $(srctree)/tools/scripts/Makefile.include
27*3b7c5e8aSDaniel Lezcanoinclude $(srctree)/tools/scripts/Makefile.arch
28*3b7c5e8aSDaniel Lezcano
29*3b7c5e8aSDaniel Lezcanoifeq ($(LP64), 1)
30*3b7c5e8aSDaniel Lezcano  libdir_relative = lib64
31*3b7c5e8aSDaniel Lezcanoelse
32*3b7c5e8aSDaniel Lezcano  libdir_relative = lib
33*3b7c5e8aSDaniel Lezcanoendif
34*3b7c5e8aSDaniel Lezcano
35*3b7c5e8aSDaniel Lezcanoprefix ?=
36*3b7c5e8aSDaniel Lezcanolibdir = $(prefix)/$(libdir_relative)
37*3b7c5e8aSDaniel Lezcano
38*3b7c5e8aSDaniel Lezcano# Shell quotes
39*3b7c5e8aSDaniel Lezcanolibdir_SQ = $(subst ','\'',$(libdir))
40*3b7c5e8aSDaniel Lezcanolibdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41*3b7c5e8aSDaniel Lezcano
42*3b7c5e8aSDaniel Lezcanoifeq ("$(origin V)", "command line")
43*3b7c5e8aSDaniel Lezcano  VERBOSE = $(V)
44*3b7c5e8aSDaniel Lezcanoendif
45*3b7c5e8aSDaniel Lezcanoifndef VERBOSE
46*3b7c5e8aSDaniel Lezcano  VERBOSE = 0
47*3b7c5e8aSDaniel Lezcanoendif
48*3b7c5e8aSDaniel Lezcano
49*3b7c5e8aSDaniel Lezcanoifeq ($(VERBOSE),1)
50*3b7c5e8aSDaniel Lezcano  Q =
51*3b7c5e8aSDaniel Lezcanoelse
52*3b7c5e8aSDaniel Lezcano  Q = @
53*3b7c5e8aSDaniel Lezcanoendif
54*3b7c5e8aSDaniel Lezcano
55*3b7c5e8aSDaniel Lezcano# Set compile option CFLAGS
56*3b7c5e8aSDaniel Lezcanoifdef EXTRA_CFLAGS
57*3b7c5e8aSDaniel Lezcano  CFLAGS := $(EXTRA_CFLAGS)
58*3b7c5e8aSDaniel Lezcanoelse
59*3b7c5e8aSDaniel Lezcano  CFLAGS := -g -Wall
60*3b7c5e8aSDaniel Lezcanoendif
61*3b7c5e8aSDaniel Lezcano
62*3b7c5e8aSDaniel LezcanoINCLUDES = \
63*3b7c5e8aSDaniel Lezcano-I/usr/include/libnl3 \
64*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/lib/thermal/include \
65*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/lib/ \
66*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/include \
67*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
68*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
69*3b7c5e8aSDaniel Lezcano-I$(srctree)/tools/include/uapi
70*3b7c5e8aSDaniel Lezcano
71*3b7c5e8aSDaniel Lezcano# Append required CFLAGS
72*3b7c5e8aSDaniel Lezcanooverride CFLAGS += $(EXTRA_WARNINGS)
73*3b7c5e8aSDaniel Lezcanooverride CFLAGS += -Werror -Wall
74*3b7c5e8aSDaniel Lezcanooverride CFLAGS += -fPIC
75*3b7c5e8aSDaniel Lezcanooverride CFLAGS += $(INCLUDES)
76*3b7c5e8aSDaniel Lezcanooverride CFGLAS += -Wl,-L.
77*3b7c5e8aSDaniel Lezcanooverride CFGLAS += -Wl,-lthermal
78*3b7c5e8aSDaniel Lezcano
79*3b7c5e8aSDaniel Lezcanoall:
80*3b7c5e8aSDaniel Lezcano
81*3b7c5e8aSDaniel Lezcanoexport srctree OUTPUT CC LD CFLAGS V
82*3b7c5e8aSDaniel Lezcanoexport DESTDIR DESTDIR_SQ
83*3b7c5e8aSDaniel Lezcano
84*3b7c5e8aSDaniel Lezcanoinclude $(srctree)/tools/build/Makefile.include
85*3b7c5e8aSDaniel Lezcano
86*3b7c5e8aSDaniel LezcanoPATCHLEVEL    = $(LIBTHERMAL_TOOLS_PATCHLEVEL)
87*3b7c5e8aSDaniel LezcanoEXTRAVERSION  = $(LIBTHERMAL_TOOLS_EXTRAVERSION)
88*3b7c5e8aSDaniel LezcanoVERSION       = $(LIBTHERMAL_TOOLS_VERSION).$(LIBTHERMAL_TOOLS_PATCHLEVEL).$(LIBTHERMAL_TOOLS_EXTRAVERSION)
89*3b7c5e8aSDaniel Lezcano
90*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_SO := $(OUTPUT)libthermal_tools.so.$(VERSION)
91*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_A  := $(OUTPUT)libthermal_tools.a
92*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_IN := $(OUTPUT)libthermal_tools-in.o
93*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_PC := $(OUTPUT)libthermal_tools.pc
94*3b7c5e8aSDaniel Lezcano
95*3b7c5e8aSDaniel LezcanoLIBTHERMAL_TOOLS_ALL := $(LIBTHERMAL_TOOLS_A) $(OUTPUT)libthermal_tools.so*
96*3b7c5e8aSDaniel Lezcano
97*3b7c5e8aSDaniel Lezcano$(LIBTHERMAL_TOOLS_IN): FORCE
98*3b7c5e8aSDaniel Lezcano	$(Q)$(MAKE) $(build)=libthermal_tools
99*3b7c5e8aSDaniel Lezcano
100*3b7c5e8aSDaniel Lezcano$(LIBTHERMAL_TOOLS_A): $(LIBTHERMAL_TOOLS_IN)
101*3b7c5e8aSDaniel Lezcano	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_TOOLS_IN)
102*3b7c5e8aSDaniel Lezcano
103*3b7c5e8aSDaniel Lezcano$(LIBTHERMAL_TOOLS_SO): $(LIBTHERMAL_TOOLS_IN)
104*3b7c5e8aSDaniel Lezcano	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal_tools.so $^ -o $@
105*3b7c5e8aSDaniel Lezcano	@ln -sf $(@F) $(OUTPUT)libthermal_tools.so
106*3b7c5e8aSDaniel Lezcano	@ln -sf $(@F) $(OUTPUT)libthermal_tools.so.$(LIBTHERMAL_TOOLS_VERSION)
107*3b7c5e8aSDaniel Lezcano
108*3b7c5e8aSDaniel Lezcano
109*3b7c5e8aSDaniel Lezcanolibs: $(LIBTHERMAL_TOOLS_A) $(LIBTHERMAL_TOOLS_SO) $(LIBTHERMAL_TOOLS_PC)
110*3b7c5e8aSDaniel Lezcano
111*3b7c5e8aSDaniel Lezcanoall: fixdep
112*3b7c5e8aSDaniel Lezcano	$(Q)$(MAKE) libs
113*3b7c5e8aSDaniel Lezcano
114*3b7c5e8aSDaniel Lezcanoclean:
115*3b7c5e8aSDaniel Lezcano	$(call QUIET_CLEAN, libthermal_tools) $(RM) $(LIBTHERMAL_TOOLS_A) \
116*3b7c5e8aSDaniel Lezcano                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_TOOLS_VERSION) .*.d .*.cmd LIBTHERMAL_TOOLS-CFLAGS $(LIBTHERMAL_TOOLS_PC)
117*3b7c5e8aSDaniel Lezcano
118*3b7c5e8aSDaniel Lezcano$(LIBTHERMAL_TOOLS_PC):
119*3b7c5e8aSDaniel Lezcano	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
120*3b7c5e8aSDaniel Lezcano		-e "s|@LIBDIR@|$(libdir_SQ)|" \
121*3b7c5e8aSDaniel Lezcano		-e "s|@VERSION@|$(VERSION)|" \
122*3b7c5e8aSDaniel Lezcano		< libthermal_tools.pc.template > $@
123*3b7c5e8aSDaniel Lezcano
124*3b7c5e8aSDaniel Lezcanodefine do_install_mkdir
125*3b7c5e8aSDaniel Lezcano	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
126*3b7c5e8aSDaniel Lezcano		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
127*3b7c5e8aSDaniel Lezcano	fi
128*3b7c5e8aSDaniel Lezcanoendef
129*3b7c5e8aSDaniel Lezcano
130*3b7c5e8aSDaniel Lezcanodefine do_install
131*3b7c5e8aSDaniel Lezcano	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
132*3b7c5e8aSDaniel Lezcano		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
133*3b7c5e8aSDaniel Lezcano	fi;                                             \
134*3b7c5e8aSDaniel Lezcano	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
135*3b7c5e8aSDaniel Lezcanoendef
136*3b7c5e8aSDaniel Lezcano
137*3b7c5e8aSDaniel Lezcanoinstall_lib: libs
138*3b7c5e8aSDaniel Lezcano	$(call QUIET_INSTALL, $(LIBTHERMAL_TOOLS_ALL)) \
139*3b7c5e8aSDaniel Lezcano		$(call do_install_mkdir,$(libdir_SQ)); \
140*3b7c5e8aSDaniel Lezcano		cp -fpR $(LIBTHERMAL_TOOLS_ALL) $(DESTDIR)$(libdir_SQ)
141*3b7c5e8aSDaniel Lezcano
142*3b7c5e8aSDaniel Lezcanoinstall_headers:
143*3b7c5e8aSDaniel Lezcano	$(call QUIET_INSTALL, headers) \
144*3b7c5e8aSDaniel Lezcano		$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
145*3b7c5e8aSDaniel Lezcano
146*3b7c5e8aSDaniel Lezcanoinstall_pkgconfig: $(LIBTHERMAL_TOOLS_PC)
147*3b7c5e8aSDaniel Lezcano	$(call QUIET_INSTALL, $(LIBTHERMAL_TOOLS_PC)) \
148*3b7c5e8aSDaniel Lezcano		$(call do_install,$(LIBTHERMAL_TOOLS_PC),$(libdir_SQ)/pkgconfig,644)
149*3b7c5e8aSDaniel Lezcano
150*3b7c5e8aSDaniel Lezcanoinstall_doc:
151*3b7c5e8aSDaniel Lezcano	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
152*3b7c5e8aSDaniel Lezcano
153*3b7c5e8aSDaniel Lezcano#install: install_lib install_headers install_pkgconfig install_doc
154*3b7c5e8aSDaniel Lezcanoinstall: install_lib install_headers install_pkgconfig
155*3b7c5e8aSDaniel Lezcano
156*3b7c5e8aSDaniel LezcanoFORCE:
157*3b7c5e8aSDaniel Lezcano
158*3b7c5e8aSDaniel Lezcano.PHONY: all install clean FORCE
159