6

I would like to rebuild/recompile all Debian packages of a machine with specific flags.

How can I do that with less command as possible?

I have found that https://debian-administration.org/article/20/Rebuilding_Debian_packages but it does not explain how to do that for all the packages installed on a system.

aurelien
  • 404
  • 4
  • 22
  • Similar question: https://unix.stackexchange.com/questions/184812/how-to-update-all-debian-packages-from-source-code – kjyv May 25 '18 at 00:09
  • @kjyv that is not the same question the other one want to update all from source ... I wish to rebuild all from source + specific flag ... the idea is not to have only something up to date but build as I wish. The evidence is also that the response is different. – aurelien May 25 '18 at 07:31
  • Not saying your question is a duplicate, just that there might be relevant answers in that question (hence "similar"). Also for others (like me) searching for this. The other question is not about updating either btw., that's not how apt building from source works. – kjyv May 27 '18 at 18:49
  • The answer you accepted only reinstalls binary packages. It seem likely that with debian there is no easy built in way to recompile all packages (with or without flags). What you want to do can be done per package like this: https://stackoverflow.com/questions/11072724/how-to-override-dpkg-buildflags-cflags – kjyv May 27 '18 at 18:50
  • That sounds to be a good idea that you adapt the response of that link to that question ... so I would vote for your answered :-) – aurelien May 28 '18 at 06:58

2 Answers2

1

You can write a script that does something like this:

for each $pkg in dpkg-query -W -f '${status} ${package}\n' | sed -n 's/^install ok installed //p':

  • run apt-get source $pkg
  • run apt-get build-dep $pkg
  • cd $pkg-version/
  • run DEB_CPPFLAGS_SET="-I/foo/bar/baz" DEB_CFLAGS_SET="-g -O3" DEB_LDFLAGS_SET="-L/fruzzel/frazzel/" dpkg-buildpackage
  • install package with dpkg -i deb-file
  • cd ..

This will go through all of your installed packages and generate .deb files for each of them. Probably there are some edge cases etc. that will have to be handled. You could also leave out packages that are not built from C code etc.

Info taken from these questions:

https://unix.stackexchange.com/questions/184812/how-to-update-all-debian-packages-from-source-code

How to override dpkg-buildflags CFLAGS?

kjyv
  • 586
  • 4
  • 15
-1

Try this approach:

dpkg --get-selections > selections
sudo dpkg --clear-selections
sudo dpkg --set-selections < selections
sudo apt-get --reinstall dselect-upgrade

Source: https://www.linuxquestions.org/questions/linux-software-2/force-apt-get-to-redownload-and-reinstall-dependencies-as-well-873038/

VTodorov
  • 953
  • 1
  • 8
  • 25