The first type of rifling was done with a rod dragging a sharp "scrape" cutter through the barrel, with a spiral guide to turn it. The first pass removed some metal, then the cutter was turned to the next cutting point (groove), some metal removed, and so on, until a light cut had been made in each groove. The cutter was then shimmed to increase the depth of the cut and the process repeated. This was continued until the grooves were at the right depth.
Later, around WWII, the button rifling method was developed. This involved a very hard die, or "button" with the rifling on it in reverse. This was forced through the drilled barrel by hydraulic pressure, and cut all the grooves at the same time. Sometimes, different buttons were used in increasing sizes, sometimes, one button did it all, partially dependent on barrel hardness.
Hammer rifling is put in by using a long or even full length mandrel with the rifling in reverse. This is inserted in the barrel and the barrel put through a machine that hammers the outside of the barrel to force the inside around the mandrel. This process leaves a spiral pattern on the outside of the barrel; some makers leave this on as a novelty, while others turn the barrel down to remove it.
HTH
Jim