I2I3WERCRM7KAHR477JRZSN5XNXUIAWMDFQK25LV6L7VDZJTTANQC
#!/bin/bash
BUILD_TYPE=Debug
cat << EndOfString
builddir = build
include_directories = -Itabula/include -Ialias/include -I\$builddir/include
dev_cflags =
dev_ldflags = -L\$builddir/dev-lib
dev_cc = gcc
rule copy
command = cp \$in \$out
rule re2c
command = re2c \$flags -o \$out \$in
rule gen_geometric_algebra
command = \$builddir/alias-gen-geometric_algebra \$flags > \$out
rule ar
command = rm -f \$out && ar crs \$out \$in
rule lemon
command = \$builddir/lemon \$in \$out
EndOfString
declare -A rule_implicit_dependencies
declare -A lib_cflags
declare -A lib_ldflags
rule_implicit_dependencies["gen_geometric_algebra"]="\$builddir/alias-gen-geometric_algebra"
rule_implicit_dependencies["lemon"]="\$builddir/lemon"
getcflags() {
local pkg=$1
shift
flags=${lib_cflags[$pkg]}
if [[ -z "$flags" ]]; then
flags=$(pkg-config --cflags "$pkg")
lib_cflags[$pkg]="$flags"
fi
echo $flags
}
getldflags() {
local pkg=$1
shift
flags=${lib_ldflags[$pkg]}
if [[ -z "$flags" ]]; then
flags=$(pkg-config --libs $pkg)
lib_ldflags[$pkg]="$flags"
fi
echo $flags
}
compile_rules() {
local platform=$1
shift
local name=$1
shift
local cflags=
local ldflags=
local implicit_dependencies=
while (( "$#" )); do
if [[ $1 = -C* ]]; then
cflags="$cflags ${1:2}"
elif [[ $1 = -L* ]]; then
ldflags="$ldflags ${1:2}"
elif [[ $1 = -D* ]]; then
implicit_dependencies="$implicit_dependencies ${1:2}"
else
add_cflags=$(getcflags $1)
add_ldflags=$(getldflags $1)
cflags="$cflags $add_cflags"
ldflags="$ldflags $add_ldflags"
fi
shift
done
cflags=$(echo $cflags | uniq)
ldfalgs=$(echo $cflags | uniq)
rule_implicit_dependencies[$(echo $name)_c]=$implicit_dependencies
cat << EndOfString
rule $(echo $name)_c
depfile = \$out.d
command = \$$(echo $platform)_cc -MD -MF \$out.d \$include_directories \$$(echo $platform)_cflags $cflags -c \$in -o \$out
deps = gcc
rule $(echo $name)_link
command = \$$(echo $platform)_cc \$$(echo $platform)_cflags $(echo $cflags) \$$(echo $platform)_ldflags $ldflags \$in -o \$out
EndOfString
}
compile_rules dev gen
compile_rules dev dev_alias \
"-C-Ialias/ext/shishua" \
"-D\$builddir/include/alias/pga2d.h" \
"-D\$builddir/include/alias/pga3d.h" \
"-D\$builddir/include/alias/cga2d.h" \
"-D\$builddir/include/alias/cga3d.h"
build() {
local dst=$1
shift
local rule=$1
shift
local src=$1
shift
local implicit_dependencies=${rule_implicit_dependencies[$rule]}
local flags=
while (( "$#" )); do
if [[ "$1" = -- ]]; then
shift
flags=$@
break
else
implicit_dependencies="$implicit_dependencies $1"
fi
shift
done
source ./configure-lib.sh
while (( "$#" )); do
object=\$builddir/$rules-$(echo $1 | sed "s/\//-/g" | sed "s/\.c$/.o/")
objects="$objects $object"
build $object $rules_c $1
shift
done
rule gen_geometric_algebra --implicit \$builddir/alias-gen_geometric_algebra --command "\$builddir/alias-gen_geometric_algebra \$flags > \$out"
build "\$builddir/$name" $rules_link "$objects"
}
build "\$builddir/include/alias/pga2d.h" gen_geometric_algebra "" --flags "-p 2 -d 1 --binary meet outer_product --binary join regressive_product --code m02"
build "\$builddir/include/alias/pga3d.h" gen_geometric_algebra "" --flags "-p 3 -d 1 --binary meet outer_product --binary join regressive_product --code m024"
build "\$builddir/include/alias/cga2d.h" gen_geometric_algebra "" --flags "-p 3 -n 1 --binary meet outer_product --binary join regressive_product"
build "\$builddir/include/alias/cga3d.h" gen_geometric_algebra "" --flags "-p 4 -n 1 --binary meet outer_product --binary join regressive_product"
static_library() {
local rules=$1
local rules_c=$(echo $rules)_c
shift
phony geometric_algebra_headers \
--include-directory "\$builddir/include" \
"\$builddir/include/alias/pga2d.h" \
"\$builddir/include/alias/pga3d.h" \
"\$builddir/include/alias/cga2d.h" \
"\$builddir/include/alias/cga3d.h"
local out=$1
shift
local objects=
while (( "$#" )); do
object=\$builddir/$rules-$(echo $1 | sed "s/\//-/g" | sed "s/\.c$/.o/")
objects="$objects $object"
build $object $rules_c $1
shift
done
build \$builddir/$out ar "$objects"
}
executable gen alias-gen-geometric_algebra alias/gen/geometric_algebra.c
build "\$builddir/include/alias/pga2d.h" gen_geometric_algebra "" -- -p 2 -d 1 --binary meet outer_product --binary join regressive_product --code m02
build "\$builddir/include/alias/pga3d.h" gen_geometric_algebra "" -- -p 3 -d 1 --binary meet outer_product --binary join regressive_product --code m024
build "\$builddir/include/alias/cga2d.h" gen_geometric_algebra "" -- -p 3 -n 1 --binary meet outer_product --binary join regressive_product
build "\$builddir/include/alias/cga3d.h" gen_geometric_algebra "" -- -p 4 -n 1 --binary meet outer_product --binary join regressive_product
static_library dev_alias dev-lib/libalias.a \
library lnx-alias \
--include-directory alias/include \
tabula \
geometric_algebra_headers \
compile_rules dev dev libuv \
"-D\$builddir/dev-lib/libalias.a" \
"-L-lalias"
library lnx-engine \
lnx-libuv lnx-glfw3 lnx-alias \
--include-directory engine/include \
engine/src/engine.c
executable lnx-engine-integration_test \
lnx-engine engine/integration_test/src/main.c
# SQLITE
cat << EndOfString
rule sqlite_configure
command = mkdir -p \$builddir/sqlite && cd \$builddir/sqlite && ../../engine/ext/sqlite/configure 1>/dev/null
generator = 1
description = sqlite::configure
rule sqlite3_amalgamation
command = cd \$builddir/sqlite && make sqlite3.c 1>/dev/null
description = sqlite::make sqlite3.c
build \$builddir/sqlite/Makefile: sqlite_configure
build \$builddir/sqlite/sqlite3.c | \$builddir/sqlite/sqlite3.h \$builddir/sqlite/lemon: sqlite3_amalgamation | \$builddir/sqlite/Makefile
build \$builddir/include/sqlite3.h: copy \$builddir/sqlite/sqlite3.h
build \$builddir/lemon: copy \$builddir/sqlite/lemon
EndOfString
rule gen_build_graph --command "ninja -t graph | dot -Tpng -o \$out" --implicit build.ninja
build build.ninja.png gen_build_graph
# NINJA BUILD and GRAPHS!
cat << EndOfString
rule configure
command = ./configure.sh > build.ninja
generator = 1
build build.ninja: configure | configure.sh
rule gen_build_graph
command = ninja -t graph | dot -Tpng -o \$out
build build.ninja.png: gen_build_graph | build.ninja
EndOfString
#!/bin/bash
variable() {
local name=$1
shift
echo "$name = $*"
}
declare -A rule_implicit_dependencies
rule() {
local name=$1
shift
local command=
local deps=
local depfile=
local implicit_dependencies=
local generator=
while (( "$#" )); do
local arg=$1
shift
if [[ $arg = --command ]]; then
command=$1
shift
elif [[ $arg = --generator ]]; then
generator=1
elif [[ $arg = --implicit ]]; then
implicit_dependencies="$implicit_dependencies $1"
shift
elif [[ $arg = --deps ]]; then
deps="$1"
shift
elif [[ $arg = --depfile ]]; then
depfile="$1"
shift
fi
done
rule_implicit_dependencies[$name]=$implicit_dependencies
echo "rule $name"
if [[ ! -z $command ]]; then
echo " command = $command"
fi
if [[ ! -z $deps ]]; then
echo " deps = $deps"
fi
if [[ ! -z $depfile ]]; then
echo " depfile = $depfile"
fi
if [[ ! -z $generator ]]; then
echo " generator = 1"
fi
}
build() {
local output=$1
shift
local _rule=$1
shift
local inputs=
local implicit_dependencies=${rule_implicit_dependencies[$_rule]}
local flags=
while (( "$#" )); do
local arg=$1
shift
if [[ $arg = --implicit ]]; then
implicit_dependencies="$implicit_dependencies $1"
shift
elif [[ $arg = --flags ]]; then
flags=$1
shift
else
inputs="$inputs $arg"
fi
done
implicit_dependencies=$(echo $implicit_dependencies | uniq)
if [[ ! -z "$implicit_dependencies" ]]; then
implicit_dependencies="| $implicit_dependencies"
fi
echo "build $output : $_rule $inputs $implicit_dependencies"
if [[ ! -z "$flags" ]]; then
echo " flags = $flags"
fi
}
PKG_CONFIG_lnx=pkg-config
CC_lnx=gcc
LINK_lnx=gcc
EXE_lnx=
CFLAGS_lnx=
LFLAGS_lnx=
AR_lnx=ar
PKG_CONFIG_win=x86_64-w64-ming32-pkg-config
CC_win=x86_64-w64-mingw32-gcc
LINK_win=x86_64-w64-mingw32-gcc
EXE_win=".exe"
CFLAGS_win=
LFLAGS_win=
AR_win=ar
declare -A target_defined target_include_directories target_defines target_cflags target_lflags target_implicit_dependencies target_link_dependencies
target() {
local name=$1
shift
local platform=lnx
local sources=
local objects=
local executable=
local phony=
local include_directories=
local defines=
local cflags=
local lflags=
local implicit_dependencies=
local link_dependencies=
local PKG_CONFIG=PKG_CONFIG_${platform}
local CC=CC_${platform}
local LINK=LINK_${platform}
local EXE=EXE_${platform}
local CFLAGS=CFLAGS_${platform}
local LFLAGS=LFLAGS_${platform}
local AR=AR_${platform}
local no_c=
while (( "$#" )); do
local arg=$1
shift
if [[ $arg = --executable ]]; then
executable=1
elif [[ $arg = --phony ]]; then
phony=1
elif [[ $arg = --include-directory ]]; then
include_directories="$include_directories -I$1"
shift
elif [[ $arg = --implicit ]]; then
implicit_dependencies="$implicit_dependencies $1"
shift
elif [[ $arg = --pkg-config ]]; then
cflags="$cflags $(pkg-config --cflags $1)"
lflags="$lflags $(pkg-config --libs $1)"
shift
else
local tgt=${target_defined[$arg]}
if [[ -z "$tgt" ]]; then
if [[ -z "$phony" ]]; then
sources="$sources $arg"
no_c=${arg%.c}
[ $arg = $no_c ] && echo "only c sources can be used"
objects="$objects \$builddir/${platform}-${no_c//\//-}.o"
else
phony="$phony $arg"
fi
else
include_directories="$include_directories ${target_include_directories[$arg]}"
defines="$defines ${target_defines[$arg]}"
cflags="$cflags ${target_cflags[$arg]}"
lflags="$lflags ${target_lflags[$arg]}"
implicit_dependencies="$implicit_dependencies ${target_implicit_dependencies[$arg]}"
link_dependencies="$link_dependencies ${target_link_dependencies[$arg]}"
fi
fi
done
if [[ ! -z "$phony" ]]; then
implicit_dependencies="$implicit_dependencies $name"
build $name phony ${phony:1}
fi
implicit_dependencies=$(echo $implicit_dependencies | uniq)
if [[ ! -z "$sources" ]]; then
rule ${name}_cc \
--command "${!CC} -MD -MF \$out.d $include_directories $defines ${!CFLAGS} $cflags -c \$in -o \$out" \
--depfile "\$out.d" \
--deps "gcc"
for src in $sources; do
no_c=${src%.c}
build "\$builddir/${platform}-${no_c//\//-}.o" ${name}_cc $src --implicit "$implicit_dependencies"
done
if [[ ! -z "$executable" ]]; then
rule ${name}_link \
--command "${!LINK} ${!CFLAGS} $cflags ${!LFLAGS} -L\$builddir/${platform}-lib $lflags \$in -o \$out"
build \$builddir/$name${!EXE} ${name}_link $objects --implicit "$link_dependencies"
else
rule ${name}_ar \
--command "rm -f \$out && ${!AR} crs \$out \$in"
build \$builddir/${platform}-lib/lib${name}.a ${name}_ar $objects
lflags="$lflags -l$name"
link_dependencies="$link_dependencies \$builddir/${platform}-lib/lib${name}.a"
fi
fi
target_defined[$name]=1
target_include_directories[$name]=$(echo $include_directories | uniq)
target_defines[$name]=$(echo $defines | uniq)
target_cflags[$name]=$(echo $cflags | uniq)
target_lflags[$name]=$(echo $lflags | uniq)
target_implicit_dependencies[$name]=$implicit_dependencies
target_link_dependencies[$name]=$link_dependencies
}
phony() {
local name=$1
shift
target $name --phony $*
}
library() {
target $*
}
executable() {
local name=$1
shift
target $name --executable $*
}