Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rebuild all Debian packages of a system with specific flag?

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.

like image 312
aurelien Avatar asked Sep 29 '17 02:09

aurelien


People also ask

How does dpkg Buildpackage work?

dpkg-buildpackage is a program that automates the process of building a Debian package. It consists of the following steps: 1. It prepares the build environment by setting various environment variables (see ENVIRONMENT), runs the init hook, and calls dpkg-source --before-build (unless -T or --target has been used).

Where are packages stored Debian?

Debian already comes with pre-approved sources to get packages from and this is how it installs all the base packages you see on your system (if a user did a net-install). On a Debian system, this sources file is the "/etc/apt/sources.

What is Debhelper in Linux?

Debhelper is used to help you build a Debian package. The philosophy behind debhelper is to provide a collection of small, simple, and easily understood tools that are used in debian/rules to automate various common aspects of building a package. This means less work for you, the packager.

What is Dh_make?

dh_make is a tool to convert a regular source code package into one formatted according to the requirements of the Debian Policy. dh_make must be invoked within a directory containing the source code, which must be named <packagename>-<version>. The <packagename> must be all lowercase, digits and dashes.


1 Answers

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?

like image 113
kjyv Avatar answered Oct 02 '22 00:10

kjyv