Linux – Make install into a temporary directory

linuxmake

I wish to do the following:

Make from an open source project to compile/link into libraries etc. However, I don't want to actually run this locally. I want to package it up into an rpm so that it can be installed into the correct directories on other machines (which would of course have similar architecture). I want it to compile and link and create symbolic links as if it were going to install under /usr/local, but I don't actually want this to go to a directory under /usr/local/ but to some temporary directory that can be wiped out without deleting files placed there by other packages.

Is there some parameter to make install that would let this happen – that is build as if it were to be installed under /usr/local but actually place the "installation" under ~/tmp/usr/local, for example.

I've looked into simply NOT running make install but stop at make, but this intermingles executables, object code, and libraries in the source directory.

Best Answer

The answer to this question depends on which open source project you're attempting to install this way. The general answer is that some open source projects have Makefiles which provide optional variables for this purpose. One specific example of this is gdb, whose top level Makefile uses (but does not seem to assign) a DESTDIR variable, and if I run this command in the gdb build directory,

make DESTDIR=/tmp install

it prepends /tmp to each destination path before copying the file.

Another more difficult approach is to do the entire build, install and all, in a chroot environment. Using something like OverlayFS can make that easier, but this is not typically the path of least resistance.

Another possibility, which is probably easier if you're already using a Debian flavor (which includes Ubuntu among many others), is to fetch the Debian source package corresponding to the open source project (this approach is unlikely to be easy if there is no such source package) and follow the instructions to build the Debian package from that source. If you really need a .rpm rather than a .deb you can convert the .deb to a .rpm, or perhaps you can construct a .rpm from the directory structure left behind in the process of building the .deb. This answer is one source of information about building a Debian package from the source.

For the latest openssl (mentioned in a comment but not yet mentioned in the question) the INSTALL file says this:

 Package builders who want to configure the library for standard
 locations, but have the package installed somewhere else so that
 it can easily be packaged, can use

   $ make DESTDIR=/tmp/package-root install         # Unix
   $ mms/macro="DESTDIR=TMP:[PACKAGE-ROOT]" install ! OpenVMS

 The specified destination directory will be prepended to all
 installation target paths.

That varies across different versions of openssl; for 1.0.2 INSTALL says this:

 Package builders who want to configure the library for standard
 locations, but have the package installed somewhere else so that
 it can easily be packaged, can use

   $ make INSTALL_PREFIX=/tmp/package-root install

 (or specify "--install_prefix=/tmp/package-root" as a configure
 option).  The specified prefix will be prepended to all
 installation target filenames.

The idea is very much the same, with slightly different details.

Related Question