I don't know how a Foreign Co. like Glock does it, but an American Co. like S&W can and does write these freebies off on their taxes.
Anytime they donate to a non-profit or a Government Agency they can write off the cost as a Tax deduction. My guess the write off would be Full Retail and then some, making their donations "profitable".
Give a man a fish and he eats for a day. Give a man a welfare check, a forty ounce malt liquor, a crack pipe and some Air Jordan's and he votes Democrat for a lifetime.