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.
A Simple Makefile for Medium-Sized C/C++ Projects
31–40 of 120 posts
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#32Just 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 ta…
It sounds fun to read.
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#33Just 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.
Would be nice if you could give an example, not just "use that".
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#34Just 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.
Would be nice if you could give an example, not just "use that".
$ scons
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#35It 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
- proper module system, none of this header file nonsense
- no compiler flags to worry about
- no preprocessor definitions to worry about
- as a consequence of the above, no dependencies that require their own linker flags, include directories and preprocessor definitions to work
- no need to support different compilers/platforms with different configurations (which work differently with libraries that require different linker flags and include directories and...)
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#36Please 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.)
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, so there's a rather large barrier to entry.
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#37Re: A Simple Makefile for Medium-Sized C/C++ Projects
#38Earlier quoted context omitted.
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
#39No.... 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!
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#40Please 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.)