I work in c++ mostly as a hobby (I'm still in school and therefor don't have a real job). The IDEs generate the makefile for me and so I'm wondering if it's worth learning how to make them myself. By "worth learning" I mean, should I drop everything and learn how to write them before continuing to learn c++? Is learning them going to be really necessary? If so, should I learn about them (general syntax and understanding how they work etc.) or really learn how to write them?
Yes, it is definitely worth understanding how Makefiles work. It might not be relevant to you right now (because you are using an IDE that generates them), but the chances are that the knowledge will be useful in the future.
By "worth learning" I mean, should I drop everything and learn how to write them before continuing to learn c++?
Frankly, that is a bizarre notion of "worth learning" ...
But no I don't think you need to do that.
Is learning them going to be really necessary?
We cannot predict whether you are really going to need this knowledge in the future. It depends on whether you continue with C++ programming and what context you do it in.
If so, should I learn about them (general syntax and understanding how they work etc.) or really learn how to write them?
I'd recommend both. If you can't write a Makefile, it is debatable that you know what is going on.
There is the other viewpoint which says that too much knowledge is not helpful.
If you get deeply into this you will learn that there are many different versions of Make, and that writing a complicated Makefile that works with multiple versions of Make on multiple platforms is ... hard. However, in the open source world, it is "best practice" to use tools such as
autoconf and so on to generate the makefiles, etc. If you do that, a lot of the version / platform related complexity is dealt with behind the scenes.
Finally, you tagged the question with "java". My take is that you shouldn't use
make to build Java applications (unless you are building native code libraries as well). There are Java specific build tools that are much easier to use ... and do a better job than
If you're working with open source or Unix-like operating systems, yes. Take heart though, they're not that complicated. Learning
make will save you a lot of time in the long run.
Makefiles are important on UNIX systems (e.g. AIX, Linux, OS X). However, I think that their absolute "you gotta know it" importance has diminished in recent years. For example, you don't really find them in Windows development (Visual Studio, etc.) and XCode (on OS X) uses a different system altogether. I'm not much into Java, but there I think they use ant files and whatnot.
There is a very cool system called CMake that generates native build files for the operating system that you happen to be running on. For example, if you write your project specification in CMake, then you can create a Visual Studio build project on Windows, an XCode project on Mac, and a Makefile on Linux. In a way, CMake replaces autoconf and automake.
I usually create CMake files for my "big projects" but I know Make in case I want to write a quick "just get it done" Makefile. It's good for your cultural literacy, because there are tons and tons of software libraries that use Makefiles, and you will inevitably need to edit the specific compilers and library locations. But you will find that big projects (like KDE) are migrating toward CMake and the like since Make does have some limitations that rear their ugly head when projects get complicated.
I'm bias as i think makefiles are a terrible system. You should learn general syntax so you can modifying an existing makefile. But i don't think learning everything about it nor making one from scratch is useful.
As with many aspects of IDE output, a typical auto-generated makefile is often inefficiently structured.
With an appropriate level of understanding, it is often possible to significantly improve the performance (faster builds etc). However, unless you really know what's going on, you are more likely to FUBAR, when fiddling with an autogen-ed file.
I highly recommend being able to understand what is going on... whether you subsequently choose to start editing an existing one, or creating your own, is a separate issue.
Being able to successfully use
make or something like it lets you check the "understands how to model the dependencies between parts of a program composed of more than one module" box.
Learning how to write Makefiles is a good idea for a number of reasons.
- Make is a language which lets you encode dependencies between components via rules. You will get a lot of experience with writing code this way, and it broadens your tools for thinking about solving programming problems.
- The principles you learn with Make can be used with Ant, Maven, and Rake if you choose to learn programming in the Java or Ruby world.
- Many IDEs have magic files which carry configuration information to help you build your software. If you don't believe me, try to write a script to build your software without the IDE. When you write your own Makefiles, you become very aware of the dependencies between your code, libraries, and your environment variables. As systems get larger, this turns out to be a useful tool for debugging your system.
You should always try to understand the build system you are using.
That does not necessarily mean you have to be able to create all of the build files by hand. The important part is understanding what the build system is doing for your project and the general ability to compile small projects manually (as in "typing commands on a terminal").
I just tend to think that creating (simple) Makefiles is the easiest step to understand what is going on, but you might have other means of understanding how to build things.
Why/when to learn Makefiles
If you keep programming for Windows only and don't expect anybody else to compile your code, feel free to compile the code how you like.
If you want to program compiler agnostic (as in "let others decide what compiler or IDE they want to use"), then you should learn another build system than just letting your IDE "deal with it".
If you want to program for different platforms, then you certainly need to use a widespread build system.
That still doesn't mean you have to know how the autogenerated Makefiles work in detail. You just have to know how the input files for the build system work. These just happen to have a similar syntax sometimes.
I personally really like Makefiles and use them for many things. Not just compiling code. I create a Makefile for every bigger pdf I create (with LaTeX) and every project I need to automate a couple of tasks in (building, packaging, uploading, updating dependencies from source repositories, pull/push manual backups)
However, I am working on the terminal a lot and I am working with Linux. I don't use what you would call an IDE other than vim (powerful text editor) and console tools. This might be very different for you.
If you ever complained about having to run different re-occuring commands just to "update"/package/upload/.. a "project", then learning how to write Makefiles might be something helpful for you.
If you have and use tools/GUIs/IDEs for everything, then you might not get anything out of that knowledge.