diff --git a/Makefile b/Makefile index f345238..82642c6 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ -test: +build: + ./build.sh + +test: build test/run.sh .SILENT: -.PHONY: test +.PHONY: build test diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..e35017b --- /dev/null +++ b/build.sh @@ -0,0 +1,66 @@ +#! /usr/bin/env bash +source "src/lib/dotify-version.sh" +source "src/lib/trim.sh" + +resolve_link() { + $(type -p greadlink readlink | head -1) $1 +} + +abs_dirname() { + local cwd="$(pwd)" + local path="$1" + + while [ -n "$path" ]; do + cd "${path%/*}" + local name="${path##*/}" + path="$(resolve_link "$name" || true)" + done + + pwd + cd "$cwd" +} + + +# +# Config +# + +source="src/bin/dotify" +target="bin/dotify" + + +# +# Setup +# + +root="$(abs_dirname "$0")" +cd "$(dirname "$root/$source")" +source="$(basename "$source")" +output="" + + +# +# Building +# + +while IFS= read line; do + if [[ "$line" == "#"* ]]; then + # Replace {{VERSION}} placeholder in comments. + line="${line/\{\{VERSION\}\}/$(dotify-version)}" + fi + + if [[ "$line" == "source \""*"\"" ]]; then + # Inject content of sourced file directly into output. + line="$(trim "$line")" + file="${line/#source \"/}" + file="${file/%\"/}" + output="${output}$(cat "$file")\n\n" + else + # Append line to output. + output="${output}${line}\n" + fi +done < "$source" + +cd "$root" +echo -e "$output" > "$target" +chmod +x "$target"