# This file is used to build ninja itself.
# It is generated by configure.py.

ninja_required_version = 1.3

# The arguments passed to configure.py, for rerunning it.
configure_args = 

root = .
builddir = build
cxx = g++
ar = ar
cflags = -g -Wall -Wextra -Wno-deprecated -Wno-missing-field-initializers $
    -Wno-unused-parameter -fno-rtti -fno-exceptions -fvisibility=hidden $
    -pipe '-DNINJA_PYTHON="python"' -O2 -DNDEBUG -DUSE_PPOLL $
    -DNINJA_HAVE_BROWSE -I.
ldflags = -L$builddir

rule cxx
  command = $cxx -MMD -MT $out -MF $out.d $cflags -c $in -o $out
  description = CXX $out
  depfile = $out.d
  deps = gcc

rule ar
  command = rm -f $out && $ar crs $out $in
  description = AR $out

rule link
  command = $cxx $ldflags -o $out $in $libs
  description = LINK $out

# browse_py.h is used to inline browse.py.
rule inline
  command = "$root/src/inline.sh" $varname < $in > $out
  description = INLINE $out
build $builddir/browse_py.h: inline $root/src/browse.py | $root/src/inline.sh
  varname = kBrowsePy

build $builddir/browse.o: cxx $root/src/browse.cc || $builddir/browse_py.h

# the depfile parser and ninja lexers are generated using re2c.
rule re2c
  command = re2c -b -i --no-generation-date -o $out $in
  description = RE2C $out
build $root/src/depfile_parser.cc: re2c $root/src/depfile_parser.in.cc
build $root/src/lexer.cc: re2c $root/src/lexer.in.cc

# Core source files all build into ninja library.
build $builddir/build.o: cxx $root/src/build.cc
build $builddir/build_log.o: cxx $root/src/build_log.cc
build $builddir/clean.o: cxx $root/src/clean.cc
build $builddir/debug_flags.o: cxx $root/src/debug_flags.cc
build $builddir/depfile_parser.o: cxx $root/src/depfile_parser.cc
build $builddir/deps_log.o: cxx $root/src/deps_log.cc
build $builddir/disk_interface.o: cxx $root/src/disk_interface.cc
build $builddir/edit_distance.o: cxx $root/src/edit_distance.cc
build $builddir/eval_env.o: cxx $root/src/eval_env.cc
build $builddir/graph.o: cxx $root/src/graph.cc
build $builddir/graphviz.o: cxx $root/src/graphviz.cc
build $builddir/lexer.o: cxx $root/src/lexer.cc
build $builddir/line_printer.o: cxx $root/src/line_printer.cc
build $builddir/manifest_parser.o: cxx $root/src/manifest_parser.cc
build $builddir/metrics.o: cxx $root/src/metrics.cc
build $builddir/state.o: cxx $root/src/state.cc
build $builddir/util.o: cxx $root/src/util.cc
build $builddir/version.o: cxx $root/src/version.cc
build $builddir/subprocess-posix.o: cxx $root/src/subprocess-posix.cc
build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $
    $builddir/build_log.o $builddir/clean.o $builddir/debug_flags.o $
    $builddir/depfile_parser.o $builddir/deps_log.o $
    $builddir/disk_interface.o $builddir/edit_distance.o $
    $builddir/eval_env.o $builddir/graph.o $builddir/graphviz.o $
    $builddir/lexer.o $builddir/line_printer.o $builddir/manifest_parser.o $
    $builddir/metrics.o $builddir/state.o $builddir/util.o $
    $builddir/version.o $builddir/subprocess-posix.o

# Main executable is library plus main() function.
build $builddir/ninja.o: cxx $root/src/ninja.cc
build ninja: link $builddir/ninja.o | $builddir/libninja.a
  libs = -lninja

