What is a 'Makefile' and how do I use it?

Started by
5 comments, last by smart_idiot 18 years, 9 months ago
Whenever I download a source code or example, I usually find no prject file, but a Makefile instead. What does it do and how do I use it?
If it's possible for us to conceive it, than it must be possible.
Advertisement
There are different forms of Makefiles, for example for gnuMake, automake,...

A Makefile is a file with rules for dependencies. Normally it will be used for building libraries and executables from sourcecode.

To use a Makefile you need the right make-Program and you need normally to change some values in the makefile, for example include-paths, compiler-path etc.

Which operating system are you using?

If you're using Windows, I can't help you, although I think the Linux example below may apply too.

Under Linux, Makefiles are part of the de facto standard for the compiler project files. They are used by the UNIX command MAKE to form a coherent executable, so they're similar to project files. The way you spell Prject (could just be a typo), I would assume that you might be using Anjuta, and Anjuta (along with KDevelop, and, I think, Borland C++) has no problems with importing makefiles - you should have no problem creating a standard project file out of them.

J
I'm using .Net on Windows.
If it's possible for us to conceive it, than it must be possible.
Makefiles contain information on what other files a file needs to be created, and the commands to do it.

Simple example:

# Object files depend on source files%.o: %.c# And the command to create an object file from a source file is this:	gcc -c $< -o $@# Our program depends on 3 object filesmyprogram: object1.o object2.o object3.o# And here is the command to link them into a program:	gcc $^ -o $@# This is a phony target, it will cause myprogram to be created.all: myprogram


Then you run 'make all', and make will figure out what needs to be done and start executing commands:

gcc -c object1.c -o object1.ogcc -c object2.c -o object2.ogcc -c object3.c -o object3.ogcc object1.o object2.o object3.o -o myprogram


Like magic.

Visual studio has nmake I think, which is mostly the same thing.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
I read about nmake, it says i have to enter a command line, where do I put this?
If it's possible for us to conceive it, than it must be possible.
I assume you enter it in that big black box with scary looking words and flashing square cursor that few dare to enter that often gets mistaken for DOS.

How to enter this mysteryous world from Windows:

  • Press Windows Key+R together.

  • Type
cmd
  • Press enter.
  • Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

    This topic is closed to new replies.

    Advertisement