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

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

builddir = build
cxx = g++
ar = ar
cflags = -g -Wall -Wextra -Wno-deprecated -Wno-unused-parameter -fno-rtti $
    -fno-exceptions -fvisibility=hidden -pipe '-DNINJA_PYTHON="python"' -O2 $
    -DNDEBUG
ldflags = -L$builddir

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

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 = src/inline.sh $varname < $in > $out
  description = INLINE $out
build $builddir/browse_py.h: inline src/browse.py | src/inline.sh
  varname = kBrowsePy

build $builddir/browse.o: cxx 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 src/depfile_parser.cc: re2c src/depfile_parser.in.cc
build src/lexer.cc: re2c src/lexer.in.cc

# Core source files all build into ninja library.
build $builddir/build.o: cxx src/build.cc
build $builddir/build_log.o: cxx src/build_log.cc
build $builddir/clean.o: cxx src/clean.cc
build $builddir/depfile_parser.o: cxx src/depfile_parser.cc
build $builddir/disk_interface.o: cxx src/disk_interface.cc
build $builddir/edit_distance.o: cxx src/edit_distance.cc
build $builddir/eval_env.o: cxx src/eval_env.cc
build $builddir/explain.o: cxx src/explain.cc
build $builddir/graph.o: cxx src/graph.cc
build $builddir/graphviz.o: cxx src/graphviz.cc
build $builddir/lexer.o: cxx src/lexer.cc
build $builddir/metrics.o: cxx src/metrics.cc
build $builddir/parsers.o: cxx src/parsers.cc
build $builddir/state.o: cxx src/state.cc
build $builddir/util.o: cxx src/util.cc
build $builddir/subprocess.o: cxx src/subprocess.cc
build $builddir/libninja.a: ar $builddir/browse.o $builddir/build.o $
    $builddir/build_log.o $builddir/clean.o $builddir/depfile_parser.o $
    $builddir/disk_interface.o $builddir/edit_distance.o $
    $builddir/eval_env.o $builddir/explain.o $builddir/graph.o $
    $builddir/graphviz.o $builddir/lexer.o $builddir/metrics.o $
    $builddir/parsers.o $builddir/state.o $builddir/util.o $builddir/subprocess.o

# Main executable is library plus main() function.
build $builddir/ninja.o: cxx 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 src/build_log_test.cc
build $builddir/build_test.o: cxx src/build_test.cc
build $builddir/clean_test.o: cxx src/clean_test.cc
build $builddir/depfile_parser_test.o: cxx src/depfile_parser_test.cc
build $builddir/disk_interface_test.o: cxx src/disk_interface_test.cc
build $builddir/edit_distance_test.o: cxx src/edit_distance_test.cc
build $builddir/graph_test.o: cxx src/graph_test.cc
build $builddir/lexer_test.o: cxx src/lexer_test.cc
build $builddir/parsers_test.o: cxx src/parsers_test.cc
build $builddir/state_test.o: cxx src/state_test.cc
build $builddir/subprocess_test.o: cxx src/subprocess_test.cc
build $builddir/test.o: cxx src/test.cc
build $builddir/util_test.o: cxx 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/disk_interface_test.o $builddir/edit_distance_test.o $
    $builddir/graph_test.o $builddir/lexer_test.o $builddir/parsers_test.o $
    $builddir/state_test.o $builddir/subprocess_test.o $builddir/test.o $
    $builddir/util_test.o | $builddir/libninja.a
  libs = -lninja -lgtest_main -lgtest -lpthread

# Perftest executable.
build $builddir/parser_perftest.o: cxx src/parser_perftest.cc
build parser_perftest: link $builddir/parser_perftest.o | $builddir/libninja.a
  libs = -L$builddir -lninja

# Generate a graph using the "graph" tool.
rule gendot
  command = ./ninja -t graph > $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 -a toc -o $out $in
  description = ASCIIDOC $in
build doc/manual.html: asciidoc doc/manual.asciidoc
build manual: phony || doc/manual.html

# Generate Doxygen.
rule doxygen
  command = doxygen $in
  description = DOXYGEN $in
doxygen_mainpage_generator = 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 HACKING COPYING | $
    $doxygen_mainpage_generator
build doxygen: doxygen doc/doxygen.config | $builddir/doxygen_mainpage

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

# Build only the main binary by default.
default ninja

build all: phony ninja ninja_test parser_perftest