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.
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!