Ninja: install target

2.8k views Asked by At

I have written a build.ninja file for a C++ project I'm working on. Nothing fancy, just a bunch of C++ source files that gets compiled and linked into an executable (see below)

I would like to add an install target, that would simply copy the executable into /usr/local/games. How do I achieve that ?

cflags = -DSYZYGY -Wall -Wcast-qual -fno-exceptions -fno-rtti  -ansi -pedantic -Wno-long-long $
  -Wextra -Wshadow -DNDEBUG -O3 -DIS_64BIT -msse -DUSE_BSFQ -msse3 -mpopcnt -DUSE_POPCNT -flto
lflags = -lpthread $cflags

rule compile
  command = c++ -MMD -MT $out -MF $out.d $cflags -c $in -o $out
  description = Compiling $in
  depfile = $out.d
  deps = gcc

rule link
  command = c++ -o $out $in $lflags && strip $out
  description = Linking $out

build src/benchmark.o: compile src/benchmark.cpp
build src/bitbase.o: compile src/bitbase.cpp
build src/bitboard.o: compile src/bitboard.cpp
build src/endgame.o: compile src/endgame.cpp
build src/evaluate.o: compile src/evaluate.cpp
build src/main.o: compile src/main.cpp
build src/material.o: compile src/material.cpp
build src/misc.o: compile src/misc.cpp
build src/movegen.o: compile src/movegen.cpp
build src/movepick.o: compile src/movepick.cpp
build src/pawns.o: compile src/pawns.cpp
build src/position.o: compile src/position.cpp
build src/search.o: compile src/search.cpp
build src/thread.o: compile src/thread.cpp
build src/timeman.o: compile src/timeman.cpp
build src/tt.o: compile src/tt.cpp
build src/uci.o: compile src/uci.cpp
build src/ucioption.o: compile src/ucioption.cpp
build src/syzygy/tbprobe.o: compile src/syzygy/tbprobe.cpp

build stockfish: link src/benchmark.o src/bitbase.o src/bitboard.o src/endgame.o src/evaluate.o $
  src/main.o src/material.o src/misc.o src/movegen.o src/movepick.o src/pawns.o src/position.o $
  src/search.o src/thread.o src/timeman.o src/tt.o src/uci.o src/ucioption.o src/syzygy/tbprobe.o

default stockfish
1

There are 1 answers

0
thakis On

Maybe this could do the trick (untested):

rule copy
  command = cp $in $out
build /usr/local/games/stockfish: copy stockfish
build install: phony /usr/local/games/stockfish