Release 18.03
[platform/upstream/armnn.git] / scripts / generate_tensorflow_protobuf.sh
1 #!/bin/sh
2 #
3 # Copyright © 2017 Arm Ltd. All rights reserved.
4 # See LICENSE file in the project root for full license information.
5 #
6
7 THIS_SCRIPT=$0
8 OUTPUT_DIR=$1
9 PROTOBUF_INSTALL_DIR=$2
10
11 usage()
12 {
13   echo
14   echo "Usage: ${THIS_SCRIPT} <OUTPUT_DIR> [PROTOBUF_INSTALL_DIR]"
15   echo
16   echo "  <OUTPUT_DIR> is the location where the generated files will be placed"
17   echo "  [PROTOBUF_INSTALL_DIR] the location of the protobuf installation"
18   echo
19 }
20
21 if [ "x$OUTPUT_DIR" = "x" ]
22 then
23   usage
24   exit 1
25 fi
26
27 mkdir -p ${OUTPUT_DIR}
28 ERR=$?
29 if [ $ERR -ne 0 ]
30 then
31   echo
32   echo "Cannot create output dir: ${OUTPUT_DIR}"
33   echo "mkdir returned: $ERR"
34   echo
35   usage
36   exit 1
37 fi
38
39
40 if [ "x${PROTOBUF_INSTALL_DIR}" = "x" ]
41 then
42   PROTOBUF_INSTALL_DIR=/usr/local
43 fi
44
45 if [ ! -x "${PROTOBUF_INSTALL_DIR}/bin/protoc" ]
46 then
47   echo
48   echo "No usable protocol buffer (protoc) compiler found in ${PROTOBUF_INSTALL_DIR}/bin/"
49   echo "You can specify the location of the protobuf installation as the second"
50   echo "argument of ${THIS_SCRIPT}."
51   usage
52   exit 1
53 fi
54
55
56 TF_PROTO_FILES=tensorflow/contrib/makefile/tf_proto_files.txt
57 if [ -r $TF_PROTO_FILES ]
58 then
59   OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
60   for i in `cat $TF_PROTO_FILES`
61   do
62     LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH:${PROTOBUF_INSTALL_DIR}/lib \
63     $PROTOBUF_INSTALL_DIR/bin/protoc $i \
64       --proto_path=. \
65       --proto_path=${PROTOBUF_INSTALL_DIR}/include \
66       --cpp_out $OUTPUT_DIR
67   done
68 else
69   echo "Couldn't find $TF_PROTO_FILES. This script should be run from the"
70   echo "tensorflow source directory."
71   exit 1
72 fi
73