Most often the companies are acting precisely as the law is intended to work, and criticism is based on a misunderstanding of what is turnover and what is profit, and how taxes should be calculated. Very commonly the complaint is that Nike (for instance) pays no corporate income tax to a country even though it sells a lot of goods there. This is a misunderstanding: the vehicle for collecting sales-based taxes is VAT, not corporate income tax. Corporate income tax is paid where the company operates.
A major thing people don't seem to understand is that within EU, it is perfectly OK for a company operating in one EU country to sell goods and services to another country. Free movement of goods and capital.
The very foundation of EU which infuriates people.
In my view, the real problem when you do not respect the spirit of the law is that you do not respect the people themselves, even if you're not doing anything illegal. And I fear that some of those people, when they learn of another case like this one in 6 months, one year or two years, could consider using violence. In the past, several terrorist groups had targeted economic or corporate symbols (the Baader group for example), so we shouldn't forget histoire. These affairs will feed those enclined to follow that path again, but against what are now documented possibilities. That is why the states across the world need to act: it is not only about getting countries' money back, it is also to avoid future violence.
A taxation race to the bottom is not what the fundamental principles of the EU are about. At best they are an unwanted side-effect.
For example, I am customer of a German branch of a French bank. The company is based in Paris and all contracts clearly state that. The actual service is provided from a German office building. That's where almost all employees responsible for the German customers are located and where you sent letters to. That company pays "income" tax according to German rules to the German government for all services provided from that building even though it's based in France. (Surely they do some tax avoidance as well but this doesn't change the point.) Thanks to the EU freedoms they could just open up an office in Germany, employ people there, and provide services.
I am also a customer at a Dutch bank based in Amsterdam and that's where the service is provided from. They don't have a presence in Germany and don't pay German taxes. Thanks to the EU freedoms they can provide services to me across the border.
(For the record: Apple does have legal entities in Germany. For every transaction they just happen to use the most tax-efficient entity of theirs without much consideration of the real-life transaction.)
As I said, the very point of EU (free movement of goods and capital) is that it is perfectly OK to have just a mailbox presence (e.g. to handle warranty claims and such, a service which is sold to the actual operating company in another EU country) and have the actual operation done somewhere else.
I take benefit of this all the time; for instance, I buy things from amazon.de which has much lower prices than domestic companies. They just pay VAT, based on sales, to my country, on my country's tax rate, but they don't operate here.
And yes, Amazon operates in Germany. They have engineering offices, customer service, and warehouses all located in Germany. Every company from Luxembourg should be able to. But taxing income derived from that is still possible under EU rules (and actually done).
Of course in recent years the EU got cold feet on the whole "four freedoms". Services never really happened. Capital is a joke - France and Germany ban foreign investments all the time and Greece had capital controls within recent memory. It's only migration the EU is really, really keen on, probably because that's the one that suits their political objectives the best.