Jump to content
  • Advertisement
Sign in to follow this  
Zmurf

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

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 files
myprogram: 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.o
gcc -c object2.c -o object2.o
gcc -c object3.c -o object3.o
gcc object1.o object2.o object3.o -o myprogram


Like magic.

Visual studio has nmake I think, which is mostly the same thing.

Share this post


Link to post
Share on other sites
I read about nmake, it says i have to enter a command line, where do I put this?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!