From 48186658fd575429eb4e31d756600115976afdf9 Mon Sep 17 00:00:00 2001 From: Nathan DECHER Date: Sun, 10 May 2020 19:14:01 +0200 Subject: [PATCH] added `from`, fixes #2 --- Build.moon | 7 ++++--- README.md | 4 ++-- moonbuild.moon | 8 +++++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Build.moon b/Build.moon index 35d1c8d..c278169 100644 --- a/Build.moon +++ b/Build.moon @@ -6,11 +6,12 @@ MAIN = "#{BINARY}.moon" MAIN_LUA = patsubst MAIN, '%.moon', '%.lua' OUT_C = patsubst MAIN, '%.moon', '%.lua.c' PREFIX = env 'PREFIX', '/usr/local' +INSTALL_LOC = "#{PREFIX}/bin" default public target 'all', deps: BINARY -public target 'install', deps: 'moonbuild', in: 'moonbuild', fn: => - -install @infile, "#{PREFIX}/bin" +public target 'install', from: BINARY, out: INSTALL_LOC, fn: => + -install @infile, @outfile public target 'clean', fn: => -rm '-f', OUT_LUA @@ -24,7 +25,7 @@ public target 'info', fn: => #echo "Compiled lua:", OUT_LUA #echo "Binary:", BINARY -target BINARY, out: {BINARY, OUT_C}, in: OUT_LUA, deps: OUT_LUA, fn: => +target BINARY, out: {BINARY, OUT_C}, from: OUT_LUA, fn: => -luastatic MAIN_LUA, OUT_LUA, '-I/usr/include/lua5.3', '-llua5.3' foreach OUT_LUA, (file) -> diff --git a/README.md b/README.md index 7d127f3..f3a8e55 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,10 @@ First, you'll need a `Build.moon`, `Buildfile.moon`, `Build` or `Buildfile` in t Then, you'll need a few `target`s, and ideally a `default target` (or the default target will be `all`). `public target`s will be listed by `moonbuild -l`. To execute a command, you can use either `-cmd` or `#cmd` (the former will print it before executing it, the later won't). -### `[default] [public] target [deps: ] [in: ] [out: ] [fn: ]` +### `[default] [public] target [deps: ] [in: ] [out: ] [from: ] [fn: ]` Define a new target, and give it a list of depenancies, inputs, outputs and a function to run to build it. -`deps`, `in` and `out` can be either strings or tables. `name` must be a string and `code` must be a function, that will be given a table with the following fields: +`deps`, `in` and `out` can be either strings or tables. `from` acts like both `in` and `deps`. `name` must be a string and `code` must be a function, that will be given a table with the following fields: - `name`: the name of the target - `ins`: the table of inputs - `infile`: the first input diff --git a/moonbuild.moon b/moonbuild.moon index cded531..0bb6719 100755 --- a/moonbuild.moon +++ b/moonbuild.moon @@ -101,7 +101,13 @@ buildscope= insert targets, target.name target target: (name, params) -> - BuildObject name, (flatten params.out), (flatten params.in), (flatten params.deps), params.fn + tout=flatten params.out + tin=flatten params.in + tdeps=flatten params.deps + for f in *flatten params.from + insert tin, f + insert tdeps, f + BuildObject name, tout, tin, tdeps, params.fn buildscope[k]=fn for k, fn in pairs util setmetatable buildscope,