This actually came up as part of an answer to a more specific question (how to get the evaluated PS1 output to a variable) and I thought the process deserved its own question and answer, one more generalised to the process of modifying bash source code.
Here are the steps to add an internal command evalps1, which is meant to give you the same output as your primary prompt string. It's based on the version 4.2 code base.
Step 1.
First, change support/mkversion.sh so that you won't confuse it with a "real" bash, and so that the FSF can deny all knowledge for warranty purposes :-) Simply change one line (I added the -pax bit):
echo "#define DISTVERSION \"${float_dist}-pax\""
That script is the one which creates version.h and affects all the various ways of getting version information from bash: --version, the $BASH_VERSION variable and so forth.
Step 2:
Change builtins/Makefile.in to add a new source file to the mix. This entails a number of steps.
(a) Add $(srcdir)/evalps1.def to the end of DEFSRC. This def file contains information about the internal command as well as the implementation code.
(b) Add evalps1.o to the end of OFILES. This simply causes your code to be linked in with bash.
(c) Add the required dependencies:
evalps1.o: evalps1.def $(topdir)/bashtypes.h $(topdir)/config.h \
$(topdir)/bashintl.h $(topdir)/shell.h common.h
Step 3:
Add the builtins/evalps1.def file itself, this is the code that gets executed when you run the