当前位置: 首页 > 工具软件 > makefile2dot > 使用案例 >

使用makefile编译ninja

苏季同
2023-12-01

makefile

.PHONY : ninja
root := .
builddir := build
cxx := g++
ar := ar
cflags := -std=c++11 -g -Wall -Wextra -Wno-deprecated -Wno-missing-field-initializers \
    -Wno-unused-parameter -fno-rtti -fno-exceptions -fvisibility=hidden \
    -pipe '-DNINJA_PYTHON="python"' -O2 -DNDEBUG -fdiagnostics-color \
    -DUSE_PPOLL -DNINJA_HAVE_BROWSE -I.
ldflags := -L$(builddir) -pthread
CXX := ${cxx} -MMD -MT 
end = ${cflags} -c $^ -o $@


ninja: ${builddir}/ninja.o ${builddir}/libninja.a
    ${cxx} ${ldflags} -o ninja ${builddir}/ninja.o -lninja
    rm ${builddir}/*.d

${builddir}/ninja.o: $(root)/src/ninja.cc
    ${CXX} ${builddir}/ninja.o -MF ${builddir}/ninja.o.d ${cflags} -c $(root)/src/ninja.cc -o ${builddir}/ninja.o


$(builddir)/browse_py.h: $(root)/src/browse.py $(root)/src/inline.sh
    "${root}/src/inline.sh" kBrowsePy <$(root)/src/browse.py> $(builddir)/browse_py.h

objects=$(builddir)/browse.o $(builddir)/build.o \
    $(builddir)/build_log.o $(builddir)/clean.o $(builddir)/clparser.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)/string_piece_util.o \
    $(builddir)/util.o $(builddir)/version.o $(builddir)/subprocess-posix.o \
    ${builddir}/dyndep.o ${builddir}/dyndep_parser.o ${builddir}/manifest_chunk_parser.o  \
    ${builddir}/parser.o ${builddir}/proto.o ${builddir}/status.o ${builddir}/thread_pool.o

$(builddir)/graph.o: ${root}/src/graph.cc
    ${CXX} $(builddir)/graph.o -MF $(builddir)/graph.o.d ${cflags} -c $^ -o $@

$(builddir)/eval_env.o: ${root}/src/eval_env.cc
    ${CXX} $(builddir)/eval_env.o -MF $(builddir)/eval_env.o.d ${cflags} -c $^ -o $@

$(builddir)/browse.o: ${root}/src/browse.cc $(builddir)/browse_py.h
    ${CXX} ${builddir}/browse.o -MF ${builddir}/browse.o.d ${cflags} -c ${root}/src/browse.cc -o $(builddir)/browse.o

$(builddir)/build.o:  ${root}/src/build.cc
    ${CXX} ${builddir}/build.o -MF ${builddir}/build.o.d ${cflags} -c $^ -o $@

$(builddir)/build_log.o:  ${root}/src/build_log.cc
    ${CXX} ${builddir}/build_log.o -MF ${builddir}/build_log.o.d ${cflags} -c $^ -o $@

$(builddir)/clean.o:  ${root}/src/clean.cc
    ${CXX} ${builddir}/clean.o -MF ${builddir}/clean.o.d ${cflags} -c $^ -o $@

$(builddir)/clparser.o:  ${root}/src/clparser.cc
    ${CXX} ${builddir}/clparser.o -MF ${builddir}/clparser.o.d ${cflags} -c $^ -o $@

$(builddir)/debug_flags.o:  ${root}/src/debug_flags.cc
    ${CXX} ${builddir}/debug_flags.o -MF ${builddir}/debug_flags.o.d ${cflags} -c $^ -o $@

$(builddir)/depfile_parser.o:  ${root}/src/depfile_parser.cc
    ${CXX} ${builddir}/depfile_parser.o -MF ${builddir}/depfile_parser.o.d ${cflags} -c $^ -o $@
    
$(builddir)/deps_log.o:  ${root}/src/deps_log.cc
    ${CXX} ${builddir}/deps_log.o -MF ${builddir}/deps_log.o.d ${cflags} -c $^ -o $@
    
$(builddir)/disk_interface.o:  ${root}/src/disk_interface.cc
    ${CXX} ${builddir}/disk_interface.o -MF ${builddir}/disk_interface.o.d ${cflags} -c $^ -o $@
    
$(builddir)/edit_distance.o:  ${root}/src/edit_distance.cc
    ${CXX} ${builddir}/edit_distance.o -MF ${builddir}/edit_distance.o.d ${cflags} -c $^ -o $@

$(builddir)/graphviz.o:  ${root}/src/graphviz.cc
    ${CXX} ${builddir}/graphviz.o -MF ${builddir}/graphviz.o.d ${cflags} -c $^ -o $@
    
$(builddir)/lexer.o:  ${root}/src/lexer.cc
    ${CXX} ${builddir}/lexer.o -MF ${builddir}/lexer.o.d ${cflags} -c $^ -o $@
    
$(builddir)/line_printer.o: ${root}/src/line_printer.cc
    ${CXX} ${builddir}/line_printer.o -MF ${builddir}/line_printer.o.d ${cflags} -c $^ -o $@

$(builddir)/manifest_parser.o: ${root}/src/manifest_parser.cc
    ${CXX} ${builddir}/manifest_parser.o -MF ${builddir}/manifest_parser.o.d ${cflags} -c $^ -o $@
    
$(builddir)/metrics.o: ${root}/src/metrics.cc
    ${CXX} ${builddir}/metrics.o -MF ${builddir}/metrics.o.d ${cflags} -c $^ -o $@
    
$(builddir)/state.o: ${root}/src/state.cc
    ${CXX} ${builddir}/state.o -MF ${builddir}/state.o.d ${cflags} ${cflags} -c $^ -o $@
    
$(builddir)/string_piece_util.o: ${root}/src/string_piece_util.cc
    ${CXX} ${builddir}/string_piece_util.o -MF ${builddir}/string_piece_util.o.d ${cflags} -c $^ -o $@
    
$(builddir)/util.o: ${root}/src/util.cc
    ${CXX} ${builddir}/util.o -MF ${builddir}/util.o.d ${cflags} -c ${root}/src/util.cc -o $(builddir)/util.o
    
$(builddir)/version.o: ${root}/src/version.cc
    ${CXX} ${builddir}/version.o -MF ${builddir}/version.o.d ${cflags} -c ${root}/src/version.cc -o $(builddir)/version.o
    
$(builddir)/subprocess-posix.o: ${root}/src/subprocess-posix.cc
    ${CXX} ${builddir}/subprocess-posix.o -MF ${builddir}/subprocess-posix.o.d ${cflags} -c ${root}/src/subprocess-posix.cc -o $(builddir)/subprocess-posix.o

${builddir}/dyndep.o: ${root}/src/dyndep.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/dyndep.cc -o $@

${builddir}/dyndep_parser.o: ${root}/src/dyndep_parser.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/dyndep_parser.cc -o $@

${builddir}/manifest_chunk_parser.o: ${root}/src/manifest_chunk_parser.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/manifest_chunk_parser.cc -o $@

${builddir}/parser.o: ${root}/src/parser.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c $^ -o $@

${builddir}/proto.o: ${root}/src/proto.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/proto.cc -o $@

${builddir}/status.o: ${root}/src/status.cc  
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/status.cc -o $@

${builddir}/thread_pool.o : ${root}/src/thread_pool.cc 
    ${CXX} $@ -MF $@.d ${cflags} -c ${root}/src/thread_pool.cc -o $@
${builddir}/libninja.a: ${objects}
    ${ar} crs ${builddir}/libninja.a ${objects}

.PHONY : clean 
clean :
    rm ${builddir}/*

build.ninja

# 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 = -std=c++11 -g -Wall -Wextra -Wno-deprecated $
    -Wno-missing-field-initializers -Wno-unused-parameter -fno-rtti $
    -fno-exceptions -fvisibility=hidden -pipe '-DNINJA_PYTHON="python3"' $
    -O2 -DNDEBUG -fdiagnostics-color -pthread -DUSE_PPOLL $
    -DNINJA_HAVE_BROWSE -I.
ldflags = -L$builddir -pthread

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.

# the proto descriptor is generated using protoc.

# Core source files all build into ninja library.
build $builddir/build.o: cxx $root/src/build.cc || $root/src/frontend.pb.h
build $builddir/build_log.o: cxx $root/src/build_log.cc || $
    $root/src/frontend.pb.h
build $builddir/clean.o: cxx $root/src/clean.cc || $root/src/frontend.pb.h
build $builddir/clparser.o: cxx $root/src/clparser.cc || $
    $root/src/frontend.pb.h
build $builddir/debug_flags.o: cxx $root/src/debug_flags.cc || $
    $root/src/frontend.pb.h
build $builddir/depfile_parser.o: cxx $root/src/depfile_parser.cc || $
    $root/src/frontend.pb.h
build $builddir/deps_log.o: cxx $root/src/deps_log.cc || $
    $root/src/frontend.pb.h
build $builddir/disk_interface.o: cxx $root/src/disk_interface.cc || $
    $root/src/frontend.pb.h
build $builddir/dyndep.o: cxx $root/src/dyndep.cc || $root/src/frontend.pb.h
build $builddir/dyndep_parser.o: cxx $root/src/dyndep_parser.cc || $
    $root/src/frontend.pb.h
build $builddir/edit_distance.o: cxx $root/src/edit_distance.cc || $
    $root/src/frontend.pb.h
build $builddir/eval_env.o: cxx $root/src/eval_env.cc || $
    $root/src/frontend.pb.h
build $builddir/graph.o: cxx $root/src/graph.cc || $root/src/frontend.pb.h
build $builddir/graphviz.o: cxx $root/src/graphviz.cc || $
    $root/src/frontend.pb.h
build $builddir/lexer.o: cxx $root/src/lexer.cc || $root/src/frontend.pb.h
build $builddir/line_printer.o: cxx $root/src/line_printer.cc || $
    $root/src/frontend.pb.h
build $builddir/manifest_chunk_parser.o: cxx $
    $root/src/manifest_chunk_parser.cc || $root/src/frontend.pb.h
build $builddir/manifest_parser.o: cxx $root/src/manifest_parser.cc || $
    $root/src/frontend.pb.h
build $builddir/metrics.o: cxx $root/src/metrics.cc || $root/src/frontend.pb.h
build $builddir/parser.o: cxx $root/src/parser.cc || $root/src/frontend.pb.h
build $builddir/proto.o: cxx $root/src/proto.cc || $root/src/frontend.pb.h
build $builddir/state.o: cxx $root/src/state.cc || $root/src/frontend.pb.h
build $builddir/status.o: cxx $root/src/status.cc || $root/src/frontend.pb.h
build $builddir/string_piece_util.o: cxx $root/src/string_piece_util.cc || $
    $root/src/frontend.pb.h
build $builddir/thread_pool.o: cxx $root/src/thread_pool.cc || $
    $root/src/frontend.pb.h
build $builddir/util.o: cxx $root/src/util.cc || $root/src/frontend.pb.h
build $builddir/version.o: cxx $root/src/version.cc || $root/src/frontend.pb.h
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/clparser.o $
    $builddir/debug_flags.o $builddir/depfile_parser.o $builddir/deps_log.o $
    $builddir/disk_interface.o $builddir/dyndep.o $builddir/dyndep_parser.o $
    $builddir/edit_distance.o $builddir/eval_env.o $builddir/graph.o $
    $builddir/graphviz.o $builddir/lexer.o $builddir/line_printer.o $
    $builddir/manifest_chunk_parser.o $builddir/manifest_parser.o $
    $builddir/metrics.o $builddir/parser.o $builddir/proto.o $
    $builddir/state.o $builddir/status.o $builddir/string_piece_util.o $
    $builddir/thread_pool.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/clparser_test.o: cxx $root/src/clparser_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/dyndep_parser_test.o: cxx $root/src/dyndep_parser_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/status_test.o: cxx $root/src/status_test.cc
build $builddir/string_piece_util_test.o: cxx $
    $root/src/string_piece_util_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/clparser_test.o $
    $builddir/depfile_parser_test.o $builddir/deps_log_test.o $
    $builddir/dyndep_parser_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/status_test.o $
    $builddir/string_piece_util_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
build $builddir/clparser_perftest.o: cxx $root/src/clparser_perftest.cc
build clparser_perftest: link $builddir/clparser_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}python3 $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 $
    clparser_perftest

 类似资料: