Score:1

Can a .deb package include sources that are to be compiled by dpkg?

us flag

I have a pkg with some c++ code. Currently I'm compiling some of the c++ code as binary, some as library, and I can ship and deploy it on other platforms.

However, I also have a driver there, which I can't cross compile due to its dependency on the kernel, which makes it so that every kernel might need a different binary.

So, what I want to have is a .deb where I will store the binary under /usr/bin (done), the library under /usr/lib (also done) and the driver source code under /opt/driver (I guess... Is this a legit place for that?)

Packing this is the easy part, since all I need to do is put it in my workspace, and call dpkg-deb. What I'm not sure about are two things

  1. Is it legit to pack source code in a .deb? (In python terminology - is .deb a bdist(binary distribution) or also can be an sdist (source distribution))
  2. If it is legit, how can I invoke the make commands? Can dpkg / apt do that for me? Or do I need to run dpkg -i pkg and then run make? [looking at postinst but I'm not sure if this is the right way to go]

I'm open to any kind of build system if it can solve this though I'm currently using cmake and would much prefer sticking to it


My POC:

tree bla_x86_64
bla_x86_64
├── DEBIAN
│   ├── control
│   └── postinst
├── opt
│   └── bla.cpp
└── usr
    ├── bin
    │   └── bla.bin
    └── lib
        └── bla.lib
cat bla_x86_64/DEBIAN/postinst 
#!/bin/sh

set -e

echo hello world!
echo compiling $(ls /opt/bla.cpp)
echo cleanup
rm -rvf /opt/bla.cpp
$ dpkg-deb --build --root-owner-group bla_x86_64/
dpkg-deb: building package 'bla' in 'bla_x86_64.deb'.
$ sudo dpkg -i bla_x86_64.deb 
(Reading database ... 407519 files and directories currently installed.)
Preparing to unpack bla_x86_64.deb ...
Unpacking bla (4.0) over (3.0) ...
Setting up bla (4.0) ...
hello world!
compiling /opt/bla.cpp
cleanup
removed '/opt/bla.cpp'
ru flag
`dpkg` doesn't control anything. If you are using DKMS properly you don't *need* a `make` command anywhere in the Debian file. DKMS will automatically compile things where it has to - you shouldn't need to have any special `make` commands anywhere.
CIsForCookies avatar
us flag
@ThomasWard I will need `dkms` command however, won't I? So, I'm still wondering if this is lefit, and if so, is there anyone who already done so (I used `make` in my question instead of `dkms` in order to simplify, but I guess it just complicated things...)
Score:2
cn flag

Technically there is no such thing as "legitimate" or "illegitimate" content of a .deb file. You may pack anything you want in it.

A good place where to put your source code on the target system would be under /usr/share/${packagename}.

To have dpkg or apt invoke your make commands, just place them in your package's postinst script. Make sure that you declare as dependencies all the programs needed for the build process, such as cmake, g++ and binutils, as well as the kernel headers, otherwise installation will fail on systems that happen to have no compiler installed. Also make sure you do proper error handling in your postinst script to avoid rendering the target system non-operational by installing a bad kernel module as a result of a failed compilation.

Note that this solves only half of your problem. In addition to compiling your driver for the kernel in use when your package is installed, you also need to make sure it is recompiled for the new kernel after each kernel update. The solution for this is DKMS, short for Dynamic Kernel Module Support. So you'll want to look into supporting DKMS in your .deb package, too.

CIsForCookies avatar
us flag
Do you happen to know of pkgs that are doing such a thing? (ie calling make / dkms from postinst). I'm trying to find guys who did this before me and learn from them
Tilman avatar
cn flag
Not offhand. If I wanted to find one I'd probably looking at Linux packages from hardware manufacturers who maintain out-of-tree drivers. Graphics adapters come to mind.
CIsForCookies avatar
us flag
found it. Nvidia does interact with dkms in their postinst script
CIsForCookies avatar
us flag
Do you know if such a `.deb` (i.e. only sources) should have a special `arch`? It should be arch-independent, but I'm not sure if this is possible
Tilman avatar
cn flag
You can set `Architecture` to `all` to indicate an architecture independent package. A different approach, if your package really contains _only_ sources, would be to actually make it a source package.
CIsForCookies avatar
us flag
I'm not sure. The sources in the package should be compiled into a driver. I read about source packages in https://wiki.debian.org/Packaging/SourcePackage, but I think since [quote] "Sources are normally **not** installed", a binary package is best - it will contain the sources + the make command in `postinst` and installing the package will `make` the sources. What do you think?
Tilman avatar
cn flag
If you consider making it a source package you should read up on the deb package build system. That will also clarify the meaning of the sentence you quote. Otherwise stick with `Architecture: all`.
CIsForCookies avatar
us flag
Can you share a link? I found a lot of data, but none seems what I was looking for
Tilman avatar
cn flag
I suggest you start at https://wiki.debian.org/Packaging/Intro and work your way up from there.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.