Aerosol Posted December 30, 2014 Report Posted December 30, 2014 I'm not superuser of make, but sometime i use it. My knowledge about the files usually end in the next things: I know that if I'll create Makefile file, write some simple rules which are in general form: target: commandAnd than execute make target, it executes command. Last time ago i started to learn some low-level stuffs as assembly programming, operating system theory and practice (as you can read and understand from previous blog posts about assembly programming). Some days ago i started to read Linux kernel Makefile and here i want to share some make syntax features which i learned from there. So this post is not for people who used make much time and knows much about it.originorigin - is a builtin function which returns information about variable. It's general form is: $(origin var)You can pass any $(variable) to it and it will return info about it. Return value of origin can be:undefined - variable didn't defineddefault - default var, like $(CC) and etc...environemnt - from environmentenvironment override - return environemnt which was overridden with make -efile - from makefilecommand line - from make command line argumentsautomatic - see bellowSo we can use it like this: all: ifeq ("$(origin A)", "command line") ALL = $(A) endif@Usually makefile prints every action after executing it, but sometimes we no need in it. We can use @ prefix for it, for example: [CODE @Echo "Done." line, but just prints Done. filterfilter function removes all space separated words from text, which doesn't match no one template. General view of it: '$(filter template..., text)' For example, we have targets list and we need to check is there build target there or not: targets := all clean findTargets: $(targets) ifeq $($(filter build, $(targets),) Check empty valueWe can check empty value with following: ifeq ($(VAR_CAN_BE_EMPTY)),)Current directoryPreviously when i was need to get current directory path, i used something like this: curr = $(shell pwd)Now i know about builtin variable:$(CURDIR)Errors, Warning and InfoThere are 3 builtin functions for printing errors, warning and info: ifeq $($(USE_VAR1),) $(USER_VAR1 must be not empty)ifeq $($(USE_VAR2), 1) $(USE_VAR2 1)ifneq $($(USE_VAR3),) $(info $(USE_VAR1) is not empty)VPATHVPATH variable defines list of directories where template rules will search dependencies: VPATH = src%.o: %.c gcc -c $< Automatic variablesThere are some special macros:$| - Names of all the order-only prerequisites, with spaces between them$@ - Filename of the target of the rule$? - Names of all the prerequisites that are newer than the target$< - Name of the first prerequisiteSource Quote