Public Group

# Make and Makefiles

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

## Recommended Posts

Hello,

I am confused about make and makefiles. I learned programming with visual studio, which uses convenient project files. VS lists all source files and when you press 'Build solution' it will be compiled and build and everything goes smoothly.

But sometimes I want to use code written by others like SDK's. Every now and than I come across some code that does not offer binaries, you have to build it yourself. They come with makefiles and as soon as I see the file "Makefile" I delete everything and search for an alternative. But today I want to find out how it works and understand why so many people use this horrible build system
So my knowledge so far:

Makefiles contain a set of instructions to build a particular program. Make is the program that reads the makefiles and builds the program based on the source files indicated by the makefile.

Questions i have:
- Make itself is not a compiler is it not? So what compiler is being used? How can you configure it?
- Lets say I download some source code that needs to be build first, it contains a Makefile. How do I proceed in Windows?
What programs do I need to download in order to build this code on Windows? I already downloaded GNUWin32, added the make to my system path but when I open cmd.exe and run the make command in the right directory I get an error (process_begin: CreateProcess(NULL, echo <etc etc> Please wait..., ...) failed. make (e=2): The system cannot find the file specified.).

Googleing doesn't really help me, neither did a search on gamedev. I heard something about cygwin, downloaded it but than I have to run some kind of Linux command screen which I don't understand too well. I also downloaded the gcc compiler, copied the files to the home directory and ran make inside this console, but than I got some other error again and I don't realy feel like using all this stuff, do people realy think this mess is any better than the goodworking convenient project files from visual studio?

I just can seem to figure out why people want to go through all this trouble to use makefiles instead of project files?
Are there any easy ways to build Makefile-projects in Windows? I hope anyone can push my in the right direction, all tutorials I can find on make and makefiles assume you use linux I guess.

Greetings,
Rob

##### Share on other sites
At the most basic Makefiles consist of two kinds of elements: definitions and rules. A definition assigns a string to a variable. Ex:
 CC = gcc 
This assings the string "gcc" to the variable CC. Next there are rules. Rules consist of a target and dependencies followed by a list of commands. A target is separated from its dependencies by a colon. When a target is processed, if the target is missing or any of the dependencies are newer than the target, the list of commands are executed. For example:

##### Share on other sites

Questions i have:
- Make itself is not a compiler is it not? So what compiler is being used? How can you configure it?
- Lets say I download some source code that needs to be build first, it contains a Makefile. How do I proceed in Windows?

What you want to google is msbuild vs nmake.
MSBuild is the Microsoft replacement tool for nmake which it used for makefiles.
The problem with Microsoft's version of make i.e. nmake is that it was never as powerful as the Unix version.
And that leads to why make is so hard to use is that it's so general.
You can pretty much run any available unix command inside your makefile and do all kinds of crazy stuff.
Also, that's probably why you are getting that error above since the makefile you found is probably trying to run some unix program which of course it's not going to find on your Windows system!
Unless you want to spend a ton of time learning about makefiles your best bet is to find a Windows specific version of what you are looking for.
For example, here is a makefile for the code for Stroustrup: "Programming: Principles and Practice using C++" and it's Mac specific at that.
The only way half of that stuff will even make any sense is if you have some unix shell programming experience.

I just can seem to figure out why people want to go through all this trouble to use makefiles instead of project files?

Because it's the unix way

##### Share on other sites
Also, consider Makefiles are generic in sense they aren't limited to calling your compiler.
You can do anything you want in them, as long as you have some, uh, "command line" skills.
Consider an environment where everytime you want to "build", you not only want to compile your code into an executable, but also to run stuff like: run scripts that auto generate documentation, run programs that check your code, generate some of the source code automatically prior to compiling, and after all, create a final product (think of creating a compacted file) containing arbitrary data (such as models and textures as this is gamedev) plus your freshly compiled executables.
With a properly written Makefile you can usually do that by just running "make".
(I don't have any Windows development experience so I don't really have a clue on how you would do that without make or some case specific and probably clumbered tool).

##### Share on other sites
I've run into a makefile situation not too long ago and did not figure out how to resolve it either. I'd like to ask what exactly is a makefile? Is it partial source code, full source code, or even source code?

I haven't touched command line *nix since Ubuntu (Fiesta I think) came out and was more heavily dependent on Win OS, though I've moved onto Mac now but still a total newb there. =+P

##### Share on other sites
I don't think you can call a makefile "portable" if it won't work right away on all target platforms (maybe when a lot of people say "portable" they really mean "Unix", but oh well)...

You can import a makefile into Visual Studio and it will create a solution/project for you. See: http://social.msdn.microsoft.com/Forums/en/vsx/thread/f7cc8fdb-8e73-44e4-b78d-2bf8ae5aa83f

##### Share on other sites
Thanks everyone. I guess the problem I had with makefiles is that I was under the false impression that makefiles were portable.
It just turns out makefile projects are a pain in the ass unless you use *nix too.
I still dont get it why this is, it shouldnt be so hard to come up with a system that is platform indepentant is it?
For now Ill tro to learn how to read and convert them. Thanks for the help everyone!

##### Share on other sites

Thanks everyone. I guess the problem I had with makefiles is that I was under the false impression that makefiles were portable.

Portable makefiles are portable. Just as C++ is portable, but most C++ programs are not actually portable.

I routinely write makefiles that work with Mingw on Windows, and standard gcc on Linux/Mac. Although a real portable build system like CMake is much to be preferred where available.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013221
×