I'm trying to append data to a Debian package's description during the build process.
The required data is stored in constants declared within debian/rules
file.
I've override dh_gencontrol
and added @printf
calls which formats the data.
The issues I'm encountering are related to whitespace-containing-strings:
printf
splits the given string, matching each word to an %s
instance. I'd like it to use the whole string instead._
and add it to the same line?Relevant sections from debian/rules
:
TEXT_STRING = "string with data"
VERSION_NUM = "v11.4"
...
...
override_dh_gencontrol:
dh_gencontrol
@echo "Adding versions to debian/control file" # This one writes to console
@printf " %-30s %-20s %s\n" "${TEXT_STRING// /_}" "${VERSION_NUM}" "${TEXT_STRING}" >> "$(CURDIR)/debian/my-package/DEBIAN/control"
Expected output:
<Package description generated by dh_gencontrol>
string_with_data v11.4 string with data
Actual output:
v11.4 string
with data
There are 2 main issues here:
Bash substitution (i.e. "${TEXT_STRING// /_}"
) does not work inside the make file.
Solution is to perform string manipulation within a (on-the-fly) shell session, like so:
$(shell echo ${TEXT_STRING} | sed 's/ /_/g')
String with spaces breaks up into list of words. printf
sees them as multiple variables, were each one "consumes" a single %s
This results in printf
adding additional lines until printing all variables.
This is solved by removing the quote marks wrapping the string, turning this "${TEXT_STRING}"
to that ${TEXT_STRING}
.
The final solution would be:
@printf " %-30s %-20s %s\n" $(shell echo ${TEXT_STRING} | sed 's/ /_/g') ${VERSION_NUM} ${TEXT_STRING} >> "$(CURDIR)/debian/my-package/DEBIAN/control"