Two-sentence definition: Make is a program that helps manage compilation of multi-file software projects. Make files are files you create that tell make just how to do that.

Why learn about this? What is it good for?

If you use a software-project-management program like Project Builder or Borland or something, this is probably handled for you. But if you, like me, generally use a simple command-line compiler, you will have to manage your own compilation projects.

If you break a program down into several files, then the compiler has to be told that they are all related. With g++, this is done like so:

But when you do this, g++ compiles each file, even if they have already been compiled and nothing has been changed in one or more of the files. This can be quite time-consuming as a project grows.

Make uses a make file that you create to tell what files belong in the project and how they have to be compiled and linked. It keeps track of when a file was last compiled and figures out whether the file has changed since that time, i.e., whether it needs to be recompiled. This can save quite a bit of compile time (of course, if you use that time to get coffee, read the paper, watch anime, etc., this may not be what you want).

Practical Application

The steps for using make are as follows:

  1. If necessary, obtain and install the program.
  2. Identify a software project you would like to use it for.
  3. Create a make file.
  4. Type in make makefile at the command line, where makefile the name of the configuration file you’ve created.
  5. Lean back and enjoy a tall glass of lemonade—or rather, don’t, because you won’t have time to anymore, since your compilations will take practically no time at all[1].

If necessary, obtain and install the program:

*nix (i.e., Unix, Linux, or Mac OS X): It is probably already installed. If not, obtain it from http://ftp.gnu.org/pub/gnu/make/

Windows: Step 1: Download Gentoo. Begin the installation process. Step 2: When it asks if you would like to delete all partitions, choose “Yes, and how!" JUST KIDDING. DO NOT DO THIS. DO NOT PERFORM THE PRECEDING FACETIOUS STEPS. Real step 1: Go here http://www.steve.org.uk/Software/make/ and follow instructions. I have not tried it, since I do not have a windows system, so hopefully it works. Good luck.

OS/2: Lol, you are awesome! But I have no idea where you should obtain make or what to do with it once you’ve obtained it.

DOS: Stick with BASIC, man, which I’m pretty sure doesn’t require make. Haha. Man, you guys are nuts. (Hey, do you have Pengo? Can I come over and play it? I love that game so much. Also, if you’re lucky, and you have a BASIC environment installed, perhaps I’ll wow you with my awesome powers of turning the screen different colors while playing music. Do you also have a dial-up modem? Because that would be awesome. I could totally get into experiencing some nostalgic extremely-slow net surfing time. But most of the sites I used back then are gone now, so I might cry. Well, let me know kk thnx bye.)

Identify a software project you would like to use it for:

Make a list of all the files that need to be compiled and linked.

Create a make file:

Type make -f makefile at the command line, where makefile the name of the configuration file you’ve created.

Note: If you use the name makefile, Makefile or GNUmakefile, you can just type make and it will use that file by default. This is the best way to use makefiles since you are only supposed to have one per project anyway. And you're not supposed to keep more than one project in a directory. Right?

Lean back and enjoy a tall glass of lemonade—or rather, don’t, because you won’t have time to anymore, since your compilations will take practically no time at all.

And there you have it, my friend. Questions? Put them in this file labeled something like “Open questions”, and I’ll find out the answers and update this page.

Sample g++ Make File: Multiple Source Files, One Executable:

a.out: list_func.o main.o search_func.o token_func.o  
     g++ list_func.o main.o search_func.o token_func.o 
list_func.o: list_func.cpp list_func.h
     g++ -c list_func.cpp
main.o: main.cpp
     g++ -c main.cpp
search_func.o: search_func.cpp search_func.h
     g++ -c search_func.cpp
token_func.o: token_func.cpp token_func.h
     g++ -c token_func.cpp

Basically, make checks the executable, which depends on four object (*.o) files. Each object file depends on a source file (*.cpp) and a header file (*.h). If any of the object files have to be remade, it does so (using the –c option so it knows not to freak out when it doesn’t fine int main() in the source file), then relinks them into the executable.

Sample g++ Make File: Multiple Executables:

all: wsj2cooked.out atis2cooked.out 
wsj2cooked.out: wsj2cooked.cpp
     g++ wsj2cooked.cpp -o wsj2cooked.out
atis2cooked.out: atis2cooked.cpp
     g++ atis2cooked.cpp -o atis2cooked.out

The first line just tells it that it has to make all the executables; if this line is omitted, it will stop after making wsj2cooked.out.


[1] This is actually an exaggeration.

MakeFile (last edited 2008-07-18 13:00:26 by NathanSanders)