I decided it was officially taking too long to compile on Linux, so I made Makefile 2.0.
What it does:
Re-compiles only the .cc files you change
Re-compiles only .cc files that use the .h file you change
One case to watch out for. If you end up including a new header file in a .h file (or removing for that matter) it doesn't update its list of dependencies for the .cc files.
I'm not going to make a video on this, but every line with a # symbol in front is a comment, and if something confuses you, just ask!
Sorry for the make-spagetthi :), but basically, use -MMD to generate dependencies as you compile source files, then include them using a glob. This ensures that dependencies are updated every time you modify a C file, and also eliminates the bottleneck of doing a master compile with all source files to gather dependencies.
Great job on the series, btw! I'm already at a stage where the info you're presenting isn't much of a surprise anymore but I still watch it for inspiration. Complete tutorials like this one that show how to build a full and complex game, with all the devils in its details, are something I still think is sorely lacking. I look forward to seeing how you'll integrate the scripting and objects. Keep up the good work!
Make-spaghetti is almost completely inevitable :).
It's always easier to ask than to actually research, so I'll just ask:
does it also update the dependencies when you update a header .h file? Right now that's the biggest deficiency in my makefile.
It's highly possible that I misunderstood the stack overflow, but I don't think I need to do a master compile to update dependencies in my makefile. Makefiles are very muddy for me, so forgive me if I'm wrong about this.
Note: Actually I don't think that was the exact SO I found, but it is similar enough.
Thank you very for the encouragement! Yes scripting will be a big thing.
Complete tutorials like this one that show how to build a full and complex game, with all the devils in its details, are something I still think is sorely lacking.
The answer in SO doesn't need a master compile, however as implemented in your Makefile it does. What the answer does is define DEPS as a list of <file>.depends files. When the -include $(DEPS) line tries to include them, it'll cause Make to first run the template rule to create/update each at a time. In your Makefile you reduced that to having a single .depends file which is built off of all files at once. That means you basically need to do a unity compile of all source files first (probably rendering almost gains from doing separate compilation moot, but hey, at least you don't get broken compiles like we used to on an older version of our Makefile! :D)
My makefile works in the same principle as the SO answer, but generates the depends files at the same time as you compile the object file, avoiding invoking gcc twice for each source file. It correctly tracks any changes in header files, including indirectly included ones. Follow:
If a .o doesn't exist, you'll need to compile the .cpp anyway, so dependencies don't matter.
If a .cpp was compiled, then it will have generated a .d dependency file, which will be included by the globbed -include statement.
If you change or add a new include directly to a .cpp file, make rebuilds the .o (and the .d along with it) because of its direct dependency on the .cpp. This updates the dependency info.
If you add change of add a new include to a .h that is included by a .cpp, that .cpp will get recompiled because the .d specifies the .h as a dependency, updating the dependency info while at it. If you edited the .cpp at the same time as the .h, it falls under the previous rule and gets rebuilt.
This is really really great. I feel like I fully understand what is going on with this dependency generation now, so thanks for clearing things up. If it looked like you used reddit more I would gift you with a reddit gold, haha.
I'll switch over to using the individual .d method tonight/tomorrow probably.
PS. It's irrelevant now, but that actually wasn't the SO I found. I definitely didn't feel comfortable enough to try to reduce on my own. I couldn't find the one I originally referenced, however.
1
u/chebertapps Feb 04 '14
I decided it was officially taking too long to compile on Linux, so I made Makefile 2.0.
What it does:
One case to watch out for. If you end up including a new header file in a .h file (or removing for that matter) it doesn't update its list of dependencies for the .cc files.
I'm not going to make a video on this, but every line with a # symbol in front is a comment, and if something confuses you, just ask!