# Tests all build into ninja_test executable.
build $builddir/build_log_test.o: cxx $root/src/build_log_test.cc
build $builddir/build_test.o: cxx $root/src/build_test.cc
build $builddir/clean_test.o: cxx $root/src/clean_test.cc
build $builddir/depfile_parser_test.o: cxx $root/src/depfile_parser_test.cc
build $builddir/deps_log_test.o: cxx $root/src/deps_log_test.cc
build $builddir/disk_interface_test.o: cxx $root/src/disk_interface_test.cc
build $builddir/edit_distance_test.o: cxx $root/src/edit_distance_test.cc
build $builddir/graph_test.o: cxx $root/src/graph_test.cc
build $builddir/lexer_test.o: cxx $root/src/lexer_test.cc
build $builddir/manifest_parser_test.o: cxx $root/src/manifest_parser_test.cc
build $builddir/ninja_test.o: cxx $root/src/ninja_test.cc
build $builddir/state_test.o: cxx $root/src/state_test.cc
build $builddir/subprocess_test.o: cxx $root/src/subprocess_test.cc
build $builddir/test.o: cxx $root/src/test.cc
build $builddir/util_test.o: cxx $root/src/util_test.cc
build ninja_test: link $builddir/build_log_test.o $builddir/build_test.o $
    $builddir/clean_test.o $builddir/depfile_parser_test.o $
    $builddir/deps_log_test.o $builddir/disk_interface_test.o $
    $builddir/edit_distance_test.o $builddir/graph_test.o $
    $builddir/lexer_test.o $builddir/manifest_parser_test.o $
    $builddir/ninja_test.o $builddir/state_test.o $
    $builddir/subprocess_test.o $builddir/test.o $builddir/util_test.o | $
    $builddir/libninja.a
  libs = -lninja

# Ancillary executables.
build $builddir/build_log_perftest.o: cxx $root/src/build_log_perftest.cc
build build_log_perftest: link $builddir/build_log_perftest.o | $
    $builddir/libninja.a
  libs = -lninja
build $builddir/canon_perftest.o: cxx $root/src/canon_perftest.cc
build canon_perftest: link $builddir/canon_perftest.o | $builddir/libninja.a
  libs = -lninja
build $builddir/depfile_parser_perftest.o: cxx $
    $root/src/depfile_parser_perftest.cc
build depfile_parser_perftest: link $builddir/depfile_parser_perftest.o | $
    $builddir/libninja.a
  libs = -lninja
build $builddir/hash_collision_bench.o: cxx $root/src/hash_collision_bench.cc
build hash_collision_bench: link $builddir/hash_collision_bench.o | $
    $builddir/libninja.a
  libs = -lninja
build $builddir/manifest_parser_perftest.o: cxx $
    $root/src/manifest_parser_perftest.cc
build manifest_parser_perftest: link $builddir/manifest_parser_perftest.o | $
    $builddir/libninja.a
  libs = -lninja

# Generate a graph using the "graph" tool.
rule gendot
  command = ./ninja -t graph all > $out
rule gengraph
  command = dot -Tpng $in > $out
build $builddir/graph.dot: gendot ninja build.ninja
build graph.png: gengraph $builddir/graph.dot

# Generate the manual using asciidoc.
rule asciidoc
  command = asciidoc -b docbook -d book -o $out $in
  description = ASCIIDOC $out
rule xsltproc
  command = xsltproc --nonet doc/docbook.xsl $in > $out
  description = XSLTPROC $out
build $builddir/manual.xml: asciidoc $root/doc/manual.asciidoc
build $root/doc/manual.html: xsltproc $builddir/manual.xml | $
    $root/doc/style.css $root/doc/docbook.xsl
build manual: phony || $root/doc/manual.html

rule dblatex
  command = dblatex -q -o $out -p doc/dblatex.xsl $in
  description = DBLATEX $out
build $root/doc/manual.pdf: dblatex $builddir/manual.xml | $
    $root/doc/dblatex.xsl
# Generate Doxygen.
rule doxygen
  command = doxygen $in
  description = DOXYGEN $in
doxygen_mainpage_generator = $root/src/gen_doxygen_mainpage.sh
rule doxygen_mainpage
  command = $doxygen_mainpage_generator $in > $out
  description = DOXYGEN_MAINPAGE $out
build $builddir/doxygen_mainpage: doxygen_mainpage README COPYING | $
    $doxygen_mainpage_generator
build doxygen: doxygen $root/doc/doxygen.config | $builddir/doxygen_mainpage

# Regenerate build files if build script changes.
rule configure
  command = ${configure_env}python $root/configure.py $configure_args
  generator = 1
build build.ninja: configure | $root/configure.py $root/misc/ninja_syntax.py

default ninja

# Packaging
rule rpmbuild
  command = misc/packaging/rpmbuild.sh
  description = Building rpms..
build rpm: rpmbuild

build all: phony ninja ninja_test build_log_perftest canon_perftest $
    depfile_parser_perftest hash_collision_bench manifest_parser_perftest