debiandpkgdpkg-buildpackage

debuild - Is it possible to build several debian packages by debuild that compile one Makefile


I create debian packages using debuild.

In file "debian/control" is described two packages:
Package: app1
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Tool1.

Package: app2
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Tool2.

Both of them should contain the same binaries compiled by one makefile but with different environment variable.

My rules file calls two compilation:

%:
    TARGET=S_SS dh $@ -papp1
    TARGET=S_TT dh $@ -papp2

A result flow of debuild stages is next:

dh clean -papp1
dh clean -papp2
dh build -papp1
dh build -papp2
dh binary -papp1
dh binary -papp2

It looks like packets are created parallel. Finally binary is overrided by second build.

Is it possible to create rules file in such way that firstly is created app1 and than app2:

dh clean -papp1
dh build -papp1
dh binary -papp1
dh clean -papp2
dh build -papp2
dh binary -papp2

Solution

  • To answer your question: no, it's not possible to change the basic sequence of how packages are build.

    The dh-sequencer will run the build-process in stages, such as (very much simplified)

    In your current setup, the "build" stage will run two builds (for your two flavours), and once both builds are completed, it will advance to the next stage where it packages all the artifacts into debs.

    Now, unfortunately, your 2nd build will just overwrite your 1st build (alternatively it will detect that it already has the binaries in place (not taking the changed envvars into account) and not re-build at all). this is mainly a problem with the build system of the upstream sources (that is: your build system), rather than with the Debian package toolset.

    In order to properly build multiple flavours of your package, your build-system should (really) support out-of-tree builds, where you can build all the binaries for one flavour in subdir1/ and all the binaries for another flavour in subdir2/, so the two builds do not interfere.

    Then you need to (manually!) instruct dh to invoke your buildsystem with the proper flags to use those subdirectories (and a different configuration, obviously).

    A real-world example of a Debian package (disclaimer: maintained by myself) that builds multiple flavours from the same sources using dh can be found here.

    The upstream build system uses autotools (which natively supports out-of-tree builds), and the flavours are distinguished by different configure-flags.

    The gist is something like this:

    #!/usr/bin/make -f
    builddir=debian/build/flavor-
    FLAVOURS = foo bar
    CONFIG_foo = --some-flag
    CONFIG_bar = --some-other-flag
    
    %:
            dh $@
    
    # this target depends on 'configure_foo' and 'configure_bar'
    override_dh_auto_configure: $(patsubst %,configure_%,$(FLAVORS))
    # 'configure_%' is expanded to 'configure_foo' and 'configure_bar'
    # the '$*' is replaced with the '%' component of the target ('foo', 'bar')
    # so there are different builddirs ('debian/build/flavor-foo', 'debian/build/flavor-bar')
    # and we call `configure`-script (relative to the builddir) with the appropriate flag
    configure_%:
            mkdir -p $(builddir)$*
            cd $(builddir)$* && ../../../configure $(CONFIG_$*)
    
    # same for the build-stage; this is simpler as we only need to run 'make' in the
    # various builddirs
    override_dh_auto_build: $(patsubst %,build_%,$(FLAVORS))
    build_%:
        dh_auto_build --sourcedirectory=$(builddir)$*