Live data from Hacker News

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

spin.atomicobject.com

41–50 of 120 posts

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

#41
post #36
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.)

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.

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

#42
post #7

Earlier quoted context omitted.

Especially since scons and cmake are in no way easy to learn, imho.

Still hell of a lot simpler than hand-writing Makefiles though. For both small and large projects. I mean, a "hello world" CMakeLists.txt can be literally just this: add_executable(hello hello.c) And it's cross-platform, can generate Visual Studio/Xcode/... projects, etc.

I think we have to go deeper than that to really see an advantage of cmake. A corresponding makefile would be:

    all: hello
That's not really complicated either.

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

#43
post #2

Neat! I've been putting off learning how to use those `-M` flags to automatically generate dependencies, but it looks like it's not that hard :) What I also like to do is hide the actual compilation command with recipes like this, inspired by the Linux kernel %.o : %.c @echo " CC $ I think it looks a lot tidier, it turns a ton of dense uninteresting command lines into a few dozen short lines.

In a past life, the mega-but-autogenerated Makefile I helped maintain would store the executed command and only echo it if the command failed. And we logged everything to file, so you got nice output but all the info was there if we needed it. Didn't take that long to work out how to do it, once we'd decided it would be a nice thing to have.

I like that. It lives the Unix philosophy to be silent unless an error occurs.

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

#45

"But because Make works backward from the object files to the source, we need to compute all the object files we want from our source files". No.... don't do this. Make is intended to work the other way around... it finds the source from your targets. Define your VPATH and let it find them. This is what loads of people do and is why there are so many Makefiles are packed full of macro-magic!

Totally agree, they should use VPATH. And that way they could've just skipped to the implicit rules version.

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

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

The LibreOffice build system (which is plain GNU Make, without generated unreadable intermediate build files) does all these and more. Doing the same with autotools would be a nightmare.

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

#47
post #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.)

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 features and bug fixes and working with pull requests.

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

#48
post #2

Neat! I've been putting off learning how to use those `-M` flags to automatically generate dependencies, but it looks like it's not that hard :) What I also like to do is hide the actual compilation command with recipes like this, inspired by the Linux kernel %.o : %.c @echo " CC $ I think it looks a lot tidier, it turns a ton of dense uninteresting command lines into a few dozen short lines.

I did the hiding for a while until I noticed that it slows my debugging down way too much when something breaks and I want to manually fiddle with some compiler flags. Now I let make use two separate colors: One for info I'm usually interested in and one for stuff I need to know when I need to get my hands dirty.

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

#49
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 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

#50
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 is kinda hilarious because, yes, "Autotools is great" [as a consumer]. But autotools and m4 is kinda awful to write IMO.
Post reply on HN