28 September 2017

why

build a system evolution

manual » script » makefile » auto-make » gn

  • adv: quick, small, tree-structure(makefile has)
  • disadv: it need all headers/libraries/source in side a package auto-make are created to use some uitiles to generate a makefile

reference: https://blog.simplypatrick.com/posts/2016/01-23-gn/

  • 由於 GN 是用 C++ 撰寫,比起用 Python 寫的 GYP 快了將近 20 倍,GN 新的 DSL 的語法也被認為是比較好讀及維護的。

Usage

Use Steps

  • configure some args
  • Use gn to generate a build.ninja a inside ‘out’ folder
  • Use ninja to read build.ninja and do its work!
>mkdir out
>copy gn.args to out

>gn gen out
>ninja -C out

download ninja

https://github.com/ninja-build/ninja/releases

tutorial (https://ninja-build.org/manual.html#ref_rule)[https://ninja-build.org/manual.html#ref_rule]

download gn

gn is a tool to help build chrome browse in windows it is a part of source code inside chrome use git’s sha1 hash-value to download the file

cheat sheet

gn ls out
; see all the taregets
gn check out
; check target dependences
gn desc out <target>
; descript the detail of target
gn refs out <target>
; list parent-targets that refs to target
gn path out <target1> <target2>
; show all paths from target1 to targets

tutorial https://chromium.googlesource.com/chromium/src/+/lkgr/tools/gn/docs/quick_start.md

gn download tool https://github.com/cpu-chromium/gn_tool

download code

  with open(gn_path, 'wb') as f:
    f.write(urllib2.urlopen('https://chromium-gn.storage-download.googleapis.com/' + sha1).read())

gn help

J:\git_home\temp\fluoride_src\fluoride\bt>gn help

Commands (type "gn help <command>" for more help):
  analyze: Analyze which targets are affected by a list of files.
  args: Display or configure arguments declared by the build.
  check: Check header dependencies.
  clean: Cleans the output directory.
  desc: Show lots of insightful information about a target or config.
  format: Format .gn file.
  gen: Generate ninja files.
  help: Does what you think.
  ls: List matching targets.
  path: Find paths between two targets.
  refs: Find stuff referencing a target or file.

file format

gn use

  • variables: use ‘=’ to assign
  • rules: use a block (indent with spaces) to define
ninja_required_version = 1.3

#variable

cc = g++
cflags = -Wall

# rule
rule cc
    command = gcc $cflags -c $in -o $out
rule link
    command = gcc $cflags $in -o $out
build foo.o: cc foo.c
build 
build .exe: link foo.c

another example by me

  • use germ.c => germ.lib
  • use foo.c => foo.o
  • use foo.o + germ.lib => foo.exe
ninja_required_version = 1.3

#variable

cc = g++

cflags = -Wall

# rule

rule cc
    command = gcc $cflags -c $in -o $out
rule ar
    command = ar rcs $out $in
rule link
    command = gcc $in -o $out -lgerm -L.
#build foo.o: cc foo.c


build germ.o: cc germ.c
build foo.o: cc foo.c
build germ.lib: ar germ.o
build foo.exe: link foo.o




blog comments powered by Disqus