github.com/zyedidia/knit@v1.1.2-0.20230901152954-f7d4e39a0e24/examples/c/README.md (about)

     1  Knitfile:
     2  
     3  ```lua
     4  local knit = require("knit")
     5  
     6  local conf = {
     7      cc = cli.cc or "gcc",
     8      debug = tobool(cli.debug) or false,
     9  }
    10  
    11  local cflags := -Wall
    12  
    13  if conf.debug then
    14      cflags := $cflags -Og -g
    15  else
    16      cflags := $cflags -O2
    17  end
    18  
    19  local src = knit.glob("*.c")
    20  local obj = knit.extrepl(src, ".c", ".o")
    21  local prog := hello
    22  
    23  return b{
    24      $ $prog: $obj
    25          $(conf.cc) $cflags $input -o $output
    26      $ %.o: %.c
    27          $(conf.cc) $cflags -c $input -o $output
    28      $ clean:VBQ:
    29          knit :all -t clean
    30  }
    31  ```
    32  
    33  Targets:
    34  
    35  * `knit hello`: builds hello.
    36  * `knit clean`: cleans build files.
    37  
    38  Configuration parameters:
    39  
    40  * `knit [target] cc=gcc`: sets the C compiler to gcc.
    41  * `knit [target] debug=1`: enables debug flags (`-Og -g`).
    42  
    43  Graph:
    44  
    45  <img alt="build graph" src="./graph.svg" width="500px"/>