linux/tools/power/cpupower
Roman Storozhenko 3a5bb5066f cpupower: fix lib default installation path
Invocation the tool built with the default settings fails:
$ cpupower
cpupower: error while loading shared libraries: libcpupower.so.1: cannot
open shared object file: No such file or directory

The issue is that Makefile puts the library to "/usr/lib64" dir for a 64
bit machine. This is wrong. According to the "File hierarchy standard
specification:
https://en.wikipedia.org/wiki/Filesystem_Hierarchy_Standard
https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.pdf

"/usr/lib<qual>" dirs are intended for alternative-format libraries
(e.g., "/usr/lib32" for 32-bit libraries on a 64-bit machine (optional)).

The utility is built for the current machine and doesn't handle
'CROSS_COMPILE' and 'ARCH' env variables. It also doesn't change bit
depth. So the result is always the same - binary for x86_64
architecture. Therefore the library should be put in the '/usr/lib'
dir regardless of the build options.
This is the case for all the distros that comply with the
'File Hierarchy Standard 3.0" by Linux Foundation. Most of the distros
comply with it. For example, one can check this by examining the
"/usr/lb64" dir on debian-based distros and find that it contains only
"/usr/lib64/ld-linux-x86-64.so.2". And examine that "/usr/lib" contains
both 32 and 64 bit code:
find /usr/lib -name "*.so*" -type f | xargs file | grep 32-bit
find /usr/lib -name "*.so*" -type f | xargs file | grep 64-bit

Fix the issue by changing library destination dir to "/usr/lib".

Signed-off-by: Roman Storozhenko <romeusmeister@gmail.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2024-07-02 15:30:32 -06:00
..
bench cpupower: Disable direct build of the 'bench' subproject 2024-06-28 15:55:20 -06:00
debug treewide: Replace GPLv2 boilerplate/reference with SPDX - gpl-2.0_385.RULE 2022-06-10 14:51:36 +02:00
lib cpupower: Add is_valid_path API 2023-07-18 16:06:44 -06:00
man cpupower: Remove absent 'v' parameter from monitor man page 2024-06-20 09:48:13 -06:00
po cpupower: Add Georgian translation 2022-11-30 16:32:34 -07:00
utils cpupower: Change the var type of the 'monitor' subcommand display mode 2024-06-20 10:08:08 -06:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
cpupower-completion.sh cpupower : Auto-completion for cpupower tool 2018-12-05 07:52:45 -07:00
Makefile cpupower: fix lib default installation path 2024-07-02 15:30:32 -06:00
README cpupower: Improve cpupower build process description 2024-06-18 12:09:09 -06:00
TODO tools/power/cpupower/{ToDo => TODO}: Rename the todo file 2022-01-24 09:07:11 -07:00

The cpupower package consists of the following elements:

requirements
------------

On x86 pciutils is needed at runtime (-lpci).
For compilation pciutils-devel (pci/pci.h) and a gcc version
providing cpuid.h is needed.
For both it's not explicitly checked for (yet).


libcpupower
----------

"libcpupower" is a library which offers a unified access method for userspace
tools and programs to the cpufreq core and drivers in the Linux kernel. This
allows for code reduction in userspace tools, a clean implementation of
the interaction to the cpufreq core, and support for both the sysfs and proc
interfaces [depending on configuration, see below].


compilation and installation
----------------------------

There are 2 output directories - one for the build output and another for
the installation of the build results, that is the utility, library,
man pages, etc...

default directory
-----------------

In the case of default directory, build and install process requires no
additional parameters:

build
-----

$ make

The output directory for the 'make' command is the current directory and
its subdirs in the kernel tree:
tools/power/cpupower

install
-------

$ sudo make install

'make install' command puts targets to default system dirs:

-----------------------------------------------------------------------
| Installing file        |               System dir                   |
-----------------------------------------------------------------------
| libcpupower            | /usr/lib                                   |
-----------------------------------------------------------------------
| cpupower               | /usr/bin                                   |
-----------------------------------------------------------------------
| cpufreq-bench_plot.sh  | /usr/bin                                   |
-----------------------------------------------------------------------
| man pages              | /usr/man                                   |
-----------------------------------------------------------------------

To put it in other words it makes build results available system-wide,
enabling any user to simply start using it without any additional steps

custom directory
----------------

There are 2 make's command-line variables 'O' and 'DESTDIR' that setup
appropriate dirs:
'O' - build directory
'DESTDIR' - installation directory. This variable could also be setup in
the 'CONFIGURATION' block of the "Makefile"

build
-----

$ make O=<your_custom_build_catalog>

Example:
$ make O=/home/hedin/prj/cpupower/build

install
-------

$ make O=<your_custom_build_catalog> DESTDIR=<your_custom_install_catalog>

Example:
$ make O=/home/hedin/prj/cpupower/build DESTDIR=/home/hedin/prj/cpupower \
> install

Notice that both variables 'O' and 'DESTDIR' have been provided. The reason
is that the build results are saved in the custom output dir defined by 'O'
variable. So, this dir is the source for the installation step. If only
'DESTDIR' were provided then the 'install' target would assume that the
build directory is the current one, build everything there and install
from the current dir.

The files will be installed to the following dirs:

-----------------------------------------------------------------------
| Installing file        |               System dir                   |
-----------------------------------------------------------------------
| libcpupower            | ${DESTDIR}/usr/lib                         |
-----------------------------------------------------------------------
| cpupower               | ${DESTDIR}/usr/bin                         |
-----------------------------------------------------------------------
| cpufreq-bench_plot.sh  | ${DESTDIR}/usr/bin                         |
-----------------------------------------------------------------------
| man pages              | ${DESTDIR}/usr/man                         |
-----------------------------------------------------------------------

If you look at the table for the default 'make' output dirs you will
notice that the only difference with the non-default case is the
${DESTDIR} prefix. So, the structure of the output dirs remains the same
regardles of the root output directory.


clean and uninstall
-------------------

'clean' target is intended for cleanup the build catalog from build results
'uninstall' target is intended for removing installed files from the
installation directory

default directory
-----------------

This case is a straightforward one:
$ make clean
$ make uninstall

custom directory
----------------

Use 'O' command line variable to remove previously built files from the
build dir:
$ make O=<your_custom_build_catalog> clean

Example:
$ make O=/home/hedin/prj/cpupower/build clean

Use 'DESTDIR' command line variable to uninstall previously installed files
from the given dir:
$ make DESTDIR=<your_custom_install_catalog>

Example:
make DESTDIR=/home/hedin/prj/cpupower uninstall


running the tool
----------------

default directory
-----------------

$ sudo cpupower

custom directory
----------------

When it comes to run the utility from the custom build catalog things
become a little bit complicated as 'just run' approach doesn't work.
Assuming that the current dir is '<your_custom_install_catalog>/usr',
issuing the following command:

$ sudo ./bin/cpupower
will produce the following error output:
./bin/cpupower: error while loading shared libraries: libcpupower.so.1:
cannot open shared object file: No such file or directory

The issue is that binary cannot find the 'libcpupower' library. So, we
shall point to the lib dir:
sudo LD_LIBRARY_PATH=lib64/ ./bin/cpupower


THANKS
------
Many thanks to Mattia Dongili who wrote the autotoolization and
libtoolization, the manpages and the italian language file for cpupower;
to Dave Jones for his feedback and his dump_psb tool; to Bruno Ducrot for his
powernow-k8-decode and intel_gsic tools as well as the french language file;
and to various others commenting on the previous (pre-)releases of 
cpupower.


        Dominik Brodowski