by danieljh · 11y ago · 0 comments
Take a look at this C++ example: for a file mybin this creates mybin.o and then links it, spitting out a mybin executable:
env CXXFLAGS="-std=c++14 -Wall -Wextra -pedantic" LDLIBS="-lstdc++" make mybin
To see what's going on, and what kind of file types are supported: make --print-data-base | egrep 'COMPILE.cc|LINK.cc'
This not only shows you what is going on, but also what kind of environment variables are involved and can therefore be customized.For small projects I would create a config.mk (e.g. with CXXFLAGS, CXX, ...) and provide a small Makefile, something along the lines of:
include config.mk
all: mybin
mybin: mybin.o
watch:
while ! inotifywait -e modify *.cc; do make; done
clean:
$(RM) *.o mybin
.PHONY: all watch clean
This allows you to easily 1/ add dependencies for binaries and 2/ speed up the development proccess, using the make watch target (note: this does not include header dependencies).Disclaimer: Makefiles seem to be wonderful build-systems (not dependency managers!) for small projects; but as soon as you find yourself searching for hacks to build into your little Makefile, ditch it and switch to something serious. That's at least my experience.
start_ci:
watch time -p make clean all & echo $$! > tmp.ci.pid
stop_ci:
kill -9 `cat tmp.ci.pid`
Then you can start continuous integration by doing make start_ci
Then you can stop continuous integration by doing make stop_ci
Obviously, this is inspired by rc.d scripts.[0] https://github.com/lpsantil/rt0/blob/master/Makefile#L117
$$() might work, but untested.
[1] https://www.gnu.org/software/make/manual/html_node/Reference...
http://sourceforge.net/p/wordgrinder/code/ci/default/tree/Ma...
While it looks crazy, it has the advantage that it avoids pattern rules completely, which means that everything's explicit and we get to avoid some of make's more annoying misfeatures. It makes the makefiles vastly easier to reason about, as well as allowing things like building the same binary multiple times with different flags, which is really hard with traditional makefiles. The downside is that it looks crazy (and GNU make macros are not what you'd call well-designed, either).
As for switching to a different build system... like what? Every other build system I've seen is horrible in other ways, and make is at least ubiquitous. Every time I need to install some software which uses a non-make build system I get this horrible sinking feeling as I have to go and install the thing I need to install the thing.
...
Incidentally, the craziest thing I ever did in make was this:
http://cowlark.com/2013-10-19-insane-make/index.html
I wrote a compiler for a statically-typed language which targeted GNU make macros as a backend. Surprisingly, it actually worked, although I never got round to finishing the arbitrary-precision maths library needed by the runtime system...
What do you recommend? Autotools, bespoke shell scripts, or something else entirely?
Autotools has never be a great tool, only a necessary evil for when you need to package cross-Unixes software. I heard that CPack (http://www.cmake.org/Wiki/CMake:Packaging_With_CPack) do the job while being exactly as good as CMake (which can be a compliment... or not. YMMV).
So, if you use Rust, use Cargo, with Java use Maven, with C# use MSBuild, with ruby use Rake, etc. And C/C++ ? Well, for once if you can chose you're lucky. You can try CMake or premake.
The only thing you must do is get away of most of the Google's build projects: Gyp, Lunch, Ninja, etc. I have horrible experiences with those. Even worse than Rubygem's native compilation, which is quite a performance.
You need these things because you know what? One day someone else is going to want to modify your build system, to cross-compile for another target device, or to build a library instead of an executable, or to add a configuration option, or whatever. Or they are going to find that they need to optimise the build because it's too slow. And without these tools, those tasks are ridiculously complicated.
And lastly, it, would be wonderful if I could take an autotools or pure-makefile based project, and convert it to this system with a simple import statement - the resulting project build file wouldn't need to be particularly beautiful, because, with all those other tools that I listed above, I could clean things up by hand after the import.
The bad news is that as far as I am aware, no such tool exists. I assume it must be a hard problem to solve, because the pain that build systems cause is a real and ongoing concern for millions of developers around the world.
If you're the sort of person that writes these types of system, I would be your customer. Make the basic build system - where you can create and build projects - free, and make the debugging tools something that you have to pay for. I for one would be your customer.
All of which leads me to the bad news: I've never yet encountered a system that does these things, which is why I needed to include a plea to someone to make one.
You see, it heavily depends on your preferred environment.
[1] The documentation is actually a little dense, as qmake is a tool capable of building "real projects", but I found that a simple qmake -project && qmake && make (I think, at least you need a project file, and the let qmake make a makefile, and then use that...).
http://doc.qt.io/qt-5/qmake-running.html
See also: https://web.njit.edu/all_topics/Prog_Lang_Docs/html/qt/qmake...
Now I use it for large scale C++ projects and I've never looked back for other build tools, not even CMake.
Surprisingly, I never understood why KDE project that uses the complete Qt ecosystem doesn't use qmake but rather settled to CMake.
You can make some horrendous messes but it's nice to have Python around instead of having to learn another intermediate language as in CMake's case.
> adherent of SCons.
o_O
> You can make some horrendous messes
:nod: