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 every day 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 subdirectories 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
Isn't it easy?
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 your "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 everyday 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 being 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 than one command in all of my 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 make your jobs done... :)