Add build script and build make target

This commit is contained in:
2013-06-27 00:09:39 +02:00
parent 291071f5b9
commit 66dfe4daa9
2 changed files with 71 additions and 2 deletions

66
build.sh Executable file
View File

@@ -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"