Hello, In my effort to upgrade devel/protobuf to 3.2.0 I ran into an interesting snag. The build process creates a code-generated file which happens to have a line like this:
::google::protobuf::int32 major() const;
as part of its src/google/protobuf/compiler/plugin.pb.h
This would normally be fine, except on BSD there's this fragment in
/usr/include/sys/types.h
#if __BSD_VISIBLE
/* Major, minor numbers, dev_t's. */
#define major(x) ((int32_t)(((u_int32_t)(x) >> 8) & 0xff))
#define minor(x) ((int32_t)((x) & 0xff) | (((x) & 0xffff0000) >> 8))
#define makedev(x,y) ((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) &
0xffff00) << 8)))
#endif
Which causes these failures reported by clang:
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/compiler/plugin.pb.h:238:29:
error:
expected ')'
::google::protobuf::int32 major() const;
^
/usr/include/sys/types.h:212:45: note: expanded from macro 'major'
#define major(x) ((int32_t)(((u_int32_t)(x) >> 8) & 0xff))
Or if it were with gcc4, it would be this undecipherable stuff:
c++ -std=c++11 -DHAVE_CONFIG_H -I.
-I/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src -I.. -pthread
-DHAVE_PTHREAD=1 -DHAVE_ZLIB=1 -Wall -Wno-sign-compare -O2 -pipe -MT
google/protobuf/compiler/code_generator.lo -MD -MP -MF
google/protobuf/compiler/.deps/code_generator.Tpo -c
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/compiler/code_generator.cc
-fPIC -DPIC -o google/protobuf/compiler/.libs/code_generator.o
In file included from /usr/include/stdio.h:46:0,
from /usr/include/wchar.h:66,
from /usr/local/include/c++/4.9.4/cwchar:44,
from /usr/local/include/c++/4.9.4/bits/postypes.h:40,
from /usr/local/include/c++/4.9.4/bits/char_traits.h:40,
from /usr/local/include/c++/4.9.4/string:40,
from
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/stubs/common.h:38,
from
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/compiler/code_generator.h:41,
from
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/compiler/code_generator.cc:35:
/usr/ports/pobj/protobuf-3.2.0/protobuf-3.2.0/src/google/protobuf/compiler/plugin.pb.h:238:29:
error: expected identifier before '(' token
::google::protobuf::int32 major() const;
^
My question is: how do ports deal with BSD defining these macros that stay
behind and spoil compilation of entirely unrelated code. I see that there's
a macro I could try to tackle. I found some references to BSD_SOURCE and
POSIX_C_SOURCE as being related, but I don't see a cookie-cutter recipe to
borrow, so I thought I should ask.
All the changes are in my github repo:
https://github.com/openbsd/ports/compare/master...blackgnezdo:proto3?expand=1
The current state of the patch is also attached.
Thanks
Greg
devel-protobuf-3.2.0.patch.gz
Description: application/gzip
