Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating symlinks when packaging a Library (Debian)?

I'm trying for the first time to package for Debian a small library. For this, I'm using the official Debian Policy manual but since two days I encounter an issue than I cannot fix.

This is the way I'm packaging :

  • Creating the tarball (here libvl_1.0.orig.tar.gz)
  • Using dh_make to generate the debian conf file in the debian directory
  • Modifying the control file, changelog and copyright properly.
  • Building the package using the dpkg-buildpackage command.

Up to here, there is no problem. But as it is a library, I need to create some symlinks while installing it, this related to the SONAME of the library. Here my library is called libvl. So for example, I'm building a file named libvl.so.1.0 as it is the first version. In order to do it right, I guess I should create symlinks like this :

libvl.so -> libvl.so.1 -> libvl.so.1.0

To do this, I'm trying to create those links while running the install process with make. This is working if you launch the 'make install' command. But when installing with dpkg, none if the links are created and I cannot get why. I tried also to use a postinst script but without any results. Here is below my makefile :

DESTDIR =
LIBDIR = usr/lib

LIB = libvl.so
MAJOR = 1
MINOR = 0

CC = gcc
CC_FLAGS = -Wall -ansi -Isrc/
LD_FLAGS =
LN = ln -s

SRC = very_long.c

OBJ = $(SRC:.c=.o)

all: libvl

libvl: $(OBJ)
    $(CC) -fPIC -c $(SRC)
    $(CC) -shared -a -o $(LIBDIR)/$(LIB).$(MAJOR).$(MINOR) $(OBJ)

install:
    install -d -m 0755 -o root -g root $(DESTDIR)/$(LIBDIR)
    install -m 0755 -o root -g root $(LIBDIR)/$(LIB).$(MAJOR).$(MINOR) $(DESTDIR)/$(LIBDIR)

    $(LN) /usr/lib/$(LIB).$(MAJOR).$(MINOR) /usr/lib/$(LIB).1
    $(LN) /usr/lib/$(LIB).$(MAJOR) /usr/lib/$(LIB)

clean:
    rm $(OBJ) $(LIBDIR)/$(LIB).1.0

I guess the problem is there. I will appreciate any answer or comment on this :-)

like image 462
Charly Avatar asked May 10 '12 12:05

Charly


2 Answers

See man dh_link

I have an example gist on github that creates /bin/hello and a symbolic link to it at /bin/helloworld

You can demo it on your system like so:

# Create the deb package
curl -O https://gist.github.com/RichardBronosky/5358867/raw/deb-packaging-example.sh
bash deb-packaging-example.sh

# Install the deb package
dpkg --install hello-world*.deb

# Check the scripts
ls -la /bin/hello*
/bin/hello
/bin/helloworld

The secret is the hello-world-0.1/debian/hello-world.links file that is created by line 18 (at the time of this writing) of the script. Check it out...

https://gist.github.com/RichardBronosky/5358867

like image 180
Bruno Bronosky Avatar answered Sep 30 '22 13:09

Bruno Bronosky


$(LN) /usr/lib/$(LIB).$(MAJOR).$(MINOR) /usr/lib/$(LIB).1
$(LN) /usr/lib/$(LIB).$(MAJOR) /usr/lib/$(LIB)

In the code above, you are directly linking to a target into /usr/lib (ie. on the build machine), but this way it will not be part of the package. Instead, you should be linking in a subdir of DESTDIR, so that the symlink is eventually put in the packaged subtree.

like image 41
kaeso Avatar answered Sep 30 '22 13:09

kaeso