Current section

Files

Jump to
gpb build compile_descriptor
Raw

build/compile_descriptor

#! /bin/sh
# This is a simple form of make, called as a post_hook from rebar,
# but depending on make for rebar support seemed ... wrong somehow
is_up_to_date () {
target="$1"
shift
test ! -f "$target" && return 1
for f in "$@"
do
test "$f" -nt "$target" && return 1
done
return 0
}
# The || exit $? is needed, if sh is a bash, then with some
# versions of bash with -e, execution does not terminte if a
# subshell exits with non-zero exit code
set -e
if [ -d "./ebin" ]; then
OUT="./ebin"
else
OUT="$REBAR_DEPS_DIR/gpb/ebin"
fi
is_up_to_date descr_src/gpb_descriptor.erl \
priv/proto3/google/protobuf/descriptor.proto || \
( echo "Compiling descriptor.proto..."
erl +B -noinput -pa $OUT \
-I priv/proto3/google/protobuf -o descr_src \
-modprefix gpb_ \
-s gpb_compile c descriptor.proto ) || exit $?
is_up_to_date $OUT/gpb_descriptor.beam descr_src/gpb_descriptor.erl || \
( echo "Compiling gpb_descriptor.erl..."
erlc -Idescr_src -Iinclude -o $OUT +debug_info \
descr_src/gpb_descriptor.erl ) || exit $?
is_up_to_date $OUT/gpb_compile_descr.beam \
descr_src/gpb_compile_descr.erl \
descr_src/gpb_descriptor.hrl || \
( echo "Compiling gpb_compile_descr.erl..."
erlc -Idescr_src -Iinclude -o $OUT +debug_info \
descr_src/gpb_compile_descr.erl ) || exit $?