File: protobufgen.sh

package info (click to toggle)
libgadu 1:1.12.1-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,820 kB
  • ctags: 1,649
  • sloc: ansic: 21,459; perl: 370; makefile: 209; sh: 124
file content (49 lines) | stat: -rwxr-xr-x 1,576 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh

PROTOC_LEGACY=no

if ! protoc-c --version | grep "protobuf-c 1." > /dev/null; then
	PROTOC_VER=`protoc-c --version | grep protobuf-c | cut -d' ' -f 2`
	if [ "$PROTOC_VER" = "" ]; then
		echo
		echo "########################################"
		echo "# WARNING"
		echo "########################################"
		echo
		echo "protoc-c < 1.0.0 found"
		echo "The output will be fixed to match the new API, but it's better to update."
		echo
		PROTOC_LEGACY=yes
	else
		echo "Invalid protoc-c version. Required 1.x.y, but $PROTOC_VER found."
		exit -2
	fi
fi

protoc-c --c_out=. packets.proto

if [ $? != 0 ] ; then
	exit -1
fi

if [ "x$PROTOC_LEGACY" = "xyes" ]; then
	sed -i 's/<google\/protobuf-c\/protobuf-c.h>/"protobuf.h"/g' packets.pb-c.h

	# fix protoc-c < 0.14 output
	if ! cat packets.pb-c.c | grep "PROTOBUF_C_NO_DEPRECATED" > /dev/null; then
		sed -i 's| NULL,NULL \+/\* reserved1, reserved2 \*/| 0, 0, NULL, NULL|g' packets.pb-c.c
	fi

	# translate 0.15 output to 1.0.2
	sed -i 's/PROTOBUF_C_BEGIN_DECLS/PROTOBUF_C__BEGIN_DECLS/g' packets.pb-c.h
	sed -i 's/PROTOBUF_C_END_DECLS/PROTOBUF_C__END_DECLS/g' packets.pb-c.h
	sed -i 's/PROTOBUF_C_ASSERT/assert /g' packets.pb-c.c
	sed -i 's/PROTOBUF_C_OFFSETOF/offsetof/g' packets.pb-c.c
	sed -i 's/PROTOBUF_C_MESSAGE_DESCRIPTOR_MAGIC/PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC/g' packets.pb-c.c
	sed -i 's/PROTOBUF_C_ENUM_DESCRIPTOR_MAGIC/PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC/g' packets.pb-c.c
else
	sed -i 's/<protobuf-c\/protobuf-c.h>/"protobuf.h"/g' packets.pb-c.h
fi

mv packets.pb-c.h include
mv packets.pb-c.c src