162306a36Sopenharmony_ci# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
262306a36Sopenharmony_ci# Most of this file is copied from tools/lib/perf/Makefile
362306a36Sopenharmony_ci
462306a36Sopenharmony_ciLIBTHERMAL_VERSION = 0
562306a36Sopenharmony_ciLIBTHERMAL_PATCHLEVEL = 0
662306a36Sopenharmony_ciLIBTHERMAL_EXTRAVERSION = 1
762306a36Sopenharmony_ci
862306a36Sopenharmony_ciMAKEFLAGS += --no-print-directory
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ciifeq ($(srctree),)
1162306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
1262306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
1362306a36Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
1462306a36Sopenharmony_ci# $(info Determined 'srctree' to be $(srctree))
1562306a36Sopenharmony_ciendif
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ciINSTALL = install
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci# Use DESTDIR for installing into a different root directory.
2062306a36Sopenharmony_ci# This is useful for building a package. The program will be
2162306a36Sopenharmony_ci# installed in this directory as if it was the root directory.
2262306a36Sopenharmony_ci# Then the build tool can move it later.
2362306a36Sopenharmony_ciDESTDIR ?=
2462306a36Sopenharmony_ciDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciinclude $(srctree)/tools/scripts/Makefile.include
2762306a36Sopenharmony_ciinclude $(srctree)/tools/scripts/Makefile.arch
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ciifeq ($(LP64), 1)
3062306a36Sopenharmony_ci  libdir_relative = lib64
3162306a36Sopenharmony_cielse
3262306a36Sopenharmony_ci  libdir_relative = lib
3362306a36Sopenharmony_ciendif
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciprefix ?=
3662306a36Sopenharmony_cilibdir = $(prefix)/$(libdir_relative)
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci# Shell quotes
3962306a36Sopenharmony_cilibdir_SQ = $(subst ','\'',$(libdir))
4062306a36Sopenharmony_cilibdir_relative_SQ = $(subst ','\'',$(libdir_relative))
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciifeq ("$(origin V)", "command line")
4362306a36Sopenharmony_ci  VERBOSE = $(V)
4462306a36Sopenharmony_ciendif
4562306a36Sopenharmony_ciifndef VERBOSE
4662306a36Sopenharmony_ci  VERBOSE = 0
4762306a36Sopenharmony_ciendif
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ciifeq ($(VERBOSE),1)
5062306a36Sopenharmony_ci  Q =
5162306a36Sopenharmony_cielse
5262306a36Sopenharmony_ci  Q = @
5362306a36Sopenharmony_ciendif
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci# Set compile option CFLAGS
5662306a36Sopenharmony_ciifdef EXTRA_CFLAGS
5762306a36Sopenharmony_ci  CFLAGS := $(EXTRA_CFLAGS)
5862306a36Sopenharmony_cielse
5962306a36Sopenharmony_ci  CFLAGS := -g -Wall
6062306a36Sopenharmony_ciendif
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciINCLUDES = \
6362306a36Sopenharmony_ci-I/usr/include/libnl3 \
6462306a36Sopenharmony_ci-I$(srctree)/tools/lib/thermal/include \
6562306a36Sopenharmony_ci-I$(srctree)/tools/lib/ \
6662306a36Sopenharmony_ci-I$(srctree)/tools/include \
6762306a36Sopenharmony_ci-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
6862306a36Sopenharmony_ci-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
6962306a36Sopenharmony_ci-I$(srctree)/tools/include/uapi
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci# Append required CFLAGS
7262306a36Sopenharmony_cioverride CFLAGS += $(EXTRA_WARNINGS)
7362306a36Sopenharmony_cioverride CFLAGS += -Werror -Wall
7462306a36Sopenharmony_cioverride CFLAGS += -fPIC
7562306a36Sopenharmony_cioverride CFLAGS += $(INCLUDES)
7662306a36Sopenharmony_cioverride CFLAGS += -fvisibility=hidden
7762306a36Sopenharmony_cioverride CFGLAS += -Wl,-L.
7862306a36Sopenharmony_cioverride CFGLAS += -Wl,-lthermal
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ciall:
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS V
8362306a36Sopenharmony_ciexport DESTDIR DESTDIR_SQ
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciVERSION_SCRIPT := libthermal.map
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ciPATCHLEVEL    = $(LIBTHERMAL_PATCHLEVEL)
9062306a36Sopenharmony_ciEXTRAVERSION  = $(LIBTHERMAL_EXTRAVERSION)
9162306a36Sopenharmony_ciVERSION       = $(LIBTHERMAL_VERSION).$(LIBTHERMAL_PATCHLEVEL).$(LIBTHERMAL_EXTRAVERSION)
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ciLIBTHERMAL_SO := $(OUTPUT)libthermal.so.$(VERSION)
9462306a36Sopenharmony_ciLIBTHERMAL_A  := $(OUTPUT)libthermal.a
9562306a36Sopenharmony_ciLIBTHERMAL_IN := $(OUTPUT)libthermal-in.o
9662306a36Sopenharmony_ciLIBTHERMAL_PC := $(OUTPUT)libthermal.pc
9762306a36Sopenharmony_ciLIBTHERMAL_ALL := $(LIBTHERMAL_A) $(OUTPUT)libthermal.so*
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciTHERMAL_UAPI := include/uapi/linux/thermal.h
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci$(THERMAL_UAPI): FORCE
10262306a36Sopenharmony_ci	ln -sf $(srctree)/$@ $(srctree)/tools/$@
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci$(LIBTHERMAL_IN): FORCE
10562306a36Sopenharmony_ci	$(Q)$(MAKE) $(build)=libthermal
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci$(LIBTHERMAL_A): $(LIBTHERMAL_IN)
10862306a36Sopenharmony_ci	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBTHERMAL_IN)
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci$(LIBTHERMAL_SO): $(LIBTHERMAL_IN)
11162306a36Sopenharmony_ci	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libthermal.so \
11262306a36Sopenharmony_ci                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
11362306a36Sopenharmony_ci	@ln -sf $(@F) $(OUTPUT)libthermal.so
11462306a36Sopenharmony_ci	@ln -sf $(@F) $(OUTPUT)libthermal.so.$(LIBTHERMAL_VERSION)
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_cilibs: $(THERMAL_UAPI) $(LIBTHERMAL_A) $(LIBTHERMAL_SO) $(LIBTHERMAL_PC)
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ciall: fixdep
12062306a36Sopenharmony_ci	$(Q)$(MAKE) libs
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ciclean:
12362306a36Sopenharmony_ci	$(call QUIET_CLEAN, libthermal) $(RM) $(LIBTHERMAL_A) \
12462306a36Sopenharmony_ci                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBTHERMAL_VERSION) .*.d .*.cmd LIBTHERMAL-CFLAGS $(LIBTHERMAL_PC)
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci$(LIBTHERMAL_PC):
12762306a36Sopenharmony_ci	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
12862306a36Sopenharmony_ci		-e "s|@LIBDIR@|$(libdir_SQ)|" \
12962306a36Sopenharmony_ci		-e "s|@VERSION@|$(VERSION)|" \
13062306a36Sopenharmony_ci		< libthermal.pc.template > $@
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_cidefine do_install_mkdir
13362306a36Sopenharmony_ci	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
13462306a36Sopenharmony_ci		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
13562306a36Sopenharmony_ci	fi
13662306a36Sopenharmony_ciendef
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_cidefine do_install
13962306a36Sopenharmony_ci	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
14062306a36Sopenharmony_ci		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
14162306a36Sopenharmony_ci	fi;                                             \
14262306a36Sopenharmony_ci	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
14362306a36Sopenharmony_ciendef
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciinstall_lib: libs
14662306a36Sopenharmony_ci	$(call QUIET_INSTALL, $(LIBTHERMAL_ALL)) \
14762306a36Sopenharmony_ci		$(call do_install_mkdir,$(libdir_SQ)); \
14862306a36Sopenharmony_ci		cp -fpR $(LIBTHERMAL_ALL) $(DESTDIR)$(libdir_SQ)
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ciinstall_headers:
15162306a36Sopenharmony_ci	$(call QUIET_INSTALL, headers) \
15262306a36Sopenharmony_ci		$(call do_install,include/thermal.h,$(prefix)/include/thermal,644); \
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ciinstall_pkgconfig: $(LIBTHERMAL_PC)
15562306a36Sopenharmony_ci	$(call QUIET_INSTALL, $(LIBTHERMAL_PC)) \
15662306a36Sopenharmony_ci		$(call do_install,$(LIBTHERMAL_PC),$(libdir_SQ)/pkgconfig,644)
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciinstall_doc:
15962306a36Sopenharmony_ci	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ciinstall: install_lib install_headers install_pkgconfig
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ciFORCE:
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci.PHONY: all install clean FORCE
166