Hello,

I was thinking about this blog post since some time now but I never wrote it because I thought it will be lame. Many of us are using Make but most of us don't know the power for using it everyday for easy tasks... I use Make in nearly all of my projects and it is soo helpful to me.

Now let's Make make things done...!

Sooooo, what is Make?

From the GNU Make website: "GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files. Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program."

As you can read, Make is built for software developers to build binary files from their code and for this Make is very useful especially when having many source files for building the final piece of software...

But!!! Make is soo powerful to just execute very easy but boring tasks with just one command. So let's say you have to execute a few commands every time you want to execute some repeating tasks in your project, just use Make.

Make is based on makefiles so you need to create a file named Makefile in the root of your project. You can have makefiles in subfolders of your project tree but I will not cover this here because this post is about the most simple usage of Make.

A very simple Makefile is shown below. It creates a file when you in your current working directory just run "make" or "make all". When you then run "make clean" the file will be deleted.

Our first Makefile:

all:
	touch file
clean:
	rm -f file

This is easy... or not?

A more useful example:

Let's say, you have three commands you need to execute to make a backup of three hosts you are responsible for. Just create a directory where you want to store you backup Makefile. Just name it what you want. "cd" to that directory and create a Makefile with the content below. When you now run "make" or "make backup" in the new directory three "rsync" commands will be executed... This is nice because you can define very complex tasks and they are documented in the Makefile and not only in the shell history. To be honest this example is really very lame but it shows the power of make for everyday tasks in allday projects.

backup:
	rsync -av host1.example.com:/ /backup/host1/
	rsync -av host2.example.com:/ /backup/host2/
	rsync -av host3.example.com:/ /backup/host2/

At the end...

Make is soo much more powerful but as I said before I will not cover this here. The most well known project which is beeing build using Make is the Linux Kernel but even other very important projects like OpenWrt are beeing built using Make. I mention these two projects because they are really using Make to the edge. Since a very long time most C code based projects on GNU (gcc) based operating systems are using Make for compiling their code to executables or libraries.

I use Make every day because I have repeating tasks consisting of more then one command in all of projects and Make makes it easy for me to handle this. When you have some shell completion and are writing "make " and then hitting the "tab" key in your project root you will also have all "make commands" available you defined in the Makefile.

I am very happy that we can use so many powerful tools for free when using a free and open operating system like GNU/Linux!

I hope this helps you and I wish you a lot of fun when you let Make get your job done... :)

Have fun!