Live data from Hacker News

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

spin.atomicobject.com

21–30 of 120 posts

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

#21
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

The tabs in the makefile have been converted to spaces by the blog-posting software.

The commands for implementing rules are always indented by a tab. This is a classic makefile newbie make gotcha & everyone gets bitten by it at some point or other.

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

#22

Just use cmake or scons. In 2016, you should not hand write a single makefile ! A simple cmake/sconcs build file will be as simple as the one shown (or even simpler !) and it will definitively will be easier to integrate external dependencies if you have to.

Honestly cmake is such a shitty language though. Scons is slow.

CMake is almost great, but I have no idea why they went ahead and designed the _language_ the way they did. (Lists are concatenated strings, everything is basically macro expanded, etc..) I mean, if they were trying to improve on m4 and shell script, I wouldn't exactly say they succeeded.

I realize that CMake has better cross-platform support, but I can't stand using it. For small projects it's fine, but for medium- to large-sized projects it's a bigger headache than autotools imho.

(That said, I explicitly don't care about Windows support, which is the only place where it really matters to have something different than autotools, and even that is not so bad with MingW and will be even better, it seems, with the coming "linux-compatible subsystem")

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

#23
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

Your editor probably automatically converted tabs into spaces. And just like that, the Makefile stops working. Which proves the point: Makefiles are at a point in life where they should be exclusively automatically generated. The only exception are throwaway projects where you and only you use it.

I strongly disagree. The tab requirement for Make is very well known and less strange than custom Makefile generation. Simple Makefiles work extremely well in lots of projects.

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

#24
post #16

It always annoys me that we don't have better solutions for building C and C++ projects by now. My own take on the generic drop-in makefile[1] has over 1000 stars on github, which says pretty loudly to me that this is a common pain point for many people. Alas I haven't had a brilliant idea for a solution (yet). [1]: https://github.com/mbcrawfo/GenericMakefile

The solution is good tooling, Visual Studio makes this a non-issue with sane defaults that can be extended if needed.

I haven't tried CLion yet but I would assume it's decent given JetBrain's track record.

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

#25
post #18
post #5

I do like simple makefiles. I adopted a C++-project without having much C++-knowledge, and simplifying the build setup was a big step in making it mine. Thinking that it might be nice, I tried this one instead of my own approach at a simple makefile ( https://github.com/onli/simdock/blob/master/Makefile ) and I get this error: > Makefile:16: * missing separator. Stop. Which raises kind of an important point: Simple m…

Make unfortunately depends on hard-tabs for the recipes. Your editor probably switched it to spaces.

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!

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

#26

Just use cmake or scons. In 2016, you should not hand write a single makefile ! A simple cmake/sconcs build file will be as simple as the one shown (or even simpler !) and it will definitively will be easier to integrate external dependencies if you have to.

cmake generally works great, but the larger and more complex the project gets (and the more platforms you need to support), it gets exponentially uglier. I've had the displeasure of needing to maintain a single cmake infrastructure for a large (~500K or so lines plus 3rd party libs) project that targeted Windows, Linux, Mac, iOS, Android, and a few other obscure mobile platforms. Here was the progression:

1. Linux target: "Wow this is a breeze!"

2. Mac target: "Ahh, a little learning curve, but no problem!"

3. Windows/VC target: "Jeez, I hope I don't have to hand-edit this monstrous vcproj this thing generates..."

4. iOS: "WTF!! Simulator targets, device targets, provisioning profiles, code signing.. This stuff was all just hacked into cmake and barely made to work wasn't it??"

5. Android+NDK: "Kill me now"

6. Other obscure mobile targets with toolchains themselves that barely worked: "La La La, I'm ready for the funny farm. The cucumbers! They're dancing! And glowing!! The room is getting hazy and dark.. Where's my vodka?"

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

#27

Just use cmake or scons. In 2016, you should not hand write a single makefile ! A simple cmake/sconcs build file will be as simple as the one shown (or even simpler !) and it will definitively will be easier to integrate external dependencies if you have to.

That is just kicking the can further down the road. Now, instead of mantaining makefile for make, you are mantaining CMakeLists.txt for cmake.

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

#28
post #23

Earlier quoted context omitted.

Your editor probably automatically converted tabs into spaces. And just like that, the Makefile stops working. Which proves the point: Makefiles are at a point in life where they should be exclusively automatically generated. The only exception are throwaway projects where you and only you use it.

I strongly disagree. The tab requirement for Make is very well known and less strange than custom Makefile generation. Simple Makefiles work extremely well in lots of projects.

Somebody listed a number of common build system requirements below, but of course there are usually many many more like custom compilers, cross-compilation, any number of things that your "simple makefile" can't work with.

By the time the Makefile has grown to support all these things it no longer has the properties that made it useful in the first place (parsimonious, understandable, small).

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

#29
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.

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.)

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

#30
post #25
post #18

Earlier quoted context omitted.

Make unfortunately depends on hard-tabs for the recipes. Your editor probably switched it to spaces.

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.

Post reply on HN