I've just completed a simple source code modification & rebuild on a Raspberry Pi OS - bullseye machine. Because this is new to me, I'll list the steps I followed in an effort to avoid ambiguity:
$ dhcpcd --version
dhcpcd 8.1.2 # "before" version
$ sudo apt install devscripts # build tools for using `debuild`
$ apt-get source dhcpcd5 # creates source tree ~/dhcpcd5-8.1.2; Debian git repo is far off!
$ cd dhcpcd5-8.1.2 # cd to source dir
$ nano src/dhcp.c # make required changes to the source (one line)
~/dhcpcd5-8.1.2 $ debuild -b -uc -us # successful build
$ cd ..
$ sudo dpkg -i dhcpcd5_8.1.2-1+rpt5_armhf.deb # install .deb file created by debuild
$ dhcpcd --version
dhcpcd 8.1.2 # "after" version
$
All well & good, but the "before" & "after" version numbers are exactly the same, which leaves me without a simple way to know whether I have my corrected code running, or the un-corrected code. I'll install the corrected .deb file to several hosts, I may get requests from others, etc, so I'd like some way to easily distinguish corrected from un-corrected code.
Using dhcpcd --version seems an easy way to do this. I've read that Debian has rules re version numbers, but as I'm not releasing this to "the world" I see no need for formality. Also - I've submitted a pull request/merge request to the Debian repo, and I've advised the RPi organization on the issue. I've gotten no feedback from either party, but this bug is a huge annoyance for me. I don't wish to wait for a new release of dhcpcd with a "proper" version number.
What must I do to cause the corrected version of dhcpcd to report dhcpcd 8.1.2.1 - or something similar?
EDIT for Clarification:
Based on this answer, I edited dhcpcd5-8.1.2/debian/changelog. Following this change, the apt utilities consistently report the version of dhcpcd as 8.1.3:
$ apt-cache policy dhcpcd5
dhcpcd5:
Installed: 1:8.1.3-1+rpt1
Candidate: 1:8.1.3-1+rpt1
Version table:
*** 1:8.1.3-1+rpt1 100
100 /var/lib/dpkg/status
1:8.1.2-1+rpt1 500
500 http://archive.raspberrypi.org/debian buster/main armhf Packages
7.1.0-2 500
500 http://raspbian.raspberrypi.org/raspbian buster/main armhf Packages
$ #
$ dpkg -s dhcpcd5 | grep Version
Version: 1:8.1.3-1+rpt1
$
However: dhcpcd --version still reports 8.1.2. dhcpcd is aliased to dhcpcd5 in /etc/alternatives. Consequently, dhcpcd --version is actually dhcpcd5 --version. It appears that the executable dhcpcd5 is getting its --version from a different source than than apt utilities.?
EDIT 2:
Turns out the version # that gets reported by dhcpcd --version is defined in defs.h as follows:
#define PACKAGE "dhcpcd"
#define VERSION "8.1.2"
I think dhcpcd is a bit of an outlier. The RPi team apparently decided to forego the upstream version 9 when released (years ago), and have stuck to version 8.1.2 even though there were several upstream releases following ver 8.1.2. Still more confusing is the fact that the .dsc file lists Vcs-Browser: https://salsa.debian.org/smlx-guest/dhcpcd5 as the Git repo - but it's actually stuck at version 7. This doesn't make much sense to me - I guess that's one reason I'm not a package maintainer. :)