pull out duplicate Makefile rules to Makefile.common

This patch does two things:

* creates file Makefile.common and makes all Makefiles include it
* puts repeated rules into Makefile.common and removes them from other Makefiles.

Perl scripts to do that are included, so that work may be repeated on other branches.

I developed it in order to be able to easily add other rules and have them apply to all files in all directories.