Live data from Hacker News

A Simple Makefile for Medium-Sized C/C++ Projects

spin.atomicobject.com

61–70 of 120 posts

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#61
post #41
post #36

Earlier quoted context omitted.

Autotools does do all of those things. I'm not a particular fan of it either, but when I'm packaging software for a Linux distro then I'd rather see autotools or cmake being used instead of some crappy custom build system that will require patching to make it work. There is room for someone to come up with a good build system. It had better do everything autotools and cmake do, and be well documented and widely used,…

Auto tools is great. To compile all you do is ./configure make make install It couldn't be simpler. Even though I am part of the GitHub generation, I don't see why so many of my peers hate it. I actually like it.

This only works in the Unix world, on Mac only for command line tools (but only after installing autoconf and make), and not at all on Windows unless you install a complete Unix environment (cygwin or mingw).

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#62
post #30
post #25

Earlier quoted context omitted.

If you cut & paste the makefile in the blogpost, you’ll discover that the blog itself has converted the tabs in the makefile to spaces. Not very helpful to any confused newbies out there!

Yep, that's exactly what happened. Thanks for the explications. I actually did know that once, but forgot. Make definitely has its hidden traps.

I’ve made a comment to that effect on the original blog post. Hopefully they’ll be able to fix it.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#63
post #10

Please don't brew your own build system. It likely won't handle at least one of the following situations: * installing into a DESTDIR * setting custom CFLAGS/LDFLAGS * changing prefix, libdir, sysconfdir * cross-compilation * parallel builds * conditional features * missing requirements and will make packaging your software in Linux distros much harder than it needs to be.

> installing into a DESTDIR

> setting custom CFLAGS/LDFLAGS

> changing prefix, libdir, sysconfdir

> cross-compilation

Pretty much all of this can be done trivially in a makefile, using a very innovative construct called "variables".

> parallel builds

make -j. Works especially well if you have working dependencies. This makefile does.

> conditional features

make has ifdef... Granted this makefile uses find to discover source files, which won't totally work. But it's a small fix. Or you can do conditional features through CFLAGS.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#64
post #47
post #29

Earlier quoted context omitted.

There’s no point telling people not to do something if you don’t give them an alternative that does do all those things. (And no, “just use autotools” is not a viable answer.)

I'm surprised no one says, "Just use waf." It does all those things. It's fast. It's cross-platform. The language is Python. It's a bit steep to learn and maybe doesn't have the most mature built-in recipes for certain complex builds like mobile or desktop frameworks, but it seems like those things would be addressed quickly if more people were using it. The maintainer is a class act, consistently putting out new fea…

WAF is not so much a build system, but a bunch of python scripts to create your own build system, it's in the same zoo as cmake, scons or premake, but (in my opion) worse than any of those. I might have had a bad first impression though because of the project I had to use WAF in had terribly complex WAF scripts.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#65
post #41
post #36

Earlier quoted context omitted.

Autotools does do all of those things. I'm not a particular fan of it either, but when I'm packaging software for a Linux distro then I'd rather see autotools or cmake being used instead of some crappy custom build system that will require patching to make it work. There is room for someone to come up with a good build system. It had better do everything autotools and cmake do, and be well documented and widely used,…

Auto tools is great. To compile all you do is ./configure make make install It couldn't be simpler. Even though I am part of the GitHub generation, I don't see why so many of my peers hate it. I actually like it.

That's the ideal situation, yes, but god help you when something goes wrong.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#66
The problem with Makefiles is that they don't work on Windows with Visual Studio, and generally only have very limited support in IDEs like Xcode, QtCreator, etc... and once stuff like cross-compilation and feature selection comes in, they get really messy really fast. That's where meta-build-systems like cmake etc come in. They all have their faults (cmake has a terrible scripting language), but they solve real problems for non-trivial projects.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#67
post #38

Earlier quoted context omitted.

Supporting custom compilers and cross‐compilation is as simple as using ${CC} in the Makefile instead of gcc…

This is how we got into this mess in the first place. "Surely it can't be very difficult, let me just add this.."

Perhaps, but I suspect writing a portable Makefile is not as difficult as you think.

Speaking as a packager, I have to patch many CMake build systems for portability issues. And don’t even get me started on SCons. Autotools is better in that regard, but has many flaws of its own.

Here’s an example of a portable Makefile I’ve contributed to a project which handles the common packaging issues (staging directories, cross‐compilation, parallel builds): https://github.com/sinamas/gambatte/pull/6/commits/8d6fffc2b...

Compared to the original build system (two SConstructs): https://github.com/sinamas/gambatte/blob/master/gambatte_sdl... https://github.com/sinamas/gambatte/blob/master/libgambatte/...

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#68
post #47

Earlier quoted context omitted.

I'm surprised no one says, "Just use waf." It does all those things. It's fast. It's cross-platform. The language is Python. It's a bit steep to learn and maybe doesn't have the most mature built-in recipes for certain complex builds like mobile or desktop frameworks, but it seems like those things would be addressed quickly if more people were using it. The maintainer is a class act, consistently putting out new fea…

WAF is not so much a build system, but a bunch of python scripts to create your own build system, it's in the same zoo as cmake, scons or premake, but (in my opion) worse than any of those. I might have had a bad first impression though because of the project I had to use WAF in had terribly complex WAF scripts.

True, they do call it a build system toolkit. But I think worse than the others is on the wrong track and the sentiment is too heavily influenced by your negative first impression.

swtoolkit made scons really nice to work with (but couldn't fix the speed issues). It's a shame it was abandoned. In the same way, a thin layer of functions as demonstrated in the waf "toolkit" examples could lean on the power of waf and provide a build system every bit as snazzy as big, polished systems like bazel and buck, but it would work cross-platform out of the box and be extensible with only Python. But I think waf is close enough to being high level that no one bothers to create and polish a build system layer (maybe internally in companies, but the open source uses I've seen use pretty standard waf scripts).

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#69
post #10

Please don't brew your own build system. It likely won't handle at least one of the following situations: * installing into a DESTDIR * setting custom CFLAGS/LDFLAGS * changing prefix, libdir, sysconfdir * cross-compilation * parallel builds * conditional features * missing requirements and will make packaging your software in Linux distros much harder than it needs to be.

> installing into a DESTDIR > setting custom CFLAGS/LDFLAGS > changing prefix, libdir, sysconfdir > cross-compilation Pretty much all of this can be done trivially in a makefile, using a very innovative construct called "variables". > parallel builds make -j. Works especially well if you have working dependencies. This makefile does. > conditional features make has ifdef... Granted this makefile uses find to discover…

Can be done. The question is will the half-assed Makefile that a developer wrote for themselves do any of those things? And I can tell you from bitter experience that is very very unlikely. Plus I will still have to spend the time to understand the Makefile, which I won't need to do if they'd used an established build system in the first place.

Re: A Simple Makefile for Medium-Sized C/C++ Projects

#70
I'm going to take this opportunity to rant about sad state of C++ open source. I would really really like to write some C++ but I'm not a C++ guru; so I tried installing facebook/folly and facebook/fatal on my Mac OS. That just doesn't work. It wasn't written cross platform and it probably never will. So I spun up a ubuntu VM and tried there. fatal compiles, folly still doesn't... And so ends my brief foray into C++. At that point I started researching how can I bind the library I need to Rust so I can skip all this nonsense.

C++ is not a bad language and I would like to write a project hat uses it. But I'm just a user of the language. I don't have time and expertise to tackle those build issues and quite frankly installing any library is a major PITA.

Post reply on HN