Makefile Other Features - Unix makefile

What is Makefile Other Features?

Recursive Use of Make

Recursive use of make means using make as a command in a makefile. This method is useful when you want divide makefiles for different subsystems that compile a larger system. For instance, suppose you have a subdirectory named `sunder' which has its own makefile, and you would like the containing directory's makefile to run make on the subdirectory. You can do it by writing this –

You can write recursive make commands just by copying this instance, but you require knowing about how they work and why, and about how the sub-make relate to the top-level make.

Communicating Variables to a Sub-Make

Variable values of the top-level make can be passed to the sub-make through the environment by open request. These variables are defined in the sub-make as defaults. You cannot ignore what is particular in the makefile used by the sub-make makefile unless you use the `-e' button.

To pass down, or export a variable, make adds the variable and its value to the environment for management each command. The sub-make, in turn, uses the environment to initialize its table of variable standards.

The special variables SHELL and MAKEFLAGS are always exported (unless you inexpert them). MAKEFILES is export if you set it to anything.
If you want to export particular variables to a sub-make, use the export instruction, as exposed –

If you want to prevent a variable from being exported, use the inexpert directive, as exposed –

The Variable MAKEFILES

If the location variable MAKEFILES is defined, make considers its value as a list of names (separated by white space) of additional makefiles to be read before the others. This works much like the include directive: changed directories are searched for those files.

The main use of MAKEFILES is in communication between recursive invocations of the make.

Including Header file from Different Directories

If you have put the header files in different directories and you are running make in a dissimilar directory, then it is essential to provide the path of header files. This can be done using -I selection in makefile. Assuming that functions’ file is accessible in /home/wisdom jobs /header folder and rest of the files are presented in /home/wisdom jobs /sac/ folder, then the make file would be written as follow.

Appending More Text to Variables

Often it is useful to add more text to the value of a variable before now defined. You do this with a line contain `+=', as exposed:

It takes the value of the variable substance, and adds the text `another’s' to it (preceded by a single space). Thus –

#

Sets substance to `amino halloo factorial’s another’s'.

Using `+=' is similar to:

Continuation Line in Makefile

If you do not like too big lines in your Makefile, then you can break your line using a back-slash "\" as exposed below –

Running Makefile from Command Prompt

If you have ready the Makefile with name "Makefile", then basically write make at command prompt and it will run the Makefile file. But if you have particular any other name to the Makefile, then use the following command –

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Unix makefile Topics