HOME

PDF (letter size)

GNU make cheat sheet

Nasser M. Abbasi

January 28, 2024   Compiled on January 28, 2024 at 9:23pm

Contents

1 recusive make
2 using common.mk in recusive make
3 How to build a file in the current directory without traversing the whole tree?
4 Using -,+,@ before SHELL commands
5 How to find number of column and rows on Linux terminal?
6 Links

1 recusive make

Assume this tree structure

 A---+--B 
     | 
     +--C

Recusrive make can be used to build everything in the tree. The directory $HOME contains this common.mk file

all:: 
        @for d in $(DIRS); \ 
        do                 \ 
              $(MAKE) --directory=$$d;   \ 
        done

Each of the subdirectories will contain a Makefile that includes the common.mk. Then running the command make -I$HOME from A gives

>make 
make[1]: Entering directory `/tmp/B' 
make[1]: Leaving directory `/tmp/B' 
make[1]: Entering directory `/tmp/C' 
make[1]: Leaving directory `/tmp/C'

2 using common.mk in recusive make

Following from the above, each Makefile in subfolders will start by defining its own specific variables, and then it will include a common.mk which resides in common location such as $HOME.

Each makefile will include this file. An example of a Makefile in the A directory shown above is

DIRS:= B C 
include common.mk 
all:: 

Each sub directory will include similar makefile which starts by listing the directories below it, then including common.mk

The actions actually performed by makefile will be done at the bottom most directories first, followed by the higher level up. This means the tree is first traveresed to the bottom, then when the bottom is reached, on going back up, each makefile will execute any other action in its all such as compiling files and other such tasks. So, this is like a stack. The last directory visited on the way down, is the first directory that will be updated in the build process, and the top directory, will be the last directory that is updated.

3 How to build a file in the current directory without traversing the whole tree?

Suppose I have index.tex that I want to build it to index.htm to try something but it is allready update to date. But if I do make clean it will now clean everything down the whole tree, which is not what I want.

I can touch index.tex then do make. But I can also use -B option and give it the target to build, like this

make -I$HOME -B index.htm

4 Using -,+,@ before SHELL commands

from http://pic.dhe.ibm.com/infocenter/aix/v6r1/ it says

@         Causes the command not to be echoed before it is executed. 
-         Causes any nonzero exit status of the command line to be ignored. 
+         Causes a command line to be executed, even though the options -n, -q, or -t are specified. 

5 How to find number of column and rows on Linux terminal?

echo -e "lines\ncols"tput -S| ref: this also stty size

Tools for terminal are here

Has make build-in symbols http://www.chemie.fu-berlin.de/chemnet/use/info/make/make_15.html