No matter whether you're dealing with new or old construction, walls are almost never straight or square enough to install woodwork without at least a little trimming. On a floating shelf installation, usually only one scribe line is needed which can be easily made with a compass. Occasionally, the job is to install a shelf into a corner or alcove so the shelf will abut walls on 2 or 3 sides. In that case it is impossible to hold the shelf up to the wall to draw a scribe line.
An accurate template can be made using 2"-3" rips of thin plywood and a hot glue gun. The template then can be removed and laid on top of the shelf to trim to size. This technique is common practice for stone countertop fabricators, though it works very well for anything where a good fit is desired.
You’ll want to order your shelf such a size that you’ll cut about 1/16” to 1/4” from the edges to be trimmed. Trimming much more than 3/16" from the back edge can affect the fit of the bracket. Up to about 1” can be cut from the ends of the shelves without causing too much trouble other than getting a clean crosscut.