Johnathon332
Posts: 10
Joined: Thu Aug 02, 2012 10:26 pm

MakeFiles

Sat Aug 04, 2012 2:35 pm

Hey, I'm fairly new to linux and looked around the net about makefiles but I can't really seem to make sense of any of them. I was wondering if someone could explain how you would compose your own makefile and what it actually does.

Thank you

User avatar
Gert van Loo
Posts: 2422
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: MakeFiles

Tue Aug 07, 2012 8:57 pm

I typed "makefiles explained" in google.
I think this one is not too bad:
http://www.google.co.uk/url?sa=t&rct=j& ... Mp6vdaGd6A

However none of the manuals will make much sens unless you have compiled programs yourself and thus
have some idea what linux commands look like, how to compile/assemble/link or in general how to build computer 'stuff'.

User avatar
gordon@drogon.net
Posts: 1961
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: MakeFiles

Wed Aug 08, 2012 9:55 am

Johnathon332 wrote:Hey, I'm fairly new to linux and looked around the net about makefiles but I can't really seem to make sense of any of them. I was wondering if someone could explain how you would compose your own makefile and what it actually does.

Thank you
A Makefile is essentially a file with instructions about how to do stuff.

So it contains a simple variable mechanism

foo = 123

and a set of rules that say

this depends on that

which then translate to

if that has changed, then to this

So if you have a project that involves more than one file and you change one file, you only need to re-compile that single file, then link the binaries together. This is much more efficient than recompiling 30 files each time something changes.

Another way to view a Makefile is that it's actually a progrmaming language - you're writing a program to control the comilition of your other programs - however it's a pretty eseoteric "language" if viewd that way.

There are 1000's of resources online about Makefiles and an O'Reilly book (or 2), but if you want some simple exanples, then have a look at my wiringPi library - it uses Makefiles to compile and link the files together.

https://projects.drogon.net/raspberry-p ... d-install/

Just one thing to remember about Makefiles - spaces and tab's are treated differently! IF you ever copy & paste a Makefile, or bits of one then it may change tabs into spaces and it'll stop working. Thats trips up a lot of newcomes to makefiles!

-Gordon
--
Gordons projects: https://projects.drogon.net/

Return to “General programming discussion”

Who is online

Users browsing this forum: No registered users and 5 guests