News for hackers. Stuff that matters.
Re:A Simple Makefile for Medium-Sized C/C++ Projects by onli on Friday August 26, 2016 @09:37AM (#12366098)
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 means understanding what is happening. I have no idea why `$(CC) $(OBJS) -o $@ $(LDFLAGS)` does raise that error - and just like that it is not simple for me anymore.

Edit: Now with the tab-error out of the way, it of course does not find the dependencies. That might be caused by a strange project organization (like said, it is an adopted project) or maybe the makefile is just not complete – I'm not sure how far the auto-generation is supposed to go. Played a bit with it, but that just removes the simplicity. For now, I think that the pkg-config way is nice and explicit, and would recommend to take a look at the linked makefile if a simple one is searched. Though I still would be happy about optimizations for that file!

I of course just might miss the point. Well, after all that supports mine: Not that simple after all.

Re:A Simple Makefile for Medium-Sized C/C++ Projects by pja on Friday August 26, 2016 @09:59AM (#12366265)
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 by steveklabnik on Friday August 26, 2016 @12:55PM (#12367544)
I recently tried to improve this error, but it looks like the maintainers aren't interested: https://savannah.gnu.org/bugs/index.php?48276
Re:A Simple Makefile for Medium-Sized C/C++ Projects by aeruder on Friday August 26, 2016 @09:54AM (#12366231)
Make unfortunately depends on hard-tabs for the recipes. Your editor probably switched it to spaces.
Re:A Simple Makefile for Medium-Sized C/C++ Projects by pja on Friday August 26, 2016 @10:02AM (#12366302)
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 by onli on Friday August 26, 2016 @10:06AM (#12366333)
Yep, that's exactly what happened. Thanks for the explications.

I actually did know that once, but forgot. Make definitely has its hidden traps.

Re:A Simple Makefile for Medium-Sized C/C++ Projects by pja on Friday August 26, 2016 @10:30AM (#12366507)
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 by pja on Saturday August 27, 2016 @03:42AM (#12371457)
Now fixed!
Re:A Simple Makefile for Medium-Sized C/C++ Projects by revelation on Friday August 26, 2016 @09:53AM (#12366218)
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.

Re:A Simple Makefile for Medium-Sized C/C++ Projects by mbrock on Friday August 26, 2016 @10:01AM (#12366293)
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 by revelation on Friday August 26, 2016 @10:05AM (#12366329)
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 by anjbe on Friday August 26, 2016 @10:15AM (#12366387)
Supporting custom compilers and cross‐compilation is as simple as using ${CC} in the Makefile instead of gcc…
Re:A Simple Makefile for Medium-Sized C/C++ Projects by revelation on Friday August 26, 2016 @10:22AM (#12366450)
This is how we got into this mess in the first place. "Surely it can't be very difficult, let me just add this.."
Re:A Simple Makefile for Medium-Sized C/C++ Projects by anjbe on Friday August 26, 2016 @10:36AM (#12366555)
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 by Tyr42 on Friday August 26, 2016 @10:20AM (#12366440)
I mean, if you're going to be generating it anyways, just generate ninja files. They are faster, but the downside is just that you need to generate them, as opposed to being generic.
Re:A Simple Makefile for Medium-Sized C/C++ Projects by stevekemp on Friday August 26, 2016 @09:52AM (#12366214)
Sadly you're bitten by the biggest misfeature in Make - You must use TABs not spaces.