The difference between .mk file and Makefile
Asked Answered
O

1

43

I came across an unfamiliar type of file which is an .mk file. It appears to be an extension of Makefile but I don't know whether it is actually different from a Makefile. Can somebody help clarify the difference?

Obese answered 27/7, 2019 at 3:20 Comment(0)
S
70

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.

Speight answered 27/7, 2019 at 5:49 Comment(1)
Another common convention is to have a top-level Makefile which contains some logic to decide whether then to include one or more of windows.mk, linux.mk, or mac.mk (for example).Overzealous

© 2022 - 2024 — McMap. All rights reserved.