The difference between .mk file and Makefile

hugtech picture hugtech · Jul 27, 2019 · Viewed 14.9k times · Source

I've just begun to study Porting Android. And I come across a new type of file which is .mk file. It's is an extension of Makefile but I don't know what it is different from a Makefile ? So, can somebody help you clarify them. Thanks very much !

Answer

Renaud Pacalet picture Renaud Pacalet · Jul 27, 2019

A make file can have any name. The -f option of make is used to specify which file to use:

make -f foobar

You can even use -f several times:

make -f foo -f bar

In which case make processes the files in order (or, equivalently, concatenates the files and processes the result).

makefile and Makefile are special names because if make is called without the -f option it automatically searches for them, in this order, and use the first it finds. Note that GNU make also considers GNUmakefile, and prefers it over makefile and Makefile. Other make implementations can have other default names.

The .mk extension is a more or less standard extension for make files that have other names than the defaults. It is a reasonable extension if you want humans to quickly understand what these files are: convert.mk is more informative than foobar. Some editors use this extension to identify the file type and apply syntax coloring. They usually apply the same syntax coloring to makefile and Makefile.