1%YAML 1.2 2--- | 3 # GRPC global makefile 4 # This currently builds C and C++ code. 5 # This file has been automatically generated from a template file. 6 # Please look at the templates directory instead. 7 # This file can be regenerated from the template by running 8 # tools/buildgen/generate_projects.sh 9 10 # Copyright 2015 gRPC authors. 11 # 12 # Licensed under the Apache License, Version 2.0 (the "License"); 13 # you may not use this file except in compliance with the License. 14 # You may obtain a copy of the License at 15 # 16 # http://www.apache.org/licenses/LICENSE-2.0 17 # 18 # Unless required by applicable law or agreed to in writing, software 19 # distributed under the License is distributed on an "AS IS" BASIS, 20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 # See the License for the specific language governing permissions and 22 # limitations under the License. 23 <%! 24 import re 25 import os 26 27 proto_re = re.compile('(.*)\\.proto') 28 29 def proto_to_cc(filename): 30 m = proto_re.match(filename) 31 if not m: 32 return filename 33 return '$(GENDIR)/' + m.group(1) + '.pb.cc $(GENDIR)/' + m.group(1) + '.grpc.pb.cc' 34 35 sources_that_need_openssl = set() 36 sources_that_don_t_need_openssl = set() 37 38 # warnings we'd like, but that dont exist in all compilers 39 PREFERRED_WARNINGS=['shadow', 'extra-semi'] 40 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized'] 41 42 def warning_var(fmt, warning): 43 return fmt % warning.replace('-', '_').replace('+', 'X').upper() 44 45 def neg_warning(warning): 46 if warning[0:3] == 'no-': 47 return warning[3:] 48 else: 49 return 'no-' + warning 50 51 lang_to_var = { 52 'c': 'CORE', 53 'c++': 'CPP', 54 'csharp': 'CSHARP' 55 } 56 %> 57 58 59 comma := , 60 61 62 # Basic platform detection 63 HOST_SYSTEM = $(shell uname | cut -f 1 -d_) 64 SYSTEM ?= $(HOST_SYSTEM) 65 ifeq ($(SYSTEM),MSYS) 66 SYSTEM = MINGW32 67 endif 68 ifeq ($(SYSTEM),MINGW64) 69 SYSTEM = MINGW32 70 endif 71 72 73 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) 74 ifndef BUILDDIR 75 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH))) 76 else 77 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR)) 78 endif 79 80 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false) 81 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false) 82 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false) 83 84 ifeq ($(HAS_CC),true) 85 DEFAULT_CC = cc 86 DEFAULT_CXX = c++ 87 else 88 ifeq ($(HAS_GCC),true) 89 DEFAULT_CC = gcc 90 DEFAULT_CXX = g++ 91 else 92 ifeq ($(HAS_CLANG),true) 93 DEFAULT_CC = clang 94 DEFAULT_CXX = clang++ 95 else 96 DEFAULT_CC = no_c_compiler 97 DEFAULT_CXX = no_c++_compiler 98 endif 99 endif 100 endif 101 102 103 BINDIR = $(BUILDDIR_ABSOLUTE)/bins 104 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs 105 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs 106 GENDIR = $(BUILDDIR_ABSOLUTE)/gens 107 108 # Configurations 109 110 % for name, args in configs.iteritems(): 111 VALID_CONFIG_${name} = 1 112 % if args.get('compile_the_world', False): 113 REQUIRE_CUSTOM_LIBRARIES_${name} = 1 114 % endif 115 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]: 116 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)} 117 % endfor 118 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']: 119 % if args.get(arg, None) is not None: 120 ${arg}_${name} = ${args.get(arg)} 121 % endif 122 % endfor 123 124 % endfor 125 126 127 # General settings. 128 # You may want to change these depending on your system. 129 130 prefix ?= /usr/local 131 132 PROTOC ?= protoc 133 DTRACE ?= dtrace 134 CONFIG ?= opt 135 # Doing X ?= Y is the same as: 136 # ifeq ($(origin X), undefined) 137 # X = Y 138 # endif 139 # but some variables, such as CC, CXX, LD or AR, have defaults. 140 # So instead of using ?= on them, we need to check their origin. 141 # See: 142 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html 143 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d 144 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html 145 ifeq ($(origin CC), default) 146 CC = $(CC_$(CONFIG)) 147 endif 148 ifeq ($(origin CXX), default) 149 CXX = $(CXX_$(CONFIG)) 150 endif 151 ifeq ($(origin LD), default) 152 LD = $(LD_$(CONFIG)) 153 endif 154 LDXX ?= $(LDXX_$(CONFIG)) 155 ifeq ($(SYSTEM),Linux) 156 ifeq ($(origin AR), default) 157 AR = ar rcs 158 endif 159 STRIP ?= strip --strip-unneeded 160 else 161 ifeq ($(SYSTEM),Darwin) 162 ifeq ($(origin AR), default) 163 AR = libtool -no_warning_for_no_symbols -o 164 endif 165 STRIP ?= strip -x 166 else 167 ifeq ($(SYSTEM),MINGW32) 168 ifeq ($(origin AR), default) 169 AR = ar rcs 170 endif 171 STRIP ?= strip --strip-unneeded 172 else 173 ifeq ($(origin AR), default) 174 AR = ar rcs 175 endif 176 STRIP ?= strip 177 endif 178 endif 179 endif 180 INSTALL ?= install 181 RM ?= rm -f 182 PKG_CONFIG ?= pkg-config 183 184 ifndef VALID_CONFIG_$(CONFIG) 185 $(error Invalid CONFIG value '$(CONFIG)') 186 endif 187 188 ifeq ($(SYSTEM),Linux) 189 TMPOUT = /dev/null 190 else 191 TMPOUT = `mktemp /tmp/test-out-XXXXXX` 192 endif 193 194 CHECK_NO_CXX14_COMPAT_WORKS_CMD = $(CC) -std=c++11 -Werror -Wno-c++14-compat -o $(TMPOUT) -c test/build/no-c++14-compat.cc 195 HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false) 196 ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true) 197 W_NO_CXX14_COMPAT=-Wno-c++14-compat 198 endif 199 200 %for warning in CHECK_WARNINGS: 201 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c 202 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false) 203 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true) 204 ${warning_var('W_%s', warning)}=-W${warning} 205 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)} 206 endif 207 %endfor 208 209 # The HOST compiler settings are used to compile the protoc plugins. 210 # In most cases, you won't have to change anything, but if you are 211 # cross-compiling, you can override these variables from GNU make's 212 # command line: make CC=cross-gcc HOST_CC=gcc 213 214 HOST_CC ?= $(CC) 215 HOST_CXX ?= $(CXX) 216 HOST_LD ?= $(LD) 217 HOST_LDXX ?= $(LDXX) 218 219 CFLAGS += -std=c99 -Wsign-conversion -Wconversion ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)} 220 CXXFLAGS += -std=c++11 221 ifeq ($(SYSTEM),Darwin) 222 CXXFLAGS += -stdlib=libc++ 223 endif 224 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']: 225 % if defaults.get('global', []).get(arg, None) is not None: 226 ${arg} += ${defaults.get('global').get(arg)} 227 % endif 228 % endfor 229 230 CPPFLAGS += $(CPPFLAGS_$(CONFIG)) 231 CFLAGS += $(CFLAGS_$(CONFIG)) 232 CXXFLAGS += $(CXXFLAGS_$(CONFIG)) 233 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\" 234 LDFLAGS += $(LDFLAGS_$(CONFIG)) 235 236 ifneq ($(SYSTEM),MINGW32) 237 PIC_CPPFLAGS = -fPIC 238 CPPFLAGS += -fPIC 239 LDFLAGS += -fPIC 240 endif 241 242 INCLUDES = . include $(GENDIR) 243 LDFLAGS += -Llibs/$(CONFIG) 244 245 ifeq ($(SYSTEM),Darwin) 246 ifneq ($(wildcard /usr/local/ssl/include),) 247 INCLUDES += /usr/local/ssl/include 248 endif 249 ifneq ($(wildcard /opt/local/include),) 250 INCLUDES += /opt/local/include 251 endif 252 ifneq ($(wildcard /usr/local/include),) 253 INCLUDES += /usr/local/include 254 endif 255 LIBS = m z 256 ifneq ($(wildcard /usr/local/ssl/lib),) 257 LDFLAGS += -L/usr/local/ssl/lib 258 endif 259 ifneq ($(wildcard /opt/local/lib),) 260 LDFLAGS += -L/opt/local/lib 261 endif 262 ifneq ($(wildcard /usr/local/lib),) 263 LDFLAGS += -L/usr/local/lib 264 endif 265 endif 266 267 ifeq ($(SYSTEM),Linux) 268 LIBS = dl rt m pthread 269 LDFLAGS += -pthread 270 endif 271 272 ifeq ($(SYSTEM),MINGW32) 273 LIBS = m pthread ws2_32 274 LDFLAGS += -pthread 275 endif 276 277 # 278 # The steps for cross-compiling are as follows: 279 # First, clone and make install of grpc using the native compilers for the host. 280 # Also, install protoc (e.g., from a package like apt-get) 281 # Then clone a fresh grpc for the actual cross-compiled build 282 # Set the environment variable GRPC_CROSS_COMPILE to true 283 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries 284 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g., 285 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" ) 286 # Set HAS_PKG_CONFIG=false 287 # To build tests, go to third_party/gflags and follow its ccmake instructions 288 # Make sure that you enable building shared libraries and set your prefix to 289 # something useful like /usr/local/cross 290 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold 291 # additional required arguments for LD and AR (examples below) 292 # Then you can do a make from the cross-compiling fresh clone! 293 # 294 ifeq ($(GRPC_CROSS_COMPILE),true) 295 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib 296 AROPTS = $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little 297 USE_BUILT_PROTOC = false 298 endif 299 300 GTEST_LIB = -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googletest third_party/googletest/googletest/src/gtest-all.cc -Ithird_party/googletest/googlemock/include -Ithird_party/googletest/googlemock third_party/googletest/googlemock/src/gmock-all.cc 301 GTEST_LIB += -lgflags 302 ifeq ($(V),1) 303 E = @: 304 Q = 305 else 306 E = @echo 307 Q = @ 308 endif 309 310 CORE_VERSION = ${settings.core_version} 311 CPP_VERSION = ${settings.cpp_version} 312 CSHARP_VERSION = ${settings.csharp_version} 313 314 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) 315 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) 316 317 LDFLAGS += $(ARCH_FLAGS) 318 LDLIBS += $(addprefix -l, $(LIBS)) 319 LDLIBSXX += $(addprefix -l, $(LIBSXX)) 320 321 322 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']: 323 ${arg} += $(EXTRA_${arg}) 324 % endfor 325 326 HOST_CPPFLAGS = $(CPPFLAGS) 327 HOST_CFLAGS = $(CFLAGS) 328 HOST_CXXFLAGS = $(CXXFLAGS) 329 HOST_LDFLAGS = $(LDFLAGS) 330 HOST_LDLIBS = $(LDLIBS) 331 332 # These are automatically computed variables. 333 # There shouldn't be any need to change anything from now on. 334 335 -include cache.mk 336 337 CACHE_MK = 338 339 HAS_PKG_CONFIG ?= $(shell command -v $(PKG_CONFIG) >/dev/null 2>&1 && echo true || echo false) 340 341 ifeq ($(HAS_PKG_CONFIG), true) 342 CACHE_MK += HAS_PKG_CONFIG = true, 343 endif 344 345 CORE_PC_TEMPLATE = prefix=$(prefix),\ 346 exec_prefix=${'\$${prefix}'},\ 347 includedir=${'\$${prefix}'}/include,\ 348 libdir=${'\$${exec_prefix}'}/lib,\ 349 ,\ 350 Name: $(PC_NAME),\ 351 Description: $(PC_DESCRIPTION),\ 352 Version: $(CORE_VERSION),\ 353 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ 354 Requires.private: $(PC_REQUIRES_PRIVATE),\ 355 Libs: -L${'\$${libdir}'} $(PC_LIB),\ 356 Libs.private: $(PC_LIBS_PRIVATE) 357 358 CPP_PC_TEMPLATE = prefix=$(prefix),\ 359 exec_prefix=${'\$${prefix}'},\ 360 includedir=${'\$${prefix}'}/include,\ 361 libdir=${'\$${exec_prefix}'}/lib,\ 362 ,\ 363 Name: $(PC_NAME),\ 364 Description: $(PC_DESCRIPTION),\ 365 Version: $(CPP_VERSION),\ 366 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ 367 Requires.private: $(PC_REQUIRES_PRIVATE),\ 368 Libs: -L${'\$${libdir}'} $(PC_LIB),\ 369 Libs.private: $(PC_LIBS_PRIVATE) 370 371 CSHARP_PC_TEMPLATE = prefix=$(prefix),\ 372 exec_prefix=${'\$${prefix}'},\ 373 includedir=${'\$${prefix}'}/include,\ 374 libdir=${'\$${exec_prefix}'}/lib,\ 375 ,\ 376 Name: $(PC_NAME),\ 377 Description: $(PC_DESCRIPTION),\ 378 Version: $(CSHARP_VERSION),\ 379 Cflags: -I${'\$${includedir}'} $(PC_CFLAGS),\ 380 Requires.private: $(PC_REQUIRES_PRIVATE),\ 381 Libs: -L${'\$${libdir}'} $(PC_LIB),\ 382 Libs.private: $(PC_LIBS_PRIVATE) 383 384 ifeq ($(SYSTEM),MINGW32) 385 EXECUTABLE_SUFFIX = .exe 386 SHARED_EXT_CORE = dll 387 SHARED_EXT_CPP = dll 388 SHARED_EXT_CSHARP = dll 389 SHARED_PREFIX = 390 SHARED_VERSION_CORE = -${settings.core_version.major} 391 SHARED_VERSION_CPP = -${settings.cpp_version.major} 392 SHARED_VERSION_CSHARP = -${settings.csharp_version.major} 393 else ifeq ($(SYSTEM),Darwin) 394 EXECUTABLE_SUFFIX = 395 SHARED_EXT_CORE = dylib 396 SHARED_EXT_CPP = dylib 397 SHARED_EXT_CSHARP = dylib 398 SHARED_PREFIX = lib 399 SHARED_VERSION_CORE = 400 SHARED_VERSION_CPP = 401 SHARED_VERSION_CSHARP = 402 else 403 EXECUTABLE_SUFFIX = 404 SHARED_EXT_CORE = so.$(CORE_VERSION) 405 SHARED_EXT_CPP = so.$(CPP_VERSION) 406 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION) 407 SHARED_PREFIX = lib 408 SHARED_VERSION_CORE = 409 SHARED_VERSION_CPP = 410 SHARED_VERSION_CSHARP = 411 endif 412 413 ifeq ($(wildcard .git),) 414 IS_GIT_FOLDER = false 415 else 416 IS_GIT_FOLDER = true 417 endif 418 419 ifeq ($(HAS_PKG_CONFIG),true) 420 OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl 421 ZLIB_CHECK_CMD = $(PKG_CONFIG) --exists zlib 422 PROTOBUF_CHECK_CMD = $(PKG_CONFIG) --atleast-version=3.5.0 protobuf 423 CARES_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.11.0 libcares 424 else # HAS_PKG_CONFIG 425 426 ifeq ($(SYSTEM),MINGW32) 427 OPENSSL_LIBS = ssl32 eay32 428 else 429 OPENSSL_LIBS = ssl crypto 430 endif 431 432 OPENSSL_ALPN_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/openssl-alpn.c $(addprefix -l, $(OPENSSL_LIBS)) $(LDFLAGS) 433 BORINGSSL_COMPILE_CHECK_CMD = $(CC) $(CPPFLAGS) ${defaults.boringssl.CPPFLAGS} $(CFLAGS) ${defaults.boringssl.CFLAGS} -o $(TMPOUT) test/build/boringssl.c $(LDFLAGS) 434 ZLIB_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) 435 PROTOBUF_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) 436 CARES_CHECK_CMD = $(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $(TMPOUT) test/build/c-ares.c -lcares $(LDFLAGS) 437 438 endif # HAS_PKG_CONFIG 439 440 PERFTOOLS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) 441 442 PROTOC_CHECK_CMD = which protoc > /dev/null 443 PROTOC_CHECK_VERSION_CMD = protoc --version | grep -q libprotoc.3 444 DTRACE_CHECK_CMD = which dtrace > /dev/null 445 SYSTEMTAP_HEADERS_CHECK_CMD = $(CC) $(CPPFLAGS) $(CFLAGS) -o $(TMPOUT) test/build/systemtap.c $(LDFLAGS) 446 447 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) 448 HAS_SYSTEM_PERFTOOLS ?= $(shell $(PERFTOOLS_CHECK_CMD) 2> /dev/null && echo true || echo false) 449 ifeq ($(HAS_SYSTEM_PERFTOOLS),true) 450 DEFINES += GRPC_HAVE_PERFTOOLS 451 LIBS += profiler 452 CACHE_MK += HAS_SYSTEM_PERFTOOLS = true, 453 endif 454 endif 455 456 HAS_SYSTEM_PROTOBUF_VERIFY = $(shell $(PROTOBUF_CHECK_CMD) 2> /dev/null && echo true || echo false) 457 ifndef REQUIRE_CUSTOM_LIBRARIES_$(CONFIG) 458 HAS_SYSTEM_OPENSSL_ALPN ?= $(shell $(OPENSSL_ALPN_CHECK_CMD) 2> /dev/null && echo true || echo false) 459 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) 460 CACHE_MK += HAS_SYSTEM_OPENSSL_ALPN = true, 461 endif 462 HAS_SYSTEM_ZLIB ?= $(shell $(ZLIB_CHECK_CMD) 2> /dev/null && echo true || echo false) 463 ifeq ($(HAS_SYSTEM_ZLIB),true) 464 CACHE_MK += HAS_SYSTEM_ZLIB = true, 465 endif 466 HAS_SYSTEM_PROTOBUF ?= $(HAS_SYSTEM_PROTOBUF_VERIFY) 467 ifeq ($(HAS_SYSTEM_PROTOBUF),true) 468 CACHE_MK += HAS_SYSTEM_PROTOBUF = true, 469 endif 470 HAS_SYSTEM_CARES ?= $(shell $(CARES_CHECK_CMD) 2> /dev/null && echo true || echo false) 471 ifeq ($(HAS_SYSTEM_CARES),true) 472 CACHE_MK += HAS_SYSTEM_CARES = true, 473 endif 474 else 475 # override system libraries if the config requires a custom compiled library 476 HAS_SYSTEM_OPENSSL_ALPN = false 477 HAS_SYSTEM_ZLIB = false 478 HAS_SYSTEM_PROTOBUF = false 479 HAS_SYSTEM_CARES = false 480 endif 481 482 HAS_PROTOC ?= $(shell $(PROTOC_CHECK_CMD) 2> /dev/null && echo true || echo false) 483 ifeq ($(HAS_PROTOC),true) 484 CACHE_MK += HAS_PROTOC = true, 485 HAS_VALID_PROTOC ?= $(shell $(PROTOC_CHECK_VERSION_CMD) 2> /dev/null && echo true || echo false) 486 ifeq ($(HAS_VALID_PROTOC),true) 487 CACHE_MK += HAS_VALID_PROTOC = true, 488 endif 489 else 490 HAS_VALID_PROTOC = false 491 endif 492 493 # Check for Systemtap (https://sourceware.org/systemtap/), first by making sure <sys/sdt.h> is present 494 # in the system and secondly by checking for the "dtrace" binary (on Linux, this is part of the Systemtap 495 # distribution. It's part of the base system on BSD/Solaris machines). 496 ifndef HAS_SYSTEMTAP 497 HAS_SYSTEMTAP_HEADERS = $(shell $(SYSTEMTAP_HEADERS_CHECK_CMD) 2> /dev/null && echo true || echo false) 498 HAS_DTRACE = $(shell $(DTRACE_CHECK_CMD) 2> /dev/null && echo true || echo false) 499 HAS_SYSTEMTAP = false 500 ifeq ($(HAS_SYSTEMTAP_HEADERS),true) 501 ifeq ($(HAS_DTRACE),true) 502 HAS_SYSTEMTAP = true 503 endif 504 endif 505 endif 506 507 ifeq ($(HAS_SYSTEMTAP),true) 508 CACHE_MK += HAS_SYSTEMTAP = true, 509 endif 510 511 # Note that for testing purposes, one can do: 512 # make HAS_EMBEDDED_OPENSSL_ALPN=false 513 # to emulate the fact we do not have OpenSSL in the third_party folder. 514 ifneq ($(wildcard third_party/${openssl_fallback.extraction_dir}/libssl.a),) 515 HAS_EMBEDDED_OPENSSL_ALPN = third_party/${openssl_fallback.extraction_dir} 516 else ifeq ($(wildcard third_party/boringssl/include/openssl/ssl.h),) 517 HAS_EMBEDDED_OPENSSL_ALPN = false 518 else 519 CAN_COMPILE_EMBEDDED_OPENSSL ?= $(shell $(BORINGSSL_COMPILE_CHECK_CMD) 2> /dev/null && echo true || echo false) 520 HAS_EMBEDDED_OPENSSL_ALPN = $(CAN_COMPILE_EMBEDDED_OPENSSL) 521 endif 522 523 ifeq ($(wildcard third_party/zlib/zlib.h),) 524 HAS_EMBEDDED_ZLIB = false 525 else 526 HAS_EMBEDDED_ZLIB = true 527 endif 528 529 ifeq ($(wildcard third_party/protobuf/src/google/protobuf/descriptor.pb.h),) 530 HAS_EMBEDDED_PROTOBUF = false 531 ifneq ($(HAS_VALID_PROTOC),true) 532 NO_PROTOC = true 533 endif 534 else 535 HAS_EMBEDDED_PROTOBUF = true 536 endif 537 538 ifeq ($(wildcard third_party/cares/cares/ares.h),) 539 HAS_EMBEDDED_CARES = false 540 else 541 HAS_EMBEDDED_CARES = true 542 endif 543 544 PC_REQUIRES_GRPC = 545 PC_LIBS_GRPC = 546 547 ifeq ($(HAS_SYSTEM_ZLIB),false) 548 ifeq ($(HAS_EMBEDDED_ZLIB), true) 549 EMBED_ZLIB ?= true 550 else 551 DEP_MISSING += zlib 552 EMBED_ZLIB ?= broken 553 endif 554 else 555 EMBED_ZLIB ?= false 556 endif 557 558 ifeq ($(EMBED_ZLIB),true) 559 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a 560 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a 561 ZLIB_MERGE_OBJS = $(LIBZ_OBJS) 562 CPPFLAGS += -Ithird_party/zlib 563 else 564 ifeq ($(HAS_PKG_CONFIG),true) 565 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags zlib) 566 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L zlib) 567 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l zlib)) 568 PC_REQUIRES_GRPC += zlib 569 else 570 PC_LIBS_GRPC += -lz 571 LIBS += z 572 endif 573 endif 574 575 CARES_PKG_CONFIG = false 576 577 ifeq ($(HAS_SYSTEM_CARES),false) 578 ifeq ($(HAS_EMBEDDED_CARES), true) 579 EMBED_CARES ?= true 580 else 581 DEP_MISSING += cares 582 EMBED_CARES ?= broken 583 endif 584 else 585 EMBED_CARES ?= false 586 endif 587 588 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a 589 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS) 590 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a 591 CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS) 592 593 ifeq ($(EMBED_CARES),true) 594 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a 595 CARES_MERGE_OBJS = $(LIBARES_OBJS) 596 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a 597 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS) 598 else 599 ifeq ($(HAS_PKG_CONFIG),true) 600 PC_REQUIRES_GRPC += libcares 601 CPPFLAGS += $(shell $(PKG_CONFIG) --cflags libcares) 602 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libcares) 603 LIBS += $(patsubst -l%,%,$(shell $(PKG_CONFIG) --libs-only-l libcares)) 604 else 605 PC_LIBS_GRPC += -lcares 606 LIBS += cares 607 endif 608 endif 609 610 OPENSSL_PKG_CONFIG = false 611 612 PC_REQUIRES_SECURE = 613 PC_LIBS_SECURE = 614 615 ifeq ($(HAS_SYSTEM_OPENSSL_ALPN),true) 616 EMBED_OPENSSL ?= false 617 NO_SECURE ?= false 618 else # HAS_SYSTEM_OPENSSL_ALPN=false 619 ifneq ($(HAS_EMBEDDED_OPENSSL_ALPN),false) 620 EMBED_OPENSSL ?= $(HAS_EMBEDDED_OPENSSL_ALPN) 621 NO_SECURE ?= false 622 else # HAS_EMBEDDED_OPENSSL_ALPN=false 623 NO_SECURE ?= true 624 endif # HAS_EMBEDDED_OPENSSL_ALPN 625 endif # HAS_SYSTEM_OPENSSL_ALPN 626 627 OPENSSL_DEP := 628 OPENSSL_MERGE_LIBS := 629 ifeq ($(NO_SECURE),false) 630 ifeq ($(EMBED_OPENSSL),true) 631 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a 632 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a 633 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS) 634 # need to prefix these to ensure overriding system libraries 635 CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS) 636 else ifneq ($(EMBED_OPENSSL),false) 637 OPENSSL_DEP += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a 638 OPENSSL_MERGE_LIBS += $(EMBED_OPENSSL)/libssl.a $(EMBED_OPENSSL)/libcrypto.a 639 OPENSSL_MERGE_OBJS += $(wildcard $(EMBED_OPENSSL)/grpc_obj/*.o) 640 # need to prefix these to ensure overriding system libraries 641 CPPFLAGS := -I$(EMBED_OPENSSL)/include $(CPPFLAGS) 642 else # EMBED_OPENSSL=false 643 ifeq ($(HAS_PKG_CONFIG),true) 644 OPENSSL_PKG_CONFIG = true 645 PC_REQUIRES_SECURE = openssl 646 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags openssl) $(CPPFLAGS) 647 LDFLAGS_OPENSSL_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L openssl) 648 ifeq ($(SYSTEM),Linux) 649 ifneq ($(LDFLAGS_OPENSSL_PKG_CONFIG),) 650 LDFLAGS_OPENSSL_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L openssl | sed s/L/Wl,-rpath,/) 651 endif # LDFLAGS_OPENSSL_PKG_CONFIG='' 652 endif # System=Linux 653 LDFLAGS := $(LDFLAGS_OPENSSL_PKG_CONFIG) $(LDFLAGS) 654 else # HAS_PKG_CONFIG=false 655 LIBS_SECURE = $(OPENSSL_LIBS) 656 endif # HAS_PKG_CONFIG 657 ifeq ($(DISABLE_ALPN),true) 658 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 659 LIBS_SECURE = $(OPENSSL_LIBS) 660 endif # DISABLE_ALPN 661 PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE)) 662 endif # EMBED_OPENSSL 663 endif # NO_SECURE 664 665 ifeq ($(OPENSSL_PKG_CONFIG),true) 666 LDLIBS_SECURE += $(shell $(PKG_CONFIG) --libs-only-l openssl) 667 else 668 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) 669 endif 670 671 # gpr .pc file 672 PC_NAME = gpr 673 PC_DESCRIPTION = gRPC platform support library 674 PC_CFLAGS = 675 PC_REQUIRES_PRIVATE = $(PC_REQUIRES_GPR) 676 PC_LIBS_PRIVATE = $(PC_LIBS_GPR) 677 PC_LIB = -lgpr 678 GPR_PC_FILE := $(CORE_PC_TEMPLATE) 679 680 # grpc .pc file 681 PC_NAME = gRPC 682 PC_DESCRIPTION = high performance general RPC framework 683 PC_CFLAGS = 684 PC_REQUIRES_PRIVATE = gpr $(PC_REQUIRES_GRPC) $(PC_REQUIRES_SECURE) 685 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) $(PC_LIBS_SECURE) 686 PC_LIB = -lgrpc 687 GRPC_PC_FILE := $(CORE_PC_TEMPLATE) 688 689 # grpc_unsecure .pc file 690 PC_NAME = gRPC unsecure 691 PC_DESCRIPTION = high performance general RPC framework without SSL 692 PC_CFLAGS = 693 PC_REQUIRES_PRIVATE = gpr $(PC_REQUIRES_GRPC) 694 PC_LIBS_PRIVATE = $(PC_LIBS_GRPC) 695 PC_LIB = -lgrpc 696 GRPC_UNSECURE_PC_FILE := $(CORE_PC_TEMPLATE) 697 698 PROTOBUF_PKG_CONFIG = false 699 700 PC_REQUIRES_GRPCXX = 701 PC_LIBS_GRPCXX = 702 703 CPPFLAGS := -Ithird_party/googletest/googletest/include -Ithird_party/googletest/googlemock/include $(CPPFLAGS) 704 705 PROTOC_PLUGINS_ALL =\ 706 % for tgt in targets: 707 % if tgt.build == 'protoc': 708 $(BINDIR)/$(CONFIG)/${tgt.name}\ 709 % endif 710 % endfor 711 712 PROTOC_PLUGINS_DIR = $(BINDIR)/$(CONFIG) 713 714 ifeq ($(HAS_SYSTEM_PROTOBUF),true) 715 ifeq ($(HAS_PKG_CONFIG),true) 716 PROTOBUF_PKG_CONFIG = true 717 PC_REQUIRES_GRPCXX = protobuf 718 CPPFLAGS := $(shell $(PKG_CONFIG) --cflags protobuf) $(CPPFLAGS) 719 LDFLAGS_PROTOBUF_PKG_CONFIG = $(shell $(PKG_CONFIG) --libs-only-L protobuf) 720 ifeq ($(SYSTEM),Linux) 721 ifneq ($(LDFLAGS_PROTOBUF_PKG_CONFIG),) 722 LDFLAGS_PROTOBUF_PKG_CONFIG += $(shell $(PKG_CONFIG) --libs-only-L protobuf | sed s/L/Wl,-rpath,/) 723 endif 724 endif 725 else 726 PC_LIBS_GRPCXX = -lprotobuf 727 endif 728 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL) 729 else 730 ifeq ($(HAS_EMBEDDED_PROTOBUF),true) 731 PROTOBUF_DEP = $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a 732 CPPFLAGS := -Ithird_party/protobuf/src $(CPPFLAGS) 733 LDFLAGS := -L$(LIBDIR)/$(CONFIG)/protobuf $(LDFLAGS) 734 ifneq ($(USE_BUILT_PROTOC),false) 735 PROTOC = $(BINDIR)/$(CONFIG)/protobuf/protoc 736 PROTOC_PLUGINS = $(PROTOC_PLUGINS_ALL) 737 else 738 PROTOC_PLUGINS = 739 PROTOC_PLUGINS_DIR = $(prefix)/bin 740 endif 741 else 742 NO_PROTOBUF = true 743 endif 744 endif 745 746 LIBS_PROTOBUF = protobuf 747 LIBS_PROTOC = protoc protobuf 748 749 HOST_LDLIBS_PROTOC += $(addprefix -l, $(LIBS_PROTOC)) 750 751 ifeq ($(PROTOBUF_PKG_CONFIG),true) 752 LDLIBS_PROTOBUF += $(shell $(PKG_CONFIG) --libs-only-l protobuf) 753 else 754 LDLIBS_PROTOBUF += $(addprefix -l, $(LIBS_PROTOBUF)) 755 endif 756 757 # grpc++ .pc file 758 PC_NAME = gRPC++ 759 PC_DESCRIPTION = C++ wrapper for gRPC 760 PC_CFLAGS = 761 PC_REQUIRES_PRIVATE = grpc $(PC_REQUIRES_GRPCXX) 762 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) 763 PC_LIB = -lgrpc++ 764 GRPCXX_PC_FILE := $(CPP_PC_TEMPLATE) 765 766 # grpc++_unsecure .pc file 767 PC_NAME = gRPC++ unsecure 768 PC_DESCRIPTION = C++ wrapper for gRPC without SSL 769 PC_CFLAGS = 770 PC_REQUIRES_PRIVATE = grpc_unsecure $(PC_REQUIRES_GRPCXX) 771 PC_LIBS_PRIVATE = $(PC_LIBS_GRPCXX) 772 PC_LIB = -lgrpc++ 773 GRPCXX_UNSECURE_PC_FILE := $(CPP_PC_TEMPLATE) 774 775 ifeq ($(MAKECMDGOALS),clean) 776 NO_DEPS = true 777 endif 778 779 .SECONDARY = %.pb.h %.pb.cc 780 781 ifeq ($(DEP_MISSING),) 782 all: static shared plugins\ 783 % for tgt in targets: 784 % if tgt.build == 'all': 785 $(BINDIR)/$(CONFIG)/${tgt.name}\ 786 % endif 787 % endfor 788 789 dep_error: 790 @echo "You shouldn't see this message - all of your dependencies are correct." 791 else 792 all: dep_error git_update stop 793 794 dep_error: 795 @echo 796 @echo "DEPENDENCY ERROR" 797 @echo 798 @echo "You are missing system dependencies that are essential to build grpc," 799 @echo "and the third_party directory doesn't have them:" 800 @echo 801 @echo " $(DEP_MISSING)" 802 @echo 803 @echo "Installing the development packages for your system will solve" 804 @echo "this issue. Please consult INSTALL to get more information." 805 @echo 806 @echo "If you need information about why these tests failed, run:" 807 @echo 808 @echo " make run_dep_checks" 809 @echo 810 endif 811 812 git_update: 813 ifeq ($(IS_GIT_FOLDER),true) 814 @echo "Additionally, since you are in a git clone, you can download the" 815 @echo "missing dependencies in third_party by running the following command:" 816 @echo 817 @echo " git submodule update --init" 818 @echo 819 endif 820 821 openssl_dep_error: openssl_dep_message git_update stop 822 823 protobuf_dep_error: protobuf_dep_message git_update stop 824 825 protoc_dep_error: protoc_dep_message git_update stop 826 827 openssl_dep_message: 828 @echo 829 @echo "DEPENDENCY ERROR" 830 @echo 831 @echo "The target you are trying to run requires an OpenSSL implementation." 832 @echo "Your system doesn't have one, and either the third_party directory" 833 @echo "doesn't have it, or your compiler can't build BoringSSL." 834 @echo 835 @echo "Please consult INSTALL to get more information." 836 @echo 837 @echo "If you need information about why these tests failed, run:" 838 @echo 839 @echo " make run_dep_checks" 840 @echo 841 842 protobuf_dep_message: 843 @echo 844 @echo "DEPENDENCY ERROR" 845 @echo 846 @echo "The target you are trying to run requires protobuf 3.5.0+" 847 @echo "Your system doesn't have it, and neither does the third_party directory." 848 @echo 849 @echo "Please consult INSTALL to get more information." 850 @echo 851 @echo "If you need information about why these tests failed, run:" 852 @echo 853 @echo " make run_dep_checks" 854 @echo 855 856 protoc_dep_message: 857 @echo 858 @echo "DEPENDENCY ERROR" 859 @echo 860 @echo "The target you are trying to run requires protobuf-compiler 3.5.0+" 861 @echo "Your system doesn't have it, and neither does the third_party directory." 862 @echo 863 @echo "Please consult INSTALL to get more information." 864 @echo 865 @echo "If you need information about why these tests failed, run:" 866 @echo 867 @echo " make run_dep_checks" 868 @echo 869 870 systemtap_dep_error: 871 @echo 872 @echo "DEPENDENCY ERROR" 873 @echo 874 @echo "Under the '$(CONFIG)' configutation, the target you are trying " 875 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other " 876 @echo "platforms such as Solaris and *BSD). " 877 @echo 878 @echo "Please consult INSTALL to get more information." 879 @echo 880 881 stop: 882 @false 883 884 % for tgt in targets: 885 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name} 886 % endfor 887 888 run_dep_checks: 889 $(OPENSSL_ALPN_CHECK_CMD) || true 890 $(ZLIB_CHECK_CMD) || true 891 $(PERFTOOLS_CHECK_CMD) || true 892 $(PROTOBUF_CHECK_CMD) || true 893 $(PROTOC_CHECK_VERSION_CMD) || true 894 $(CARES_CHECK_CMD) || true 895 896 third_party/protobuf/configure: 897 $(E) "[AUTOGEN] Preparing protobuf" 898 $(Q)(cd third_party/protobuf ; autoreconf -f -i -Wall,no-obsolete) 899 900 $(LIBDIR)/$(CONFIG)/protobuf/libprotobuf.a: third_party/protobuf/configure 901 $(E) "[MAKE] Building protobuf" 902 $(Q)mkdir -p $(LIBDIR)/$(CONFIG)/protobuf 903 $(Q)(cd third_party/protobuf ; CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS_$(CONFIG)) -g $(PROTOBUF_LDFLAGS_EXTRA)" CPPFLAGS="$(PIC_CPPFLAGS) $(CPPFLAGS_$(CONFIG)) -g $(PROTOBUF_CPPFLAGS_EXTRA)" ./configure --disable-shared --enable-static $(PROTOBUF_CONFIG_OPTS)) 904 $(Q)$(MAKE) -C third_party/protobuf clean 905 $(Q)$(MAKE) -C third_party/protobuf 906 $(Q)mkdir -p $(BINDIR)/$(CONFIG)/protobuf 907 $(Q)cp third_party/protobuf/src/.libs/libprotoc.a $(LIBDIR)/$(CONFIG)/protobuf 908 $(Q)cp third_party/protobuf/src/.libs/libprotobuf.a $(LIBDIR)/$(CONFIG)/protobuf 909 $(Q)cp third_party/protobuf/src/protoc $(BINDIR)/$(CONFIG)/protobuf 910 911 static: static_c static_cxx 912 913 static_c: pc_c pc_c_unsecure cache.mk \ 914 % for lib in libs: 915 % if 'Makefile' in lib.get('build_system', ['Makefile']): 916 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): 917 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 918 % endif 919 % endif 920 % endfor 921 922 923 static_cxx: pc_cxx pc_cxx_unsecure cache.mk \ 924 % for lib in libs: 925 % if 'Makefile' in lib.get('build_system', ['Makefile']): 926 % if lib.build == 'all' and lib.language == 'c++': 927 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 928 % endif 929 % endif 930 % endfor 931 932 933 static_csharp: static_c \ 934 % for lib in libs: 935 % if 'Makefile' in lib.get('build_system', ['Makefile']): 936 % if lib.build == 'all' and lib.language == 'csharp': 937 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 938 % endif 939 % endif 940 % endfor 941 942 943 shared: shared_c shared_cxx 944 945 shared_c: pc_c pc_c_unsecure cache.mk\ 946 % for lib in libs: 947 % if 'Makefile' in lib.get('build_system', ['Makefile']): 948 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): 949 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\ 950 % endif 951 % endif 952 % endfor 953 954 shared_cxx: pc_cxx pc_cxx_unsecure cache.mk\ 955 % for lib in libs: 956 % if 'Makefile' in lib.get('build_system', ['Makefile']): 957 % if lib.build == 'all' and lib.language == 'c++': 958 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\ 959 % endif 960 % endif 961 % endfor 962 963 964 shared_csharp: shared_c \ 965 % for lib in libs: 966 % if 'Makefile' in lib.get('build_system', ['Makefile']): 967 % if lib.build == 'all' and lib.language == 'csharp': 968 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\ 969 % endif 970 % endif 971 % endfor 972 973 grpc_csharp_ext: shared_csharp 974 975 plugins: $(PROTOC_PLUGINS) 976 977 privatelibs: privatelibs_c privatelibs_cxx 978 979 privatelibs_c: \ 980 % for lib in libs: 981 % if 'Makefile' in lib.get('build_system', ['Makefile']): 982 % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl: 983 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 984 % endif 985 % endif 986 % endfor 987 988 pc_c: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc 989 990 pc_c_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc 991 992 pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc 993 994 pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc 995 996 ifeq ($(EMBED_OPENSSL),true) 997 privatelibs_cxx: \ 998 % for lib in libs: 999 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1000 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None): 1001 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 1002 % endif 1003 % endif 1004 % endfor 1005 1006 else 1007 privatelibs_cxx: \ 1008 % for lib in libs: 1009 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1010 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl: 1011 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 1012 % endif 1013 % endif 1014 % endfor 1015 1016 endif 1017 1018 1019 buildtests: buildtests_c buildtests_cxx 1020 1021 buildtests_c: privatelibs_c <%text>\</%text> 1022 % for tgt in targets: 1023 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None): 1024 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text> 1025 % endif 1026 % endfor 1027 1028 1029 ifeq ($(EMBED_OPENSSL),true) 1030 buildtests_cxx: privatelibs_cxx <%text>\</%text> 1031 % for tgt in targets: 1032 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None): 1033 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text> 1034 % endif 1035 % endfor 1036 1037 else 1038 buildtests_cxx: privatelibs_cxx <%text>\</%text> 1039 % for tgt in targets: 1040 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: 1041 $(BINDIR)/$(CONFIG)/${tgt.name} <%text>\</%text> 1042 % endif 1043 % endfor 1044 1045 endif 1046 1047 1048 test: test_c test_cxx 1049 1050 flaky_test: flaky_test_c flaky_test_cxx 1051 1052 test_c: buildtests_c 1053 % for tgt in targets: 1054 % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): 1055 $(E) "[RUN] Testing ${tgt.name}" 1056 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) 1057 % endif 1058 % endfor 1059 1060 1061 flaky_test_c: buildtests_c 1062 % for tgt in targets: 1063 % if tgt.build == 'test' and tgt.get('run', True) and not tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): 1064 $(E) "[RUN] Testing ${tgt.name}" 1065 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) 1066 % endif 1067 % endfor 1068 1069 1070 test_cxx: buildtests_cxx 1071 % for tgt in targets: 1072 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and not tgt.get('flaky', False) and not tgt.get('external_deps', None): 1073 $(E) "[RUN] Testing ${tgt.name}" 1074 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) 1075 % endif 1076 % endfor 1077 1078 1079 flaky_test_cxx: buildtests_cxx 1080 % for tgt in targets: 1081 % if tgt.build == 'test' and tgt.get('run', True) and tgt.language == 'c++' and tgt.get('flaky', False) and not tgt.get('external_deps', None): 1082 $(E) "[RUN] Testing ${tgt.name}" 1083 $(Q) $(BINDIR)/$(CONFIG)/${tgt.name} || ( echo test ${tgt.name} failed ; exit 1 ) 1084 % endif 1085 % endfor 1086 1087 1088 test_python: static_c 1089 $(E) "[RUN] Testing python code" 1090 $(Q) tools/run_tests/run_tests.py -lpython -c$(CONFIG) 1091 1092 1093 tools: tools_c tools_cxx 1094 1095 1096 tools_c: privatelibs_c\ 1097 % for tgt in targets: 1098 % if tgt.build == 'tool' and not tgt.language=='c++': 1099 $(BINDIR)/$(CONFIG)/${tgt.name}\ 1100 % endif 1101 % endfor 1102 1103 1104 tools_cxx: privatelibs_cxx\ 1105 % for tgt in targets: 1106 % if tgt.build == 'tool' and tgt.language=='c++': 1107 $(BINDIR)/$(CONFIG)/${tgt.name}\ 1108 % endif 1109 % endfor 1110 1111 1112 buildbenchmarks: privatelibs\ 1113 % for tgt in targets: 1114 % if tgt.build == 'benchmark': 1115 $(BINDIR)/$(CONFIG)/${tgt.name}\ 1116 % endif 1117 % endfor 1118 1119 1120 benchmarks: buildbenchmarks 1121 1122 strip: strip-static strip-shared 1123 1124 strip-static: strip-static_c strip-static_cxx 1125 1126 strip-shared: strip-shared_c strip-shared_cxx 1127 1128 1129 # TODO(nnoble): the strip target is stripping in-place, instead 1130 # of copying files in a temporary folder. 1131 # This prevents proper debugging after running make install. 1132 1133 strip-static_c: static_c 1134 ifeq ($(CONFIG),opt) 1135 % for lib in libs: 1136 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1137 % if lib.language == "c": 1138 % if lib.build == "all": 1139 % if not lib.get('external_deps', None): 1140 $(E) "[STRIP] Stripping lib${lib.name}.a" 1141 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 1142 % endif 1143 % endif 1144 % endif 1145 % endif 1146 % endfor 1147 endif 1148 1149 strip-static_cxx: static_cxx 1150 ifeq ($(CONFIG),opt) 1151 % for lib in libs: 1152 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1153 % if lib.language == "c++": 1154 % if lib.build == "all": 1155 $(E) "[STRIP] Stripping lib${lib.name}.a" 1156 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 1157 % endif 1158 % endif 1159 % endif 1160 % endfor 1161 endif 1162 1163 strip-shared_c: shared_c 1164 ifeq ($(CONFIG),opt) 1165 % for lib in libs: 1166 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1167 % if lib.language == "c": 1168 % if lib.build == "all": 1169 % if not lib.get('external_deps', None): 1170 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" 1171 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) 1172 % endif 1173 % endif 1174 % endif 1175 % endif 1176 % endfor 1177 endif 1178 1179 strip-shared_cxx: shared_cxx 1180 ifeq ($(CONFIG),opt) 1181 % for lib in libs: 1182 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1183 % if lib.language == "c++": 1184 % if lib.build == "all": 1185 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" 1186 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) 1187 % endif 1188 % endif 1189 % endif 1190 % endfor 1191 endif 1192 1193 strip-shared_csharp: shared_csharp 1194 ifeq ($(CONFIG),opt) 1195 % for lib in libs: 1196 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1197 % if lib.language == "csharp": 1198 % if lib.build == "all": 1199 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)" 1200 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) 1201 % endif 1202 % endif 1203 % endif 1204 % endfor 1205 endif 1206 1207 cache.mk:: 1208 $(E) "[MAKE] Generating $@" 1209 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ 1210 1211 $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc: 1212 $(E) "[MAKE] Generating $@" 1213 $(Q) mkdir -p $(@D) 1214 $(Q) echo "$(GPR_PC_FILE)" | tr , '\n' >$@ 1215 1216 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc: 1217 $(E) "[MAKE] Generating $@" 1218 $(Q) mkdir -p $(@D) 1219 $(Q) echo "$(GRPC_PC_FILE)" | tr , '\n' >$@ 1220 1221 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc: 1222 $(E) "[MAKE] Generating $@" 1223 $(Q) mkdir -p $(@D) 1224 $(Q) echo "$(GRPC_UNSECURE_PC_FILE)" | tr , '\n' >$@ 1225 1226 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc: 1227 $(E) "[MAKE] Generating $@" 1228 $(Q) mkdir -p $(@D) 1229 $(Q) echo "$(GRPCXX_PC_FILE)" | tr , '\n' >$@ 1230 1231 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc: 1232 $(E) "[MAKE] Generating $@" 1233 $(Q) mkdir -p $(@D) 1234 $(Q) echo "$(GRPCXX_UNSECURE_PC_FILE)" | tr , '\n' >$@ 1235 1236 % for p in protos: 1237 ifeq ($(NO_PROTOC),true) 1238 $(GENDIR)/${p}.pb.cc: protoc_dep_error 1239 $(GENDIR)/${p}.grpc.pb.cc: protoc_dep_error 1240 else 1241 <% 1242 pluginflags="" 1243 %> 1244 % if p in ["src/proto/grpc/testing/compiler_test", "src/proto/grpc/testing/echo"]: 1245 <% 1246 pluginflags="generate_mock_code=true:" 1247 %> 1248 % endif 1249 $(GENDIR)/${p}.pb.cc: ${p}.proto $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc' % q for q in proto_deps.get(p, []))} 1250 $(E) "[PROTOC] Generating protobuf CC file from $<" 1251 $(Q) mkdir -p `dirname $@` 1252 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --cpp_out=$(GENDIR) $< 1253 1254 $(GENDIR)/${p}.grpc.pb.cc: ${p}.proto $(GENDIR)/${p}.pb.cc $(PROTOBUF_DEP) $(PROTOC_PLUGINS) ${' '.join('$(GENDIR)/%s.pb.cc $(GENDIR)/%s.grpc.pb.cc' % (q,q) for q in proto_deps.get(p, []))} 1255 $(E) "[GRPC] Generating gRPC's protobuf service CC file from $<" 1256 $(Q) mkdir -p `dirname $@` 1257 $(Q) $(PROTOC) -Ithird_party/protobuf/src -I. --grpc_out=${pluginflags}$(GENDIR) --plugin=protoc-gen-grpc=$(PROTOC_PLUGINS_DIR)/grpc_cpp_plugin$(EXECUTABLE_SUFFIX) $< 1258 endif 1259 1260 % endfor 1261 1262 ifeq ($(CONFIG),stapprof) 1263 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h 1264 ifeq ($(HAS_SYSTEMTAP),true) 1265 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d 1266 $(E) "[DTRACE] Compiling $<" 1267 $(Q) mkdir -p `dirname $@` 1268 $(Q) $(DTRACE) -C -h -s $< -o $@ 1269 else 1270 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop 1271 endif 1272 endif 1273 1274 $(OBJDIR)/$(CONFIG)/%.o : %.c 1275 $(E) "[C] Compiling $<" 1276 $(Q) mkdir -p `dirname $@` 1277 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1278 1279 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc 1280 $(E) "[CXX] Compiling $<" 1281 $(Q) mkdir -p `dirname $@` 1282 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1283 1284 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc 1285 $(E) "[HOSTCXX] Compiling $<" 1286 $(Q) mkdir -p `dirname $@` 1287 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1288 1289 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc 1290 $(E) "[CXX] Compiling $<" 1291 $(Q) mkdir -p `dirname $@` 1292 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1293 1294 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc 1295 $(E) "[CXX] Compiling $<" 1296 $(Q) mkdir -p `dirname $@` 1297 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1298 1299 $(OBJDIR)/$(CONFIG)/%.o : %.cc 1300 $(E) "[CXX] Compiling $<" 1301 $(Q) mkdir -p `dirname $@` 1302 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1303 1304 $(OBJDIR)/$(CONFIG)/%.o : %.cpp 1305 $(E) "[CXX] Compiling $<" 1306 $(Q) mkdir -p `dirname $@` 1307 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1308 1309 install: install_c install_cxx install-plugins install-certs 1310 1311 install_c: install-headers_c install-static_c install-shared_c 1312 1313 install_cxx: install-headers_cxx install-static_cxx install-shared_cxx 1314 1315 install_csharp: install-shared_csharp install_c 1316 1317 install_grpc_csharp_ext: install_csharp 1318 1319 install-headers: install-headers_c install-headers_cxx 1320 1321 install-headers_c: 1322 $(E) "[INSTALL] Installing public C headers" 1323 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 1324 $(Q) $(foreach h, $(PUBLIC_HEADERS_C), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 1325 1326 install-headers_cxx: 1327 $(E) "[INSTALL] Installing public C++ headers" 1328 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) -d $(prefix)/$(dir $(h)) && ) exit 0 || exit 1 1329 $(Q) $(foreach h, $(PUBLIC_HEADERS_CXX), $(INSTALL) $(h) $(prefix)/$(h) && ) exit 0 || exit 1 1330 1331 install-static: install-static_c install-static_cxx 1332 1333 install-static_c: static_c strip-static_c install-pkg-config_c 1334 % for lib in libs: 1335 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1336 % if lib.language == "c": 1337 % if lib.build == "all": 1338 % if not lib.get('external_deps', None): 1339 $(E) "[INSTALL] Installing lib${lib.name}.a" 1340 $(Q) $(INSTALL) -d $(prefix)/lib 1341 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a 1342 % endif 1343 % endif 1344 % endif 1345 % endif 1346 % endfor 1347 1348 install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx 1349 % for lib in libs: 1350 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1351 % if lib.language == "c++": 1352 % if lib.build == "all": 1353 $(E) "[INSTALL] Installing lib${lib.name}.a" 1354 $(Q) $(INSTALL) -d $(prefix)/lib 1355 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(prefix)/lib/lib${lib.name}.a 1356 % endif 1357 % endif 1358 % endif 1359 % endfor 1360 1361 <%def name="install_shared(lang_filter)">\ 1362 % for lib in libs: 1363 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1364 % if lib.language == lang_filter: 1365 % if lib.build == "all": 1366 % if not lib.get('external_deps', None): 1367 $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})" 1368 $(Q) $(INSTALL) -d $(prefix)/lib 1369 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) 1370 ifeq ($(SYSTEM),MINGW32) 1371 $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]})-dll.a $(prefix)/lib/lib${lib.name}.a 1372 else ifneq ($(SYSTEM),Darwin) 1373 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so.${settings.core_version.major} 1374 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/lib${lib.name}.so 1375 endif 1376 % endif 1377 % endif 1378 % endif 1379 % endif 1380 % endfor 1381 ifneq ($(SYSTEM),MINGW32) 1382 ifneq ($(SYSTEM),Darwin) 1383 $(Q) ldconfig || true 1384 endif 1385 endif 1386 </%def> 1387 1388 install-shared_c: shared_c strip-shared_c install-pkg-config_c 1389 ${install_shared("c")} 1390 1391 install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx 1392 ${install_shared("c++")} 1393 1394 install-shared_csharp: shared_csharp strip-shared_csharp 1395 ${install_shared("csharp")} 1396 1397 install-plugins: $(PROTOC_PLUGINS) 1398 $(E) "[INSTALL] Installing grpc protoc plugins" 1399 % for tgt in targets: 1400 % if tgt.build == 'protoc': 1401 $(Q) $(INSTALL) -d $(prefix)/bin 1402 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/${tgt.name} $(prefix)/bin/${tgt.name} 1403 % endif 1404 % endfor 1405 1406 install-grpc-cli: grpc_cli 1407 $(E) "[INSTALL] Installing grpc cli" 1408 $(Q) $(INSTALL) -d $(prefix)/bin 1409 $(Q) $(INSTALL) $(BINDIR)/$(CONFIG)/grpc_cli $(prefix)/bin/grpc_cli 1410 1411 install-pkg-config_c: pc_c pc_c_unsecure 1412 $(E) "[INSTALL] Installing C pkg-config files" 1413 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig 1414 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/gpr.pc $(prefix)/lib/pkgconfig/gpr.pc 1415 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc.pc $(prefix)/lib/pkgconfig/grpc.pc 1416 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc_unsecure.pc $(prefix)/lib/pkgconfig/grpc_unsecure.pc 1417 1418 install-pkg-config_cxx: pc_cxx pc_cxx_unsecure 1419 $(E) "[INSTALL] Installing C++ pkg-config files" 1420 $(Q) $(INSTALL) -d $(prefix)/lib/pkgconfig 1421 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc $(prefix)/lib/pkgconfig/grpc++.pc 1422 $(Q) $(INSTALL) -m 0644 $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc $(prefix)/lib/pkgconfig/grpc++_unsecure.pc 1423 1424 install-certs: etc/roots.pem 1425 $(E) "[INSTALL] Installing root certificates" 1426 $(Q) $(INSTALL) -d $(prefix)/share/grpc 1427 $(Q) $(INSTALL) etc/roots.pem $(prefix)/share/grpc/roots.pem 1428 1429 clean: 1430 $(E) "[CLEAN] Cleaning build directories." 1431 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk 1432 1433 1434 # The various libraries 1435 1436 % for lib in libs: 1437 % if 'Makefile' in lib.get('build_system', ['Makefile']): 1438 ${makelib(lib)} 1439 % endif 1440 % endfor 1441 1442 1443 # All of the test targets, and protoc plugins 1444 1445 % for tgt in targets: 1446 ${maketarget(tgt)} 1447 % endfor 1448 1449 <%def name="makelib(lib)"> 1450 LIB${lib.name.upper()}_SRC = \\ 1451 1452 % for src in lib.src: 1453 ${proto_to_cc(src)} \\ 1454 1455 % endfor 1456 1457 % if "public_headers" in lib: 1458 % if lib.language == "c++": 1459 PUBLIC_HEADERS_CXX += \\ 1460 1461 % else: 1462 PUBLIC_HEADERS_C += \\ 1463 1464 % endif 1465 % for hdr in lib.public_headers: 1466 ${hdr} \\ 1467 1468 % endfor 1469 % endif 1470 1471 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC)))) 1472 1473 % if lib.get('defaults', None): 1474 % for name, value in defaults.get(lib.defaults).iteritems(): 1475 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value} 1476 % endfor 1477 % endif 1478 1479 ## If the library requires OpenSSL, let's add some restrictions. 1480 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1481 ifeq ($(NO_SECURE),true) 1482 1483 # You can't build secure libraries if you don't have OpenSSL. 1484 1485 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error 1486 1487 % if lib.build == "all": 1488 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error 1489 % endif 1490 1491 else 1492 1493 % if lib.language == 'c++': 1494 ifeq ($(NO_PROTOBUF),true) 1495 1496 # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. 1497 1498 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error 1499 1500 % if lib.build == "all": 1501 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error 1502 % endif 1503 1504 else 1505 % endif 1506 1507 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)\ 1508 ## The else here corresponds to the if secure earlier. 1509 % else: 1510 % if lib.language == 'c++': 1511 ifeq ($(NO_PROTOBUF),true) 1512 1513 # You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. 1514 1515 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: protobuf_dep_error 1516 1517 % if lib.build == "all": 1518 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): protobuf_dep_error 1519 % endif 1520 1521 else 1522 1523 % endif 1524 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \ 1525 % if lib.name not in ['z', 'ares', 'address_sorting']: 1526 $(ZLIB_DEP) \ 1527 $(CARES_DEP) \ 1528 $(ADDRESS_SORTING_DEP) \ 1529 % endif 1530 % endif 1531 % if lib.language == 'c++': 1532 $(PROTOBUF_DEP)\ 1533 % endif 1534 $(LIB${lib.name.upper()}_OBJS) \ 1535 % if lib.get('baselib', False): 1536 $(LIBGPR_OBJS) \ 1537 $(ZLIB_MERGE_OBJS) \ 1538 $(CARES_MERGE_OBJS) \ 1539 $(ADDRESS_SORTING_MERGE_OBJS) \ 1540 % if lib.get('secure', 'check') == True: 1541 $(OPENSSL_MERGE_OBJS) \ 1542 % endif 1543 % endif 1544 1545 $(E) "[AR] Creating $@" 1546 $(Q) mkdir -p `dirname $@` 1547 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 1548 $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \ 1549 % if lib.get('baselib', False): 1550 $(LIBGPR_OBJS) \ 1551 $(ZLIB_MERGE_OBJS) \ 1552 $(CARES_MERGE_OBJS) \ 1553 $(ADDRESS_SORTING_MERGE_OBJS) \ 1554 % if lib.get('secure', 'check') == True: 1555 $(OPENSSL_MERGE_OBJS) \ 1556 % endif 1557 % endif 1558 1559 ifeq ($(SYSTEM),Darwin) 1560 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 1561 endif 1562 1563 <% 1564 1565 if lib.language == 'c++': 1566 ld = '$(LDXX)' 1567 else: 1568 ld = '$(LD)' 1569 1570 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')' 1571 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')' 1572 1573 common = '$(LIB' + lib.name.upper() + '_OBJS)' 1574 1575 link_libs = '' 1576 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)' 1577 mingw_libs = '' 1578 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP)' 1579 if lib.language == 'c++': 1580 lib_deps += ' $(PROTOBUF_DEP)' 1581 mingw_lib_deps += ' $(PROTOBUF_DEP)' 1582 if lib.get('deps_linkage', None) == 'static': 1583 for dep in lib.get('deps', []): 1584 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a' 1585 common = common + ' ' + lib_archive 1586 lib_deps = lib_deps + ' ' + lib_archive 1587 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive 1588 else: 1589 for dep in lib.get('deps', []): 1590 dep_lib = None 1591 for dl in libs: 1592 if dl.name == dep: 1593 dep_lib = dl 1594 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name) 1595 link_libs = link_libs + ' -l' + dep 1596 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')' 1597 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll' 1598 mingw_lib_deps = mingw_lib_deps + ' $(LIBDIR)/$(CONFIG)/' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ').$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')' 1599 1600 security = lib.get('secure', 'check') 1601 if security == True: 1602 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' 1603 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS)' 1604 1605 if security in [True, 'check']: 1606 for src in lib.src: 1607 if not proto_re.match(src): 1608 sources_that_need_openssl.add(src) 1609 else: 1610 for src in lib.src: 1611 sources_that_don_t_need_openssl.add(src) 1612 1613 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1614 lib_deps = lib_deps + ' $(OPENSSL_DEP)' 1615 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)' 1616 1617 if lib.language == 'c++': 1618 common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)' 1619 1620 ldflags = '$(LDFLAGS)' 1621 if lib.get('LDFLAGS', None): 1622 ldflags += ' ' + lib['LDFLAGS'] 1623 1624 common = common + ' $(LDLIBS)' 1625 %> 1626 1627 % if lib.build == "all": 1628 ifeq ($(SYSTEM),MINGW32) 1629 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps} 1630 $(E) "[LD] Linking $@" 1631 $(Q) mkdir -p `dirname $@` 1632 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_mingbase}.def -Wl,--out-implib=${out_libbase}-dll.a -o ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${mingw_libs} 1633 else 1634 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps} 1635 $(E) "[LD] Linking $@" 1636 $(Q) mkdir -p `dirname $@` 1637 ifeq ($(SYSTEM),Darwin) 1638 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs} 1639 else 1640 $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs} 1641 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} 1642 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so 1643 endif 1644 endif 1645 % endif 1646 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1647 ## If the lib was secure, we have to close the Makefile's if that tested 1648 ## the presence of OpenSSL. 1649 1650 endif 1651 % endif 1652 % if lib.language == 'c++': 1653 ## If the lib was C++, we have to close the Makefile's if that tested 1654 ## the presence of protobuf 3.5.0+ 1655 1656 endif 1657 % endif 1658 1659 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1660 ifneq ($(NO_SECURE),true) 1661 % endif 1662 ifneq ($(NO_DEPS),true) 1663 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep) 1664 endif 1665 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1666 endif 1667 % endif 1668 % for src in lib.src: 1669 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in lib.src): 1670 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in lib.src if proto_re.match(src2))} 1671 % endif 1672 % endfor 1673 </%def> 1674 1675 <%def name="maketarget(tgt)"><% has_no_sources = not tgt.src %> 1676 % if not has_no_sources: 1677 ${tgt.name.upper()}_SRC = \\ 1678 1679 % for src in tgt.src: 1680 ${proto_to_cc(src)} \\ 1681 1682 % endfor 1683 1684 ${tgt.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(${tgt.name.upper()}_SRC)))) 1685 % endif 1686 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': 1687 ifeq ($(NO_SECURE),true) 1688 1689 # You can't build secure targets if you don't have OpenSSL. 1690 1691 $(BINDIR)/$(CONFIG)/${tgt.name}: openssl_dep_error 1692 1693 else 1694 1695 % endif 1696 1697 % if tgt.boringssl: 1698 # boringssl needs an override to ensure that it does not include 1699 # system openssl headers regardless of other configuration 1700 # we do so here with a target specific variable assignment 1701 $(${tgt.name.upper()}_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) 1702 $(${tgt.name.upper()}_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) 1703 $(${tgt.name.upper()}_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE 1704 % else: 1705 % endif 1706 1707 ## 1708 ## We're not trying to add a dependency on building zlib and openssl here, 1709 ## as it's already done in the libraries. We're assuming that the build 1710 ## trickles down, and that a secure target requires a secure version of 1711 ## a library. 1712 ## 1713 ## That simplifies the codegen a bit, but prevents a fully defined Makefile. 1714 ## I can live with that. 1715 ## 1716 % if tgt.build == 'protoc' or tgt.language == 'c++': 1717 1718 ifeq ($(NO_PROTOBUF),true) 1719 1720 # You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. 1721 1722 $(BINDIR)/$(CONFIG)/${tgt.name}: protobuf_dep_error 1723 1724 else 1725 1726 $(BINDIR)/$(CONFIG)/${tgt.name}: \ 1727 % if not has_no_sources: 1728 $(PROTOBUF_DEP) $(${tgt.name.upper()}_OBJS)\ 1729 % endif 1730 % else: 1731 $(BINDIR)/$(CONFIG)/${tgt.name}: \ 1732 % if not has_no_sources: 1733 $(${tgt.name.upper()}_OBJS)\ 1734 % endif 1735 % endif 1736 % for dep in tgt.deps: 1737 $(LIBDIR)/$(CONFIG)/lib${dep}.a\ 1738 % endfor 1739 1740 % if tgt.language == "c++" or tgt.boringssl or tgt.build == 'fuzzer': 1741 ## C++ targets specificies. 1742 % if tgt.build == 'protoc': 1743 $(E) "[HOSTLD] Linking $@" 1744 $(Q) mkdir -p `dirname $@` 1745 $(Q) $(HOST_LDXX) $(HOST_LDFLAGS) \ 1746 % if not has_no_sources: 1747 $(${tgt.name.upper()}_OBJS)\ 1748 % endif 1749 % else: 1750 $(E) "[LD] Linking $@" 1751 $(Q) mkdir -p `dirname $@` 1752 $(Q) $(LDXX) $(LDFLAGS) \ 1753 % if not has_no_sources: 1754 $(${tgt.name.upper()}_OBJS)\ 1755 % endif 1756 % endif 1757 % else: 1758 ## C-only targets specificities. 1759 $(E) "[LD] Linking $@" 1760 $(Q) mkdir -p `dirname $@` 1761 $(Q) $(LD) $(LDFLAGS) \ 1762 % if not has_no_sources: 1763 $(${tgt.name.upper()}_OBJS)\ 1764 % endif 1765 % endif 1766 % for dep in tgt.deps: 1767 $(LIBDIR)/$(CONFIG)/lib${dep}.a\ 1768 % endfor 1769 % if tgt.language == "c++": 1770 % if tgt.build == 'protoc': 1771 $(HOST_LDLIBSXX) $(HOST_LDLIBS_PROTOC)\ 1772 % else: 1773 $(LDLIBSXX) $(LDLIBS_PROTOBUF)\ 1774 % endif 1775 % endif 1776 % if tgt.build == 'protoc': 1777 $(HOST_LDLIBS)\ 1778 % else: 1779 $(LDLIBS)\ 1780 % endif 1781 % if tgt.build == 'protoc': 1782 $(HOST_LDLIBS_PROTOC)\ 1783 % elif tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': 1784 $(LDLIBS_SECURE)\ 1785 % endif 1786 % if tgt.language == 'c++' and tgt.build == 'test': 1787 $(GTEST_LIB)\ 1788 % elif tgt.language == 'c++' and tgt.build == 'benchmark': 1789 $(GTEST_LIB)\ 1790 % endif 1791 % if tgt.build == 'fuzzer': 1792 -lFuzzer\ 1793 % endif 1794 -o $(BINDIR)/$(CONFIG)/${tgt.name} 1795 % if tgt.build == 'protoc' or tgt.language == 'c++': 1796 1797 endif 1798 % endif 1799 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': 1800 1801 endif 1802 % endif 1803 1804 % if tgt.get('defaults', None): 1805 % for name, value in defaults.get(tgt.defaults).iteritems(): 1806 $(${tgt.name.upper()}_OBJS): ${name} += ${value} 1807 % endfor 1808 % endif 1809 % for src in tgt.src: 1810 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: \ 1811 % for dep in tgt.deps: 1812 $(LIBDIR)/$(CONFIG)/lib${dep}.a\ 1813 % endfor 1814 1815 % if tgt.language == 'c89': 1816 % for src in tgt.src: 1817 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o : ${src} 1818 $(E) "[C] Compiling $<" 1819 $(Q) mkdir -p `dirname $@` 1820 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -std=c89 -pedantic -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 1821 % endfor 1822 % endif 1823 1824 % endfor 1825 % if not has_no_sources: 1826 deps_${tgt.name}: $(${tgt.name.upper()}_OBJS:.o=.dep) 1827 % endif 1828 1829 % if not has_no_sources: 1830 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': 1831 ifneq ($(NO_SECURE),true) 1832 % endif 1833 ifneq ($(NO_DEPS),true) 1834 -include $(${tgt.name.upper()}_OBJS:.o=.dep) 1835 endif 1836 % if tgt.get('secure', 'check') == True or tgt.get('secure', 'check') == 'check': 1837 endif 1838 % endif 1839 % endif 1840 % for src in tgt.src: 1841 % if not proto_re.match(src) and any(proto_re.match(src2) for src2 in tgt.src): 1842 $(OBJDIR)/$(CONFIG)/${os.path.splitext(src)[0]}.o: ${' '.join(proto_to_cc(src2) for src2 in tgt.src if proto_re.match(src2))} 1843 % endif 1844 % endfor 1845 </%def> 1846 1847 ifneq ($(OPENSSL_DEP),) 1848 # This is to ensure the embedded OpenSSL is built beforehand, properly 1849 # installing headers to their final destination on the drive. We need this 1850 # otherwise parallel compilation will fail if a source is compiled first. 1851 % for src in sorted(sources_that_need_openssl): 1852 % if src not in sources_that_don_t_need_openssl: 1853 ${src}: $(OPENSSL_DEP) 1854 % endif 1855 % endfor 1856 endif 1857 1858 .PHONY: all strip tools \ 1859 dep_error openssl_dep_error openssl_dep_message git_update stop \ 1860 buildtests buildtests_c buildtests_cxx \ 1861 test test_c test_cxx \ 1862 install install_c install_cxx \ 1863 install-headers install-headers_c install-headers_cxx \ 1864 install-shared install-shared_c install-shared_cxx \ 1865 install-static install-static_c install-static_cxx \ 1866 strip strip-shared strip-static \ 1867 strip_c strip-shared_c strip-static_c \ 1868 strip_cxx strip-shared_cxx strip-static_cxx \ 1869 dep_c dep_cxx bins_dep_c bins_dep_cxx \ 1870 clean 1871 1872 .PHONY: printvars 1873 printvars: 1874 @$(foreach V,$(sort $(.VARIABLES)), \ 1875 $(if $(filter-out environment% default automatic, \ 1876 $(origin $V)),$(warning $V=$($V) ($(value $V))))) 1877