4

In the program GNU Stow, the symlink farm manager/package manager/whatever you want to call it, you can run the following commands to install a package to /usr/local:

./configure --prefix=/usr/local
make
sudo make prefix=/usr/local/stow/foo-1.2 install # well not nessecarily sudo but this is personal preference 
cd /usr/local/stow
sudo stow foo-1.2 # you have to have sudo here

Basically you are tricking the package so that programs link against /usr/local, but it is actually installed in /usr/local/stow/foo-1.2.

But what if there is no configure script? How can I trick it then? Some notable programs without configure scripts:

  • bzip2 (this is the program I wrote the question for)
  • R (the programming language)
fosslinux
  • 143
  • 7

1 Answers1

3

First off, when using stow with a GNU autotools configure script, use

$ ./configure --prefix=/usr/local/stow/package-version

That way you don't have to repeat yourself when you invoke make.

bzip2 comes with a ready-made Makefile. It also has a README file that explains exactly how to install it in a non-standard location:

HOW TO BUILD -- UNIX

Type 'make'.  This builds the library libbz2.a and then the programs
bzip2 and bzip2recover.  Six self-tests are run.  If the self-tests
complete ok, carry on to installation:

To install in /usr/local/bin, /usr/local/lib, /usr/local/man and
/usr/local/include, type

   make install

To install somewhere else, eg, /xxx/yyy/{bin,lib,man,include}, type

   make install PREFIX=/xxx/yyy

This means that you may use

$ make install PREFIX=/usr/local/stow/bzip2-1.0.6

if you wish.

R comes with a configure script, at least in the source distribution of version 3.4.1 which I downloaded for testing.

Programs that build using CMake may be installed in a configurable location using

$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/stow/package-version .
$ make && sudo make install

If GNU autotools haven't been used to create a configure script, and if it's not a CMake project, then do read the README and/or INSTALL file about how to install the program (you should obviously do this nonetheless). Most programs are able to install in non-default locations quite easily.

If worse comes to worse, just read the Makefile.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • Hold on, back up. I'm a bit confused. Look at this: https://www.gnu.org/software/stow/manual/stow.html#Compile_002dtime-vs-Install_002dtime. Won't this mean that I have to "trick" it, as I stated in my original question, in order to ensure linking problems are fixed? And also will it still work in the way I want it to: being to swap versions quickly and easily? – fosslinux Aug 19 '17 at 07:09
  • @ubashu Don't try to correct for a problem that you don't have. Until you actually run into issues with having an application link against libraries in its explicit `stow` path, don't make it unnecessarily complicated for yourself. – Kusalananda Aug 19 '17 at 07:30
  • Yeah I'm not great at following the "don't fix what ain't broke" principle. – fosslinux Aug 19 '17 at 07:33
  • Hi, I'm the Stow maintainer. This is a good answer, and corresponds to what the Stow manual suggests as linked in the comment above by @ubashu, but I fear that the manual is actually out of date. I suspect that this text was probably written before [`DESTDIR`](https://www.gnu.org/software/automake/manual/html_node/DESTDIR.html) was introduced into automake, and from memory `DESTDIR` is the more correct approach. However it's a long time since I looked into this in detail. I should probably revisit and update the manual. – Adam Spiers Aug 19 '17 at 22:40
  • @AdamSpiers Hi. I have a few questions then: 1. Is Kusalananda correct about the `./configure` prefix argument? 2. Dosen't DESTDIR create a completely new directory tree? So how is Stow supposed to manage it properly if there is not only sub folders of usr, but also var, etc, etcetera? 3. I have been looking at the Linux From Scratch project and successfully built a system. I am now looking at creating another system based on Stow. Do you think Stow is up to this, and what problems could I face? If Stow isn't, do you have an alternative you think would work? Sorry for all the questions! :-) – fosslinux Aug 20 '17 at 21:01
  • I would prefer that these discussions happened on one of the Stow mailing lists, where they belong. But briefly: 1. I wouldn't say @Kusalananda is wrong, but `DESTDIR` is a better option when available. 2. Yes it does, but I don't see a problem. `./configure --prefix=/usr/local && sudo make install DESTDIR=/usr/local/stow/mypackage` then stow into `/usr/local` as normal. 3. [Stow is a symlink farm manager and is missing many features a modern system package manager needs](https://lists.gnu.org/archive/html/info-stow/2016-11/msg00008.html) - but that's OK! Just be aware of its limitations. – Adam Spiers Aug 22 '17 at 15:28
  • 1
    @AdamSpiers I appreciate your input. Thanks! I happen to be the port maintainer for `stow` on OpenBSD, BTW. – Kusalananda Aug 22 '17 at 15:29
  • Cool! Thanks for your maintainership work :) BTW @ubashu if you want a modern package manager, I would recommend taking a look at [GNU Guix](https://en.wikipedia.org/wiki/GNU_Guix), or `rpm` if you need something more proven and less adventurous. – Adam Spiers Aug 22 '17 at 15:30