A Simple Makefile for Medium-Sized C/C++ Projects
spin.atomicobject.com
A Simple Makefile for Medium-Sized C/C++ Projects
1–10 of 120 posts
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#2What 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.Re: A Simple Makefile for Medium-Sized C/C++ Projects
#3A 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.
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#4Re: A Simple Makefile for Medium-Sized C/C++ Projects
#5Thinking 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
#6Just 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.
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#7Just 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
#8Neat! 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.
Q ?= @
%.o : %.c
@echo 'CC $@'
$(Q)$(CC) -o $@ -c $(CFLAGS) $
Now you can make the commands visible again via `make Q=`.A more subjective question is, if you echo $@ or $<.
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#9We must be using a different definition of simple. I've never seen a simple makefile.
e.g. (not "medium-sized" project, but illustrates the simplicity) https://gist.github.com/androm3da/9b5575fb288045775c178a4fb2...
here's a slightly more feature-rich example, still relatively simple IMO.
https://gist.github.com/androm3da/9126ff51b5b47f69b99b1e3db8...
Re: A Simple Makefile for Medium-Sized C/C++ Projects
#10* 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.