summaryrefslogtreecommitdiffstats
path: root/build.ninja
blob: bb635918599039ec59c7cc15fa30c330c0ec98f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# This file is used to build ninja itself, but it also serves as a
# documented example.

# The special variable "builddir" can be referenced later via the short
# name "@".  The mnemonic comes from executables having an "@" prefix
# in ls -F output.
builddir = build

# Most other variables, like cflags, aren't magic at all; it's up to
# the rules to make use of them.
cxx = g++
#cxx = /home/evanm/projects/src/llvm/Release+Asserts/bin/clang++
cflags = -g -Wall

# Here we declare a "rule" named "cxx", which knows how to compile
# C++ code.  The variables indented below the rule are scoped to the
# rule itself.  The "command" and "depfile" variables in rule scope
# are special; see the documentation.
rule cxx
  depfile = $out.d
  command = $cxx -MMD -MF $out.d $cflags -c $in -o $out

rule ar
  command = ar crsT $out $in

rule link
  command = $cxx $ldflags -o $out $in

# These build rules build the ".o" files from the ".cc" files,
# build "ninja.a" by linking the builddir's "ninja.o",
# and build that "ninja.o" by compiling "ninja.cc".
build @build.o: cxx build.cc
build @parsers.o: cxx parsers.cc
build @ninja_jumble.o: cxx ninja_jumble.cc
build @ninja.a: ar @build.o @parsers.o @ninja_jumble.o

build @ninja.o: cxx ninja.cc
build ninja: link @ninja.o @ninja.a

build @ninja_test.o: cxx ninja_test.cc
build @parsers_test.o: cxx parsers_test.cc
build ninja_test: link @ninja_test.o @parsers_test.o @ninja.a
  ldflags = -lgtest -lgtest_main -lpthread


# Generate a graph of the dependency tree (including the
# graph generation itself in the resulting tree).
graph_targets = ninja ninja_test graph.png
rule gendot
  command = ./ninja -g $graph_targets > $out
rule gengraph
  command = dot -Tpng $in > $out

build @graph.dot: gendot ninja build.ninja
build graph.png: gengraph @graph.dot

# Use the built-in phony rule and an order-only dependency
# to make building "all" build all targets.
build all: phony | ninja ninja_test graph.png