Wednesday, October 27, 2021

[SOLVED] Make: Extracting a number from working directory name (Debian packaging rules)

Issue

I'd like some help with the following problem:

I have a debian package built daily with Launchpad's Recipes feature. The version name (and the name of the source directory) is automatically generated and includes current revision number. I want to modify the debian/rules file to extract the revision number and pass it to CMake.

So far it doesn't work - it seems that an empty string is passed to CMake. I don't know if the problem is in my make code or in something else.

The rules file:

#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

%:
    dh $@ --parallel --list-missing

# Try to detect the Bazaar revision number from the directory name
ifneq ($(findstring bzr,$(PWD)),)
COMPONENTS := $(PWD)
COMPONENTSL := $(subst -,' ',COMPONENTS)
COMPONENTSLL := $(subst ~,' ',COMPONENTSL)
BZRVER := $(filter bzr%,COMPONENTSLL)
BZRVERN := $(subst bzr,,$(BZRVER))
override_dh_auto_configure:
    dh_auto_configure -- -DRELEASE_BUILD=0 -DBZR_REVISION=$(BZRVERN)
endif

Relevant section of the build log:

make[1]: Entering directory `/build/buildd/stellarium-0.11.2~bzr5066'
dh_auto_configure -- -DRELEASE_BUILD=0 -DBZR_REVISION=
    mkdir -p obj-i686-linux-gnu
    cd obj-i686-linux-gnu
    cmake .. -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_VERBOSE_MAKEFILE=ON -DRELEASE_BUILD=0 -DBZR_REVISION=

The full log is here: https://launchpadlibrarian.net/86783083/buildlog_ubuntu-natty-i386.stellarium_0.11.2~bzr5066-0ubuntu0~natty1_BUILDING.txt.gz

Any ideas?


Solution

You've made a mistake at least in these lines:

COMPONENTSL := $(subst -,' ',COMPONENTS)
COMPONENTSLL := $(subst ~,' ',COMPONENTSL)
BZRVER := $(filter bzr%,COMPONENTSLL)

You have to perform changes on the actual values of COMPONENTSXX variables, thus their names should be enclosed into $(...).

If the only thing you need is the revision number (5066 in your example), it could be extracted as follows:

BZR_REVISION := $(lastword $(subst ~bzr, ,$(PWD)))


Answered By - Eldar Abusalimov