[unix] ELI5 'makefile'
Hello, all! I'm relatively new to programming. Took a Intro to C and a Intro to C++ course and want to improve some of my knowledge, so I thought I'd do a project I found online. I stumbled upon using a 'makefile' on the project and decided to look into it.
I've looked at these sites and don't quite grasp how makefiles work or mostly, how they are created.
What exactly are targets? What are exactly are dependencies?
Say I have three files, main.cpp, hello.cpp, name.cpp and that name.cpp has a function that tells me the name, hello.cpp displays "hello, name::function" or whatever and main calls it all. (That was probably a quite terrible example), could I make a 'makefile' called swaggity_swag ? How would that look like?
ELI5 would be nice. thanks in advance.
Posted Mar 31, 2015, 12:32 PM UTC
It's just a bunch of instructions to build an application. This saves you from typing all the commands every time you want to build your application from source. That's pretty much all there's to it: it saves (a lot of) time.
In a text editor. They're just text files.
They're basically just tasks. The compilation of C++ into an executable consists of a bunch of steps. You combine those steps into a 'build'.
Dependencies are anything that your code depends on to be able to be built. For example if you want to create an MP3 player you might depend on an MP3 library to handle the decompression for you.
You could but normally the filename is in fact 'Makefile'. If you type 'make' it will find the makefile and run the commands in there to build the project.
There's plenty simple examples of what a makefile looks like.