15

Is it possible to make rpmbuild to preserve symlinks on packaging?

The current behavior is to create copies of files, which I would like to avoid.

CivFan
  • 13,560
  • 9
  • 41
  • 58
SyBer
  • 5,407
  • 13
  • 55
  • 64

4 Answers4

20

Sure it supports symlinks. But you actually have to package symlink and not copy the contents to the buildroot. Example spec packaging a symlink to /bin directory called /newbin

Name:           test
Version:        1.0
Release:        1%{?dist}
Summary:        nothing
License:        GPLv2
Source0:        nothing

%description 

%install
rm -rf %{buildroot}
mkdir %{buildroot}
ln -sf /bin %{buildroot}/newbin

%files
/newbin

You'll also need nothing file in your SOURCES directory to succesfully build rpm out of this. Tested with rpm 4.9.1.2

Stan
  • 2,487
  • 18
  • 27
  • I would make one change to what Stan said above, since the -f is in the create link, the remove shouldn't be needed. – Jane Jul 25 '14 at 22:15
  • @Jane - I disagree. It's usually a good idea to clean out the buildroot to remove cruft at the beginning of `%install`. For instance, let's say that a previous version of the package installed a second file, "`%{buildroot}/newlib`", but the current version does not install that file. The current version of the package won't be aware of that file and thus it won't be removed from the buildroot (following your suggestion). In general, the current rpmbuild instance isn't aware of any old cruft that may be in the build root. Better just to nuke the whole buildroot before the install step. – jayhendren Jul 28 '14 at 20:14
  • It's not a good idea to create symlinks in your buildroot for 2 reasons: 1) You shouldn't point to anything outside your buildroot. 2) if you do link to something within your buildroot (e.g. let's say you created a %{buildroot}/bin and linked to that, then copying the file in the files section will copy the link that points to your buildroot, not the actual /bin directory. The best way is to use a %ghost file and create the symlinks in a %post section (see my post below). – Alther Sep 03 '21 at 16:47
4

I know this Q is old, but here's how I do it.

In the %install section, simply touch the file that will be the symlink.

touch %{buildroot}[path to your file]

In the %files section, you specify it as a %ghost file:

%ghost [path to symlink file]

By doing this, it'll be listed as part of the package's files and will also be automatically removed when the package is uninstalled.

Finally, create the symlink in the %post section:

ln -sf [file to link to] [symlink]
Alther
  • 451
  • 4
  • 6
0

If the symbolic link is relative it will get installed as you expect.

Use the -r, --relative option to ln.

Vance Shipley
  • 737
  • 4
  • 17
-1

I don't think so. I've used the post-install script set up symlinks in my packages.

pwan
  • 2,894
  • 2
  • 24
  • 38