emsec / hal

HAL – The Hardware Analyzer
MIT License
619 stars 74 forks source link

`make install` attempts to write to `/etc` regardless of specified destination directory #524

Open xiota opened 1 year ago

xiota commented 1 year ago

Describe the bug

After successfully downloading and building the 4.2.0 source tarball, attempting to install with either make install or cmake --install produces errors.

To Reproduce

$ cmake -B build -S "hal-4.2.0" \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX='/usr'
...

$ cmake --build build
...

$ pkgdir="$PWD/pkg"
$ mkdir -p "$pkgdir"

$ make DESTDIR="$pkgdir" install

make: *** No rule to make target 'install'.  Stop.

$ DESTDIR="$pkgdir" cmake --install build
...

-- Copy file /usr/share/hal/ld_conf/hal.conf to /etc/ld.so.conf.d/
Error copying file "hal.conf" to "/etc/ld.so.conf.d/".
-- Running: ldconfig
ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
CMake Warning at build/post_install.cmake:11 (message):
  ldconfig failed
Call Stack (most recent call first):
  build/cmake_install.cmake:147 (include)

...

Expected behavior

xiota commented 1 year ago

make install with git checkout (cb176c3a194b700f4efed433cde958d1048022b2) does not have the same error as when trying to install from the 4.2.0 tarball. However, it does have the same error message as cmake --install from the tarball. I found old logs, and the same error did occur previously (pre-4.2.0 git 1c499268a9f).

-- Copy file /usr/share/hal/ld_conf/hal.conf to /etc/ld.so.conf.d/
Error copying file "hal.conf" to "/etc/ld.so.conf.d/".
-- Running: ldconfig
ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied
CMake Warning at build/post_install.cmake:11 (message):
  ldconfig failed
Call Stack (most recent call first):
  build/cmake_install.cmake:147 (include)
xiota commented 1 year ago

I believe the problem may be:

https://github.com/emsec/hal/blob/2ab94d205e13cf32800020ae306c1fc60a6aa840/cmake/post_install.cmake.in#L6

Perhaps changing the line to the following would fix it:

 execute_process(COMMAND ${CMAKE_COMMAND} -E copy hal.conf "$ENV{DESTDIR}/etc/ld.so.conf.d/") 

I have not tested the change because of the length of time building takes.