4 ms·
Good advise. How do you usually define different sets of flags (for debugging, for production...) in your Makefile?
by teo_zero 3y ago
Good advise.
How do you usually define different sets of flags (for debugging, for production...) in your Makefile?
- flohofwoe 3y agoMeta build systems like cmake allow defining different build types with their own compile settings. I wouldn't recommend using 'raw' Makefiles directly for C/C++ development.
- SleepyMyroslav 3y agoPeople do not write makefiles anymore. At least not by hand. Typical AAA gamedev project has at least 4 targets defined in the build system of choice. Each target gets a set of flags for each platform. Typically there are ways to define common sets of flags and use them in the specific target. Half jokingly, choosing build system for a project is a very important step and one of things that kills desire to do C or C++ projects on the side. The article is a very friendly description of at least a decade of experience. Debugging build systems that do a lot of things ( unity files, caching, multiplatform and distributed builds ) has become an art in itself. Personally I prefer to capture commandlines that are passed to compiler as result to make sure that options are correct.
- saagarjha 3y ago…? Plenty of people write makefiles by hand. ./configure && make && make install is still a common method of doing build systems, even though there are a lot of new ways to also do builds now.
- cultureswitch 3y agoIt is a common and terrible method, only surviving out of general familiarity with the abomination that is autotools.
- saagarjha 3y agoSure, but that doesn’t mean it’s not still common.
- SleepyMyroslav 3y agoWriting software is a team effort. You need to be on same page with your team. Which means one needs to learn 'one of a lot of new ways'. In continuation of my AAA project example. For a standalone utility that targets only one Linux platform and will never need to consume libraries from AAA project a makefile is still acceptable.
- saagarjha 3y agoI’m curious why you’re focusing on games? I understand they have their own build systems. Everyone else has other needs.
- SleepyMyroslav 3y ago>why you’re focusing on games? Its quite simple. Games is what I do for living for quite some time. They are a decent specific example of a software project that employs lots of people who need to build software every day on a job. This way I can say what industry does instead of what I think it should do.
- Jorengarenar 3y agoI just want to remind, typical GameDev experience can differ substantially from typical SoftDev experience, so I'd be cautious from extrapolating on whole industry.
- SleepyMyroslav 3y agoI hope by specifically mentioning GameDev I have avoided misrepresenting other industries.
- Jorengarenar 3y agoI mean... you started by saying nobody writes Makefiles anymore...
- flohofwoe 3y agoUsing autotools on Windows is a PITA. And as much as cmake syntax sucks, at least cmake properly supports Windows and MSVC.
- SAI_Peregrinus 3y agoIf there's a ./configure step before make, it's not a hand-written Makefile, it's generated by Autotools.
- saagarjha 3y agoSome people hand-write their configure scripts, but it’s less common.
- SAI_Peregrinus 3y agoAnd some people hand-write Makefiles for some simple projects. But those are the output of configure scripts (or CMake files), so hand-writing a configure script (or CMakeLists.txt) isn't hand-writing the resulting Makefile. Writing Makefiles by hand for a single platform and target is easy, I do it for task automation, but it's unusably complex for multi-platform software with multiple build configurations.
- pjmlp 3y agoHow I keep the joy on C++ projects on the side, IDE project files, just like I have been doing since the Borland IDEs for MS-DOS were a thing.
- staunton 3y agoI would go further and say that nowadays "people should not use C++ anymore". You need a very good reason to start a big new C or C++ project. Half of such projects should "just be Java" (or C#, maybe even Python, Julia or JS with Electron etc.). The ones where C/C++ would have originally really made sense should now be Rust or Zig.
- Jorengarenar 3y ago> People do not write makefiles anymore. We do, not every project is of scope of AAA game. Heck, I don't even know if some of our projects could be converted from hand written Makefiles to something else.
- mytailorisrich 3y agoYou do not want different sets of warning flags. Usually what can change between, say, dev and release are optimization flags and stripping symbols.
- flohofwoe 3y agoYou might want to have at least different build types for enabling -Werror and not.
- Someone 3y agoIn GNU make, you can use Target-specific Variable Values (https://www.gnu.org/software/make/manual/make.html#Target_002dspecific https://www.gnu.org/software/make/manual/make.html#Target_00...) You can also do DEBUG ?= 1 ifeq ($(DEBUG), 1) CFLAGS =<whatever you want> else CFLAGS=<whatever you want> endif and then build with make DEBUG=0 for the release build. In BSD make, you can use something like .ifmake target CFLAGS := <whatever you want> .else CFLAGS := <whatever you want> .endif