diff --git a/Makefile b/Makefile index 745e3d006eb..e8c252b2846 100644 --- a/Makefile +++ b/Makefile @@ -339,10 +339,10 @@ CACHE_MK = HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false) ifeq ($(HAS_PKG_CONFIG), true) -CACHE_MK += HAS_PKG_CONFIG = true\n +CACHE_MK += HAS_PKG_CONFIG = true, endif -PC_TEMPLATE = prefix=$(prefix)\nexec_prefix=\$${prefix}\nincludedir=\$${prefix}/include\nlibdir=\$${exec_prefix}/lib\n\nName: $(PC_NAME)\nDescription: $(PC_DESCRIPTION)\nVersion: $(VERSION)\nCflags: -I\$${includedir} $(PC_CFLAGS)\nRequires.private: $(PC_REQUIRES_PRIVATE)\nLibs: -L\$${libdir} $(PC_LIB)\nLibs.private: $(PC_LIBS_PRIVATE) +PC_TEMPLATE = prefix=$(prefix),exec_prefix=\$${prefix},includedir=\$${prefix}/include,libdir=\$${exec_prefix}/lib,,Name: $(PC_NAME),Description: $(PC_DESCRIPTION),Version: $(VERSION),Cflags: -I\$${includedir} $(PC_CFLAGS),Requires.private: $(PC_REQUIRES_PRIVATE),Libs: -L\$${libdir} $(PC_LIB),Libs.private: $(PC_LIBS_PRIVATE) # gpr .pc file PC_NAME = gRPC Portable Runtime @@ -417,7 +417,7 @@ HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true ifeq ($(HAS_SYSTEM_PERFTOOLS),true) DEFINES += GRPC_HAVE_PERFTOOLS LIBS += profiler -CACHE_MK += HAS_SYSTEM_PERFTOOLS = true\n +CACHE_MK += HAS_SYSTEM_PERFTOOLS = true, endif endif @@ -426,20 +426,20 @@ ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) HAS_SYSTEM_OPENSSL_NPN = true -CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true\n +CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true, else HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false) endif ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) -CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true\n +CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true, endif HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_ZLIB),true) -CACHE_MK += HAS_SYSTEM_ZLIB = true\n +CACHE_MK += HAS_SYSTEM_ZLIB = true, endif HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY) ifeq ($(HAS_SYSTEM_PROTOBUF),true) -CACHE_MK += HAS_SYSTEM_PROTOBUF = true\n +CACHE_MK += HAS_SYSTEM_PROTOBUF = true, endif else # override system libraries if the config requires a custom compiled library @@ -451,10 +451,10 @@ endif HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_PROTOC),true) -CACHE_MK += HAS_PROTOC = true\n +CACHE_MK += HAS_PROTOC = true, HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_VALID_PROTOC),true) -CACHE_MK += HAS_VALID_PROTOC = true\n +CACHE_MK += HAS_VALID_PROTOC = true, endif else HAS_VALID_PROTOC = false @@ -475,7 +475,7 @@ endif endif ifeq ($(HAS_SYSTEMTAP),true) -CACHE_MK += HAS_SYSTEMTAP = true\n +CACHE_MK += HAS_SYSTEMTAP = true, endif # Note that for testing purposes, one can do: @@ -2905,32 +2905,32 @@ endif cache.mk:: $(E) "[MAKE] Generating $@" - $(Q) echo -e "$(CACHE_MK)" >$@ + $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GPR_PC_FILE)" >$@ + $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPC_PC_FILE)" >$@ + $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPC_UNSECURE_PC_FILE)" >$@ + $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPCXX_PC_FILE)" >$@ + $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPCXX_UNSECURE_PC_FILE)" >$@ + $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ ifeq ($(NO_PROTOC),true) $(GENDIR)/examples/pubsub/empty.pb.cc: protoc_dep_error diff --git a/include/grpc/support/useful.h b/include/grpc/support/useful.h index e1ce0455c6a..6eb212a311b 100644 --- a/include/grpc/support/useful.h +++ b/include/grpc/support/useful.h @@ -52,4 +52,13 @@ b = x; \ } while (0) +/** Set the \a n-th bit of \a i */ +#define GPR_BITSET(i, n) (i |= (1u << n)) + +/** Clear the \a n-th bit of \a i */ +#define GPR_BITCLEAR(i, n) (i &= ~(1u << n)) + +/** Get the \a n-th bit of \a i */ +#define GPR_BITGET(i, n) ((i & (1u << n)) != 0) + #endif /* GRPC_SUPPORT_USEFUL_H */ diff --git a/templates/Makefile.template b/templates/Makefile.template index 490c002f9a9..044db4dbfee 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -353,20 +353,20 @@ CACHE_MK = HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false) ifeq ($(HAS_PKG_CONFIG), true) -CACHE_MK += HAS_PKG_CONFIG = true\n -endif - -PC_TEMPLATE = prefix=$(prefix)\n\ -exec_prefix=${'\$${prefix}'}\n\ -includedir=${'\$${prefix}'}/include\n\ -libdir=${'\$${exec_prefix}'}/lib\n\ -\n\ -Name: $(PC_NAME)\n\ -Description: $(PC_DESCRIPTION)\n\ -Version: $(VERSION)\n\ -Cflags: -I${'\$${includedir}'} $(PC_CFLAGS)\n\ -Requires.private: $(PC_REQUIRES_PRIVATE)\n\ -Libs: -L${'\$${libdir}'} $(PC_LIB)\n\ +CACHE_MK += HAS_PKG_CONFIG = true, +endif + +PC_TEMPLATE = prefix=$(prefix),\ +exec_prefix=${'\$${prefix}'},\ +includedir=${'\$${prefix}'}/include,\ +libdir=${'\$${exec_prefix}'}/lib,\ +,\ +Name: $(PC_NAME),\ +Description: $(PC_DESCRIPTION),\ +Version: $(VERSION),\ +Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ +Requires.private: $(PC_REQUIRES_PRIVATE),\ +Libs: -L${'\$${libdir}'} $(PC_LIB),\ Libs.private: $(PC_LIBS_PRIVATE) # gpr .pc file @@ -442,7 +442,7 @@ HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true ifeq ($(HAS_SYSTEM_PERFTOOLS),true) DEFINES += GRPC_HAVE_PERFTOOLS LIBS += profiler -CACHE_MK += HAS_SYSTEM_PERFTOOLS = true\n +CACHE_MK += HAS_SYSTEM_PERFTOOLS = true, endif endif @@ -451,20 +451,20 @@ ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) HAS_SYSTEM_OPENSSL_NPN = true -CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true\n +CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true, else HAS_SYSTEM_OPENSSL_NPN ?= $(shell $(OPENSSL_NPN_CHECK_CMD) 2> /dev/null && echo true || echo false) endif ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) -CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true\n +CACHE_MK += HAS_SYSTEM_OPENSSL_NPN = true, endif HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_SYSTEM_ZLIB),true) -CACHE_MK += HAS_SYSTEM_ZLIB = true\n +CACHE_MK += HAS_SYSTEM_ZLIB = true, endif HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY) ifeq ($(HAS_SYSTEM_PROTOBUF),true) -CACHE_MK += HAS_SYSTEM_PROTOBUF = true\n +CACHE_MK += HAS_SYSTEM_PROTOBUF = true, endif else # override system libraries if the config requires a custom compiled library @@ -476,10 +476,10 @@ endif HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_PROTOC),true) -CACHE_MK += HAS_PROTOC = true\n +CACHE_MK += HAS_PROTOC = true, HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false) ifeq ($(HAS_VALID_PROTOC),true) -CACHE_MK += HAS_VALID_PROTOC = true\n +CACHE_MK += HAS_VALID_PROTOC = true, endif else HAS_VALID_PROTOC = false @@ -500,7 +500,7 @@ endif endif ifeq ($(HAS_SYSTEMTAP),true) -CACHE_MK += HAS_SYSTEMTAP = true\n +CACHE_MK += HAS_SYSTEMTAP = true, endif # Note that for testing purposes, one can do: @@ -1108,32 +1108,32 @@ endif cache.mk:: $(E) "[MAKE] Generating $@" - $(Q) echo -e "$(CACHE_MK)" >$@ + $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GPR_PC_FILE)" >$@ + $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPC_PC_FILE)" >$@ + $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPC_UNSECURE_PC_FILE)" >$@ + $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPCXX_PC_FILE)" >$@ + $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@ $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: $(E) "[MAKE] Generating $@" $(Q) mkdir -p $(@D) - $(Q) echo -e "$(GRPCXX_UNSECURE_PC_FILE)" >$@ + $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ % for p in protos: ifeq ($(NO_PROTOC),true) diff --git a/test/core/support/useful_test.c b/test/core/support/useful_test.c index feaf4363795..0804a81b7c3 100644 --- a/test/core/support/useful_test.c +++ b/test/core/support/useful_test.c @@ -39,6 +39,7 @@ int main(int argc, char **argv) { int four[4]; int five[5]; + gpr_uint32 bitset = 0; grpc_test_init(argc, argv); GPR_ASSERT(GPR_MIN(1, 2) == 1); @@ -55,5 +56,11 @@ int main(int argc, char **argv) { GPR_ASSERT(GPR_ARRAY_SIZE(four) == 4); GPR_ASSERT(GPR_ARRAY_SIZE(five) == 5); + GPR_ASSERT(GPR_BITSET(bitset, 3) == 8); + GPR_ASSERT(GPR_BITGET(bitset, 3) == 1); + GPR_ASSERT(GPR_BITSET(bitset, 1) == 10); + GPR_ASSERT(GPR_BITCLEAR(bitset, 3) == 2); + GPR_ASSERT(GPR_BITGET(bitset, 3) == 0); + return 0; }