aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/_user_build.in32
-rwxr-xr-xscripts/benchflatcc.sh6
-rwxr-xr-xscripts/benchmark.sh6
-rwxr-xr-xscripts/bfbs-sample.sh15
-rw-r--r--scripts/build.cfg.make3
-rw-r--r--scripts/build.cfg.make-32bit3
-rw-r--r--scripts/build.cfg.make-concurrent3
-rw-r--r--scripts/build.cfg.ninja3
-rwxr-xr-xscripts/build.sh37
-rwxr-xr-xscripts/cleanall.sh20
-rwxr-xr-xscripts/dev.sh9
-rwxr-xr-xscripts/flatcc-doc.sh36
-rwxr-xr-xscripts/initbuild.sh40
-rwxr-xr-xscripts/monster-doc.example.sh6
-rwxr-xr-xscripts/reflection-doc-example.sh6
-rwxr-xr-xscripts/release.sh9
-rwxr-xr-xscripts/setup.sh112
-rwxr-xr-xscripts/test.sh38
18 files changed, 384 insertions, 0 deletions
diff --git a/scripts/_user_build.in b/scripts/_user_build.in
new file mode 100644
index 0000000..dfcc40a
--- /dev/null
+++ b/scripts/_user_build.in
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+set -e
+
+CC=${CC:-cc}
+
+# assume we are in a subdirectory of the project to build
+HERE=$(dirname $0)/..
+cd $HERE
+ROOT=$(pwd)
+NAME=$(basename $ROOT)
+
+mkdir -p build
+mkdir -p generated
+
+cd build
+
+if [[ "$FLATCC_PORTABLE" = "yes" ]]; then
+ CFLAGS="$CFLAGS -DFLATCC_PORTABLE"
+fi
+
+CFLAGS="$CFLAGS -I ${ROOT}/include -I ${ROOT}/generated"
+CFLAGS_DEBUG=${CFLAGS_DEBUG:--g}
+CFLAGS_RELEASE=${CFLAGS_RELEASE:--O2 -DNDEBUG}
+
+${ROOT}/bin/flatcc -a -o ${ROOT}/generated ${ROOT}/src/*.fbs
+
+echo "building '$NAME' for debug"
+$CC $CFLAGS $CFLAGS_DEBUG ${ROOT}/src/*.c ${ROOT}/lib/libflatccrt_d.a -o ${NAME}_d
+
+echo "building '$NAME' for release"
+$CC $CFLAGS $CFLAGS_RELEASE ${ROOT}/src/*.c ${ROOT}/lib/libflatccrt.a -o ${NAME}
diff --git a/scripts/benchflatcc.sh b/scripts/benchflatcc.sh
new file mode 100755
index 0000000..1dcb830
--- /dev/null
+++ b/scripts/benchflatcc.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+cd `dirname $0`/..
+test/benchmark/benchflatcc/run.sh
diff --git a/scripts/benchmark.sh b/scripts/benchmark.sh
new file mode 100755
index 0000000..370dd56
--- /dev/null
+++ b/scripts/benchmark.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -e
+
+cd `dirname $0`/..
+test/benchmark/benchall.sh
diff --git a/scripts/bfbs-sample.sh b/scripts/bfbs-sample.sh
new file mode 100755
index 0000000..306d93f
--- /dev/null
+++ b/scripts/bfbs-sample.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+cd $(dirname $0)/..
+builddir=build/Debug
+bfbsdir=$builddir/test/reflection_test/generated/
+
+if [ ! -e $bfbsdir/monster_test.bfbs ]; then
+ scripts/test.sh
+fi
+
+$builddir/samples/reflection/bfbs2json_d \
+ $bfbsdir/monster_test.bfbs > $bfbsdir/monster_test_bfbs.json
+
+cat $bfbsdir/monster_test_bfbs.json \
+ | python -m json.tool
diff --git a/scripts/build.cfg.make b/scripts/build.cfg.make
new file mode 100644
index 0000000..ae9c332
--- /dev/null
+++ b/scripts/build.cfg.make
@@ -0,0 +1,3 @@
+FLATCC_BUILD_GEN="Unix Makefiles"
+FLATCC_BUILD_CMD=make
+FLATCC_BUILD_FLAGS=""
diff --git a/scripts/build.cfg.make-32bit b/scripts/build.cfg.make-32bit
new file mode 100644
index 0000000..2299d67
--- /dev/null
+++ b/scripts/build.cfg.make-32bit
@@ -0,0 +1,3 @@
+FLATCC_BUILD_GEN="Unix Makefiles"
+FLATCC_BUILD_CMD=make
+FLATCC_BUILD_FLAGS="-DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32"
diff --git a/scripts/build.cfg.make-concurrent b/scripts/build.cfg.make-concurrent
new file mode 100644
index 0000000..7684642
--- /dev/null
+++ b/scripts/build.cfg.make-concurrent
@@ -0,0 +1,3 @@
+FLATCC_BUILD_GEN="Unix Makefiles"
+FLATCC_BUILD_CMD="make -j"
+FLATCC_BUILD_FLAGS=""
diff --git a/scripts/build.cfg.ninja b/scripts/build.cfg.ninja
new file mode 100644
index 0000000..07ead70
--- /dev/null
+++ b/scripts/build.cfg.ninja
@@ -0,0 +1,3 @@
+FLATCC_BUILD_GEN=Ninja
+FLATCC_BUILD_CMD=ninja
+FLATCC_BUILD_FLAGS=""
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100755
index 0000000..98cd41c
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+set -e
+
+HERE=`dirname $0`
+cd $HERE/..
+ROOT=`pwd`
+
+CFGFILE=${ROOT}/scripts/build.cfg
+
+if [ -e $CFGFILE ]; then
+ . $CFGFILE
+fi
+
+FLATCC_BUILD_CMD=${FLATCC_BUILD_CMD:-ninja}
+
+mkdir -p ${ROOT}/bin
+mkdir -p ${ROOT}/lib
+
+rm -f ${ROOT}/bin/flatcc
+rm -f ${ROOT}/bin/flatcc_d
+rm -f ${ROOT}/libflatcc
+rm -f ${ROOT}/libflatcc_d.a
+rm -f ${ROOT}/libflatccrt.a
+rm -f ${ROOT}/libflatccrt_d.a
+
+if [ ! -d ${ROOT}/build/Debug ] || [ ! -d ${ROOT}/build/Release ]; then
+ ${ROOT}/scripts/initbuild.sh
+fi
+
+echo "building Debug" 1>&2
+cd ${ROOT}/build/Debug && $FLATCC_BUILD_CMD
+
+if [ "$1" != "--debug" ]; then
+ echo "building Release" 1>&2
+ cd ${ROOT}/build/Release && $FLATCC_BUILD_CMD
+fi
diff --git a/scripts/cleanall.sh b/scripts/cleanall.sh
new file mode 100755
index 0000000..a91d58c
--- /dev/null
+++ b/scripts/cleanall.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -e
+
+echo "removing build products"
+
+cd `dirname $0`/..
+
+rm -rf build
+rm -rf release
+rm -f bin/flatcc*
+rm -f bin/bfbs2json*
+rm -f lib/libflatcc*
+if [ -d bin ]; then
+ rmdir bin
+fi
+if [ -d lib ]; then
+ rmdir lib
+fi
+
diff --git a/scripts/dev.sh b/scripts/dev.sh
new file mode 100755
index 0000000..12dabf4
--- /dev/null
+++ b/scripts/dev.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env sh
+
+set -e
+
+HERE=`dirname $0`
+cd $HERE/..
+ROOT=`pwd`
+
+${ROOT}/scripts/test.sh --debug --no-clean
diff --git a/scripts/flatcc-doc.sh b/scripts/flatcc-doc.sh
new file mode 100755
index 0000000..902ae5c
--- /dev/null
+++ b/scripts/flatcc-doc.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+HOME=$(dirname $0)/..
+SCHEMA=${SCHEMA:-$1}
+PREFIX=${PREFIX:-$2}
+OUTDIR=${OUTDIR:-$3}
+OUTDIR=${OUTDIR:-'.'}
+INCLUDE=${INCLUDE:-$HOME/include}
+FLATCC=${FLATCC:-$HOME/bin/flatcc}
+
+if [ "x$SCHEMA" = "x" ]; then
+ echo "Missing schema arg"
+ echo "usage: $(basename $0) schema-file name-prefix [outdir]"
+ exit 1
+fi
+
+if [ "x$PREFIX" = "x" ]; then
+ echo "Missing prefix arg"
+ echo "usage: $(basename $0) schema-file name-prefix [outdir]"
+ exit 1
+fi
+
+echo "flatcc doc for schema: '$SCHEMA' with name prefix: '$PREFIX'"
+
+echo "generating $OUTDIR/$PREFIX.doc"
+
+$FLATCC $SCHEMA -a --json --stdout | \
+ clang - -E -DNDEBUG -I $INCLUDE | \
+ clang-format -style="WebKit" | \
+ grep "^static.* $PREFIX\w*(" | \
+ cut -f 1 -d '{' | \
+ grep -v deprecated | \
+ grep -v ");$" | \
+ sed 's/__tmp//g' | \
+ sed 's/)/);/g' \
+ > $OUTDIR/$PREFIX.doc
diff --git a/scripts/initbuild.sh b/scripts/initbuild.sh
new file mode 100755
index 0000000..2b18cd2
--- /dev/null
+++ b/scripts/initbuild.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+# link a specific build.cfg.xxx to build.cfg to use that build
+# configuration, e.g. ln -sf build.cfg.make build.cfg
+#
+# call build/cleanall.sh before changing
+
+set -e
+
+HERE=`dirname $0`
+cd $HERE/..
+ROOT=`pwd`
+
+CFGFILE=${ROOT}/scripts/build.cfg
+
+if [ x"$1" != x ]; then
+ if [ -e ${CFGFILE}.$1 ]; then
+ ln -sf ${CFGFILE}.$1 $CFGFILE
+ else
+ echo "missing config file for build generator option: $1"
+ exit -1
+ fi
+ ${ROOT}/scripts/cleanall.sh
+fi
+
+if [ -e $CFGFILE ]; then
+ . $CFGFILE
+fi
+
+FLATCC_BUILD_GEN=${FLATCC_BUILD_GEN:-Ninja}
+
+echo "initializing build for CMake $FLATCC_BUILD_GEN"
+
+mkdir -p ${ROOT}/build/Debug
+mkdir -p ${ROOT}/build/Release
+rm -rf ${ROOT}/build/Debug/*
+rm -rf ${ROOT}/build/Release/*
+
+cd ${ROOT}/build/Debug && cmake -G "$FLATCC_BUILD_GEN" $FLATCC_BUILD_FLAGS ../.. -DCMAKE_BUILD_TYPE=Debug
+cd ${ROOT}/build/Release && cmake -G "$FLATCC_BUILD_GEN" $FLATCC_BUILD_FLAGS ../.. -DCMAKE_BUILD_TYPE=Release
diff --git a/scripts/monster-doc.example.sh b/scripts/monster-doc.example.sh
new file mode 100755
index 0000000..a4c6b70
--- /dev/null
+++ b/scripts/monster-doc.example.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+PREFIX=MyGame_Sample_Monster_
+FLATCC=bin/flatcc
+SCHEMA=samples/monster/monster.fbs
+
+. $(dirname $0)/flatcc-doc.sh
diff --git a/scripts/reflection-doc-example.sh b/scripts/reflection-doc-example.sh
new file mode 100755
index 0000000..ea2bcf4
--- /dev/null
+++ b/scripts/reflection-doc-example.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+PREFIX=reflection_Field_vec_
+FLATCC=bin/flatcc
+SCHEMA=reflection/reflection.fbs
+
+. $(dirname $0)/flatcc-doc.sh
diff --git a/scripts/release.sh b/scripts/release.sh
new file mode 100755
index 0000000..d3ad800
--- /dev/null
+++ b/scripts/release.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+VER=`git describe --tags`
+
+echo "archiving tagged version ${VER} to release folder"
+
+cd `dirname $0`/..
+mkdir -p release
+git archive --format=tar.gz --prefix=flatcc-$VER/ v$VER >release/flatcc-$VER.tar.gz
diff --git a/scripts/setup.sh b/scripts/setup.sh
new file mode 100755
index 0000000..c7ea533
--- /dev/null
+++ b/scripts/setup.sh
@@ -0,0 +1,112 @@
+#!/usr/bin/env bash
+
+# This is intended for quickly developming with flatcc tools
+# in a standalone directory
+
+set -e
+
+DIR=`pwd`
+HERE=`dirname $0`
+cd $HERE/..
+ROOT=`pwd`
+
+function usage() {
+ echo "Usage: <flatcc-dir>/scripts/`basename $0` [options] <path>"
+ echo ""
+ echo "Options:"
+ echo " -g | --gitignore : create/update .gitignore file"
+ echo " -b | --build : build flatcc (otherwise is must have been)"
+ echo " -x | --example : copy example source and schema"
+ echo " -s | --script : copy generic build script"
+ echo " -a | --all : all of the above"
+ echo " -h | --help"
+ echo ""
+ echo "Sets up a client project for use with flatcc."
+ echo ""
+ echo "Links flatcc into bin, lib, and include directories and optionally"
+ echo "starts a build first. Optionally creates or updates a .gitignore file"
+ echo "and a generic build script, and a sample project."
+ echo "Also adds an empty generated directory for 'flatcc -o generated',"
+ echo "'cc -I generated', and for git to ignore. 'build' directory"
+ echo "will be ignored if '-b' is selected."
+ echo ""
+ echo "When using the build script (-s), place source and schema files in 'src'."
+ echo "It is only meant for sharing small examples."
+ echo ""
+ echo "The flatcc project must be the parent of the path to this script."
+ exit 1
+}
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+
+ # Standard help option.
+ -h|-\?|-help|--help|--doc*) usage ;;
+ -g|--gitignore) G=1 ;;
+ -b|--build) B=1 ;;
+ -s|--script) S=1 ;;
+ -x|--example) X=1 ;;
+ -a|--all) G=1; B=1; S=1; X=1 ;;
+
+ -*) echo "Unknown option \"$1\""; usage ;;
+ *) break ;; # unforced end of user options
+ esac
+ shift # next option
+done
+
+if [[ -z "$1" ]]; then
+ echo "Please specify a path"
+ usage
+fi
+
+echo "Building flatcc libraries and tool"
+
+if [[ ! -d "$ROOT/include/flatcc" ]]; then
+ echo "script not located in flatcc project"
+fi
+
+if [[ -n "$B" ]]; then
+ $ROOT/scripts/build.sh
+fi
+
+echo "Linking flatcc tool and library into $1"
+
+mkdir -p $DIR/$1
+cd $DIR/$1
+
+if [[ -n "$S" ]]; then
+ echo "Copying build script"
+ mkdir -p scripts
+ mkdir -p src
+ cp $ROOT/scripts/_user_build.in scripts/build.sh
+ chmod +x scripts/build.sh
+fi
+
+if [[ -n "$X" ]]; then
+ echo "Copying monster sample project"
+ mkdir -p src
+ cp $ROOT/samples/monster/monster.{c,fbs} src
+fi
+
+mkdir -p lib
+mkdir -p bin
+mkdir -p include
+
+ln -sf $ROOT/bin/flatcc bin/
+ln -sf $ROOT/lib/libflatcc.a lib/
+ln -sf $ROOT/lib/libflatccrt.a lib/
+ln -sf $ROOT/lib/libflatcc_d.a lib/
+ln -sf $ROOT/lib/libflatccrt_d.a lib/
+ln -sf $ROOT/include/flatcc include/
+
+if [[ -n "$G" ]]; then
+ echo "Updating .gitignore"
+ touch .gitignore
+ grep -q '^bin/flatcc*' .gitignore || echo 'bin/flatcc*' >> .gitignore
+ grep -q '^lib/libflatcc*.a' .gitignore || echo 'lib/libflatcc*.a' >> .gitignore
+ grep -q '^include/flatcc' .gitignore || echo 'include/flatcc' >> .gitignore
+ grep -q '^generated/' .gitignore || echo 'generated/' >> .gitignore
+ if [[ -n "$S" ]]; then
+ grep -q '^build/' .gitignore || echo 'build/' >> .gitignore
+ fi
+fi
diff --git a/scripts/test.sh b/scripts/test.sh
new file mode 100755
index 0000000..d87924b
--- /dev/null
+++ b/scripts/test.sh
@@ -0,0 +1,38 @@
+#!/usr/bin/env sh
+
+set -e
+
+HERE=`dirname $0`
+cd $HERE/..
+ROOT=`pwd`
+
+DBGDIR=$ROOT/build/Debug
+RELDIR=$ROOT/build/Release
+
+if [ "$1" = "--debug" ]; then
+ DEBUG=$1
+ echo "running debug build"
+ shift
+fi
+
+if [ "$1" != "--no-clean" ]; then
+ echo "cleaning build before tests ..."
+ $ROOT/scripts/cleanall.sh
+else
+ shift
+fi
+
+echo "building before tests ..."
+$ROOT/scripts/build.sh $DEBUG
+
+echo "running test in debug build ..."
+cd $DBGDIR && ctest $ROOT
+
+if [ "$DEBUG" != "--debug" ]; then
+echo "running test in release build ..."
+cd $RELDIR && ctest $ROOT
+echo "TEST PASSED"
+else
+ echo "DEBUG TEST PASSED"
+fi
+