by chimeracoder · 12y ago · 0 comments
Most of the common criticisms of Make are actually criticisms of autoconf, which I agree is a hideous tool. (On the other hand, autoconf is a tool intended to address a hideous problem, so perhaps that's inevitable).
A lot of the more recent build tools I see are largely reinventions of Make. Make is very widely supported (most basic projects can make do[0] with portable Makefiles, though GNU Make is also available for most systems), and its syntax is actually very easy to grasp and manipulate[1].
[0] no pun intended
[1] Most projects only need a very small subset of what Make has to offer, anyway, and that can be learned in a matter of minutes.
[1] Something like http://mad-scientist.net/make/autodep.html
Incidentally, I am working on a make-replacement that is intended to address this and similar needs. It's still in very early stages, but I think I'm onto something.
The idea is to write a very low-level tool that leaves out most of Make's higher-level abstractions. In my tool there are no recipes, no implicit rules, no variables or variable substitutions, no conditionals, etc. The input to my tool is just the precise specifications of the commands you need to run, their inputs and outputs (so a precise dependency graph can be calculated), and with everything fully-expanded already.
The idea, then, is that whatever higher-level abstractions you want (if any) you build into a higher-level tool. The higher-level tool just spits out a file describing the list of tasks. Then the higher-level tool can worry about the higher-level structure, policy, configuration, etc. of your project. So instead of writing things like implicit rules in Makefiles, you just write some code that explicitly generates tasks.
For example, with Make, you might write an implicit rule like this:
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
Then Make magically decides which output files match this implicit rule. My idea is that, instead of this, explicitly apply your rules to your inputs. Your build system could instead be a Ruby/Python/etc. script that looks something like this: for c_file, o_file in files:
tasks.append(Task(
target=o_file,
source=c_file,
command="gcc -c %s -o %s", c_file, o_file
))
print(tasks)
I think this is much more convenient than having to program in Make and learn its quirky abstractions.I have an elegant solution for the auto-dependency problem (unproven, but I think it's promising). The idea is that your dependency-calculating tasks are still just tasks, but the tool knows how to integrate the calculated dependencies back into the overall dependency graph. These dependency-generating tasks depend on the files they are generating dependencies for, so it is all part of the unified dependency graph.
If you're interested, star my project and follow my blog (where I will make any announcements about it):
I agree with you that Make's pattern matching facilities are ugly and could be improved upon. I tried something of the sort [3] with redo, and it worked well, but felt too alien.
From what I've seen at big companies with huge builds, the "dependency graph itself changed, now what do we rebuild" problem is the killer problem. I bet you've seen instances of that at Google.
You can do something like the make variant with:
: foreach *.c |> gcc -c %f -o %o |> %B.o
Edit: Note that this example is different from what Make will do. With Make you're saying "whenever you need to satisfy a * .o dependency go compile a .c". With Tup, it is "find all * .c and make .os from each of them". In fact, a complete Tupfile that just compiles all .c files it finds and links the resulting .o files is simply (copied straight from the examples): : foreach *.c |> gcc -Wall -c %f -o %o |> %B.o
: *.o |> gcc %f -o %o |> hello
Or if you want to output files named in some other way and not as basename.o, you can write a script that generates those rules and include it inline: run ./myscript.py
Or you can write a Lua script that uses the Tup Lua API to define rules.> Ninja is a small build system with a focus on speed. It differs from other build systems in two major respects: it is designed to have its input files generated by a higher-level build system, and it is designed to run builds as fast as possible.
Obligatory: https://xkcd.com/927/
Also played a bit with tup, and it's quite nice too.
Yes, I came across Ninja when searching for prior art. While it's "philosophy" essays make it sound like it is exactly what I'm looking for, when I dug in deeper I found that it was still a ways away from what I had in mind.
When you look at Ninja files, you find some of the things that I explicitly want to get rid of: variables and rules, evaluation and scoping. Their solution for C/C++ dependencies is to have special magic in the tool.
Maybe the biggest difference between Ninja and what I am envisioning is that, although pared down and low-level, Ninja is still a command-line tool implemented as a language (.ninja files). What I have in mind is an embeddable library that deals only in flat, fully-expanded lists of tasks. At its core it is much more like an API than a tool (though wrapping it in a convenient command-line tool will of course be an important use case).
Think about it this way. There are so many directions you might want to extend your build system:
1. you might want to run your jobs in a different way, for example by distributing them to a cluster of build workers.
2. you might want to run your builder as a daemon that watches the filesystem and receives notifications of changed files, instead of having to figure everything out from scratch every time.
3. You might have custom, per-language logic for calculating dynamic dependencies.
4. You might want to fingerprint your inputs and outputs and cache artifacts so that you can return cached results instead of doing redundant work (especially useful if you have a build cluster that many people share).
5. You might want to do strongly isolated and hermetic builds that run each command against a directory tree that only contains its supposed inputs.
6. you might want to closely integrate the build system with your IDE, so the IDE can show deep and up-to-date information about the progress of the build.
7. I think of Light Table-like environments as being the future of IDEs. Part of the philosophy of Light Table is that you can program your own custom editor interactions easily ("The future is specific": http://www.chris-granger.com/2012/05/21/the-future-is-specif...). Programming a specific editing mode would often involve calculating artifacts derived from your source files to show in a different editor pane (for example, the assembly corresponding to your C, or a graphical representation of your source). To do this, you want something like "make", but programmable so you can generate and remove rules on the fly.
With a Ninja-like approach, you would have to add these features to Ninja itself. But once you do this, Ninja is going to get even less small and simple.
This is why I think the way forward is to have an API-based, embeddable builder engine. The core just knows how to take fully-expanded task specifications and evaluate the dependency graph to decide what jobs need to run. Then the logic for how to run jobs, record their results, possibly return cached results etc. can be easily mixed and matched. For example:
1. I would ship with a very simple command-line tool that acts mostly like "make" or "ninja": you run it, it looks at the filesystem to decide what to do, and then does it. When the build is finished the tool exits.
2. I would likely also ship with a daemon version of the same that watches the filesystem with inotify/dnotify and automatically keeps outputs up to date when inputs change. The daemon would likely support some kind of service API that you could use to programmatically query the list of tasks and jobs, and probably also an HTTP/HTML UI.
3. Anyone who wanted to integrate with a distributed builder service could embed the library but write completely custom code for actually executing the jobs.
But here is the key thing: the Tasks that a project writes can stay the same no matter what fancy stuff gets built on top. Whether you are doing the dead-simplest local build from scratch or whether you have a long-lived daemon that distributes your build and heavily caches your artifacts, there is still a common data model for tasks and jobs, and still a common dependency-evaluating core that can be shared no matter where the library is embedded.
So, to compile a slightly complicated project, I would need Ruby for the main project, Python for a library it builds on, Haskell for another library it builds on, etc?
In theory, that's not a new problem, but I think that, by removing the common language that make provides, it will become much more common in practice.
At the extreme, it would only be natural, but disastrous, for the guys writing language X to use language X to write their make file. Result: you need to bootstrap language X through a zillion versions to port it to a new system, or mess around trying to build its parts by hand.
Whilst salt is not aiming at Make-for-DevOps it certainly is something that is in the realm of possible.
The gap between compiling a bunch of source code that becomes an executable and a bunch of source code that becomes twenty servers running fifty apps is very very small.
return ctx(
rule = 'candle.exe -nologo -out ${TGT} ${SRC} -dMySource="%s"' % dirpath,
source = ['%s.wxs' % group],
target = ['%s.wxsobj' % group]
)
It has canned dependency node generators in libraries for most popular languages: ctx.objects(source = glob.glob('src/*.cpp'), target = 'OBJS')
Here you don't specify the names of the target object files directly and instead let WAF's c++ tool figure them out. On Windows, they will be .obj, on Linux .o and maybe something else on Mac.until you get to update a codebase were all the build scripts are the worst form of perl/forth/ksh/awk scripts all written by someone who though a new script on top of the old one would be easier
def outname(f):
return f[:-1] + "o"
@file_rule("*.c", outname)
def compile(f):
#do the compiling here
Here's an example of file_rule in use: https://github.com/llimllib/Newsite/blob/master/pub.py#L27http://www.reddit.com/r/programming/comments/21i19h/a_generi...
I think the main issue with approaches like yours is that there's no way to verify correctness, so it's easy to introduce bugs.
- I'm just not a big fan of automating the configuration of a build system - you build/put yet another machine around a machine. As long as it works - ok, but as soon as you run into unexpected behavior it will become a huge time sink to debug. When you update the Makefile contents manually you take ownership over everything and you get a deeper understanding on how everything works together, right down to the command parameters sent to compiler and linker. If you don't want to do that I'd suggest switching to something like cmake - if it has to 'magic', at least have the behavior specified in a coherent manner.
Not at all sure what autoconf has to do with anything, autodeps are a completely separate problem space.
http://www.freebsd.org/cgi/man.cgi?query=make&sektion=1
which points you to this:
https://www.freebsd.org/doc/en/books/pmake/
But really, if you just hate using info(1), always remember that GNU also puts the pages on the web in HTML multichunks, HTML one big page, and PDF, so there's no reason to dodge a GNU tool just because you hate info(1).
info --subnodes "$@" 2>&1 | less
and info(1) output will look a lot like man(1) output.