The problem is, profits are the end result of a lot of complex corporate operations across many countries. Who's to say which bit of which revenue was used to pay for which costs, while other bits are pure profit?
There is another corporate tax that is entirely linked to the market they're selling to, though: VAT. The problem is: it's only over revenue made from selling to consumers, not to other businesses, and it's always completely offloaded to those consumers, and therefore not really a corporate tax but a consumption tax.
So how about treating profits that way? In every market, you count the revenue made from selling in that market, and subtract the costs made by buying, hiring, etc in that market. The difference is the profit you made in that market, and you've got to pay your corporate tax over that amount to the tax authority in that market.
That way you can't book your profits in a country where you didn't make any revenue. And if somehow you do make your revenue in a country where you didn't make incur costs, you pay tax over the entire amount. If you don't make revenue, then tough. You could have made some tax-free revenue there.
I'm no international tax lawyer, though, so there are probably problems with this idea. I like the principle, though: they've got to pay back to the market they're profiting from, and not to a completely unrelated country that offers them tax breaks for coming there.