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 def is_absl_lib(target_name): 28 return target_name.startswith("absl/"); 29 30 sources_that_need_openssl = set() 31 sources_that_don_t_need_openssl = set() 32 33 # warnings we'd like, but that don't exist in all compilers 34 PREFERRED_WARNINGS=['extra-semi'] 35 CHECK_WARNINGS=PREFERRED_WARNINGS + ['no-shift-negative-value', 'no-unused-but-set-variable', 'no-maybe-uninitialized', 'no-unknown-warning-option'] 36 37 def warning_var(fmt, warning): 38 return fmt % warning.replace('-', '_').replace('+', 'X').upper() 39 40 def neg_warning(warning): 41 if warning[0:3] == 'no-': 42 return warning[3:] 43 else: 44 return 'no-' + warning 45 46 lang_to_var = { 47 'c': 'CORE', 48 'c++': 'CPP', 49 'csharp': 'CSHARP' 50 } 51 %> 52 <% 53 # Makefile is only intended for internal needs (building distribution artifacts etc.) 54 # so we can restrict the number of libraries/targets that are buildable using the Makefile. 55 # Other targets can be built with cmake or bazel. 56 # TODO(jtattermusch): Figure out how to avoid the need to list the dependencies explicitly. 57 # Currently it is necessary because some dependencies are marked as "build: private" in build.yaml 58 # (which itself is correct, as they are not "public" libraries from our perspective and cmake 59 # needs to have them marked as such) 60 filtered_libs = [lib for lib in libs if (lib.build in ['all'] and lib.language != 'c++') or lib.name in ['ares', 'boringssl', 're2', 'upb', 'z']] 61 filtered_targets = [tgt for tgt in targets if tgt.build in ['all'] and lib.language != 'c++'] 62 %> 63 64 comma := , 65 66 67 # Basic platform detection 68 HOST_SYSTEM = $(shell uname | cut -f 1 -d_) 69 SYSTEM ?= $(HOST_SYSTEM) 70 ifeq ($(SYSTEM),MSYS) 71 SYSTEM = MINGW32 72 endif 73 ifeq ($(SYSTEM),MINGW64) 74 SYSTEM = MINGW32 75 endif 76 77 # Basic machine detection 78 HOST_MACHINE = $(shell uname -m) 79 ifeq ($(HOST_MACHINE),x86_64) 80 HOST_IS_X86_64 = true 81 else 82 HOST_IS_X86_64 = false 83 endif 84 85 MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) 86 ifndef BUILDDIR 87 BUILDDIR_ABSOLUTE = $(patsubst %/,%,$(dir $(MAKEFILE_PATH))) 88 else 89 BUILDDIR_ABSOLUTE = $(abspath $(BUILDDIR)) 90 endif 91 92 HAS_GCC = $(shell which gcc > /dev/null 2> /dev/null && echo true || echo false) 93 HAS_CC = $(shell which cc > /dev/null 2> /dev/null && echo true || echo false) 94 HAS_CLANG = $(shell which clang > /dev/null 2> /dev/null && echo true || echo false) 95 96 ifeq ($(HAS_CC),true) 97 DEFAULT_CC = cc 98 DEFAULT_CXX = c++ 99 else 100 ifeq ($(HAS_GCC),true) 101 DEFAULT_CC = gcc 102 DEFAULT_CXX = g++ 103 else 104 ifeq ($(HAS_CLANG),true) 105 DEFAULT_CC = clang 106 DEFAULT_CXX = clang++ 107 else 108 DEFAULT_CC = no_c_compiler 109 DEFAULT_CXX = no_c++_compiler 110 endif 111 endif 112 endif 113 114 115 BINDIR = $(BUILDDIR_ABSOLUTE)/bins 116 OBJDIR = $(BUILDDIR_ABSOLUTE)/objs 117 LIBDIR = $(BUILDDIR_ABSOLUTE)/libs 118 GENDIR = $(BUILDDIR_ABSOLUTE)/gens 119 120 # Configurations (as defined under "configs" section in build_handwritten.yaml) 121 122 % for name, args in configs.items(): 123 VALID_CONFIG_${name} = 1 124 % if args.get('compile_the_world', False): 125 REQUIRE_CUSTOM_LIBRARIES_${name} = 1 126 % endif 127 % for tool, default in [('CC', 'CC'), ('CXX', 'CXX'), ('LD', 'CC'), ('LDXX', 'CXX')]: 128 ${tool}_${name} = ${args.get(tool, '$(DEFAULT_%s)' % default)} 129 % endfor 130 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES']: 131 % if args.get(arg, None) is not None: 132 ${arg}_${name} = ${args.get(arg)} 133 % endif 134 % endfor 135 136 % endfor 137 138 139 # General settings. 140 # You may want to change these depending on your system. 141 142 prefix ?= /usr/local 143 144 DTRACE ?= dtrace 145 CONFIG ?= opt 146 # Doing X ?= Y is the same as: 147 # ifeq ($(origin X), undefined) 148 # X = Y 149 # endif 150 # but some variables, such as CC, CXX, LD or AR, have defaults. 151 # So instead of using ?= on them, we need to check their origin. 152 # See: 153 # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html 154 # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d 155 # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html 156 ifeq ($(origin CC), default) 157 CC = $(CC_$(CONFIG)) 158 endif 159 ifeq ($(origin CXX), default) 160 CXX = $(CXX_$(CONFIG)) 161 endif 162 ifeq ($(origin LD), default) 163 LD = $(LD_$(CONFIG)) 164 endif 165 LDXX ?= $(LDXX_$(CONFIG)) 166 ARFLAGS ?= rcs 167 ifeq ($(SYSTEM),Linux) 168 ifeq ($(origin AR), default) 169 AR = ar 170 endif 171 STRIP ?= strip --strip-unneeded 172 else 173 ifeq ($(SYSTEM),Darwin) 174 ifeq ($(origin AR), default) 175 AR = libtool 176 ARFLAGS = -no_warning_for_no_symbols -o 177 endif 178 STRIP ?= strip -x 179 else 180 ifeq ($(SYSTEM),MINGW32) 181 ifeq ($(origin AR), default) 182 AR = ar 183 endif 184 STRIP ?= strip --strip-unneeded 185 else 186 ifeq ($(origin AR), default) 187 AR = ar 188 endif 189 STRIP ?= strip 190 endif 191 endif 192 endif 193 INSTALL ?= install 194 RM ?= rm -f 195 PKG_CONFIG ?= pkg-config 196 197 ifndef VALID_CONFIG_$(CONFIG) 198 $(error Invalid CONFIG value '$(CONFIG)') 199 endif 200 201 ifeq ($(SYSTEM),Linux) 202 TMPOUT = /dev/null 203 else 204 TMPOUT = `mktemp /tmp/test-out-XXXXXX` 205 endif 206 207 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 208 HAS_WORKING_NO_CXX14_COMPAT = $(shell $(CHECK_NO_CXX14_COMPAT_WORKS_CMD) 2> /dev/null && echo true || echo false) 209 ifeq ($(HAS_WORKING_NO_CXX14_COMPAT),true) 210 W_NO_CXX14_COMPAT=-Wno-c++14-compat 211 endif 212 213 %for warning in CHECK_WARNINGS: 214 ${warning_var('CHECK_%s_WORKS_CMD', warning)} = $(CC) -std=c99 -Werror -W${warning} -o $(TMPOUT) -c test/build/${warning}.c 215 ${warning_var('HAS_WORKING_%s', warning)} = $(shell $(${warning_var('CHECK_%s_WORKS_CMD', warning)}) 2> /dev/null && echo true || echo false) 216 ifeq ($(${warning_var('HAS_WORKING_%s', warning)}),true) 217 ${warning_var('W_%s', warning)}=-W${warning} 218 ${warning_var('NO_W_%s', warning)}=-W${neg_warning(warning)} 219 endif 220 %endfor 221 222 # The HOST compiler settings are used to compile the protoc plugins. 223 # In most cases, you won't have to change anything, but if you are 224 # cross-compiling, you can override these variables from GNU make's 225 # command line: make CC=cross-gcc HOST_CC=gcc 226 227 HOST_CC ?= $(CC) 228 HOST_CXX ?= $(CXX) 229 HOST_LD ?= $(LD) 230 HOST_LDXX ?= $(LDXX) 231 232 CFLAGS += -std=c99 ${' '.join(warning_var('$(W_%s)', warning) for warning in PREFERRED_WARNINGS)} 233 CXXFLAGS += -std=c++11 234 ifeq ($(SYSTEM),Darwin) 235 CXXFLAGS += -stdlib=libc++ 236 LDFLAGS += -framework CoreFoundation 237 endif 238 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'COREFLAGS', 'LDFLAGS', 'DEFINES']: 239 % if defaults.get('global', []).get(arg, None) is not None: 240 ${arg} += ${defaults.get('global').get(arg)} 241 % endif 242 % endfor 243 244 CPPFLAGS += $(CPPFLAGS_$(CONFIG)) 245 CFLAGS += $(CFLAGS_$(CONFIG)) 246 CXXFLAGS += $(CXXFLAGS_$(CONFIG)) 247 DEFINES += $(DEFINES_$(CONFIG)) INSTALL_PREFIX=\"$(prefix)\" 248 LDFLAGS += $(LDFLAGS_$(CONFIG)) 249 250 ifneq ($(SYSTEM),MINGW32) 251 PIC_CPPFLAGS = -fPIC 252 CPPFLAGS += -fPIC 253 LDFLAGS += -fPIC 254 endif 255 256 INCLUDES = . include $(GENDIR) 257 LDFLAGS += -Llibs/$(CONFIG) 258 259 ifeq ($(SYSTEM),Darwin) 260 ifneq ($(wildcard /usr/local/ssl/include),) 261 INCLUDES += /usr/local/ssl/include 262 endif 263 ifneq ($(wildcard /opt/local/include),) 264 INCLUDES += /opt/local/include 265 endif 266 ifneq ($(wildcard /usr/local/include),) 267 INCLUDES += /usr/local/include 268 endif 269 LIBS = m z 270 ifneq ($(wildcard /usr/local/ssl/lib),) 271 LDFLAGS += -L/usr/local/ssl/lib 272 endif 273 ifneq ($(wildcard /opt/local/lib),) 274 LDFLAGS += -L/opt/local/lib 275 endif 276 ifneq ($(wildcard /usr/local/lib),) 277 LDFLAGS += -L/usr/local/lib 278 endif 279 endif 280 281 ifeq ($(SYSTEM),Linux) 282 LIBS = dl rt m pthread 283 LDFLAGS += -pthread 284 endif 285 286 ifeq ($(SYSTEM),MINGW32) 287 LIBS = m pthread ws2_32 dbghelp 288 LDFLAGS += -pthread 289 endif 290 291 # 292 # The steps for cross-compiling are as follows: 293 # First, clone and make install of grpc using the native compilers for the host. 294 # Also, install protoc (e.g., from a package like apt-get) 295 # Then clone a fresh grpc for the actual cross-compiled build 296 # Set the environment variable GRPC_CROSS_COMPILE to true 297 # Set CC, CXX, LD, LDXX, AR, and STRIP to the cross-compiling binaries 298 # Also set PROTOBUF_CONFIG_OPTS to indicate cross-compilation to protobuf (e.g., 299 # PROTOBUF_CONFIG_OPTS="--host=arm-linux --with-protoc=/usr/local/bin/protoc" ) 300 # Set HAS_PKG_CONFIG=false 301 # To build tests, go to third_party/gflags and follow its ccmake instructions 302 # Make sure that you enable building shared libraries and set your prefix to 303 # something useful like /usr/local/cross 304 # You will also need to set GRPC_CROSS_LDOPTS and GRPC_CROSS_AROPTS to hold 305 # additional required arguments for LD and AR (examples below) 306 # Then you can do a make from the cross-compiling fresh clone! 307 # 308 ifeq ($(GRPC_CROSS_COMPILE),true) 309 LDFLAGS += $(GRPC_CROSS_LDOPTS) # e.g. -L/usr/local/lib -L/usr/local/cross/lib 310 ARFLAGS += $(GRPC_CROSS_AROPTS) # e.g., rc --target=elf32-little 311 USE_BUILT_PROTOC = false 312 endif 313 314 # V=1 can be used to print commands run by make 315 ifeq ($(V),1) 316 E = @: 317 Q = 318 else 319 E = @echo 320 Q = @ 321 endif 322 323 CORE_VERSION = ${settings.core_version} 324 CPP_VERSION = ${settings.cpp_version} 325 CSHARP_VERSION = ${settings.csharp_version} 326 327 CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) $(addprefix -D, $(DEFINES)) 328 CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS) 329 330 LDFLAGS += $(ARCH_FLAGS) 331 LDLIBS += $(addprefix -l, $(LIBS)) 332 LDLIBSXX += $(addprefix -l, $(LIBSXX)) 333 334 335 % for arg in ['CFLAGS', 'CXXFLAGS', 'CPPFLAGS', 'LDFLAGS', 'DEFINES', 'LDLIBS']: 336 ${arg} += $(EXTRA_${arg}) 337 % endfor 338 339 HOST_CPPFLAGS += $(CPPFLAGS) 340 HOST_CFLAGS += $(CFLAGS) 341 HOST_CXXFLAGS += $(CXXFLAGS) 342 HOST_LDFLAGS += $(LDFLAGS) 343 HOST_LDLIBS += $(LDLIBS) 344 345 # These are automatically computed variables. 346 # There shouldn't be any need to change anything from now on. 347 348 -include cache.mk 349 350 CACHE_MK = 351 352 ifeq ($(SYSTEM),MINGW32) 353 EXECUTABLE_SUFFIX = .exe 354 SHARED_EXT_CORE = dll 355 SHARED_EXT_CPP = dll 356 SHARED_EXT_CSHARP = dll 357 SHARED_PREFIX = 358 SHARED_VERSION_CORE = -${settings.core_version.major} 359 SHARED_VERSION_CPP = -${settings.cpp_version.major} 360 SHARED_VERSION_CSHARP = -${settings.csharp_version.major} 361 else ifeq ($(SYSTEM),Darwin) 362 EXECUTABLE_SUFFIX = 363 SHARED_EXT_CORE = dylib 364 SHARED_EXT_CPP = dylib 365 SHARED_EXT_CSHARP = dylib 366 SHARED_PREFIX = lib 367 SHARED_VERSION_CORE = 368 SHARED_VERSION_CPP = 369 SHARED_VERSION_CSHARP = 370 else 371 EXECUTABLE_SUFFIX = 372 SHARED_EXT_CORE = so.$(CORE_VERSION) 373 SHARED_EXT_CPP = so.$(CPP_VERSION) 374 SHARED_EXT_CSHARP = so.$(CSHARP_VERSION) 375 SHARED_PREFIX = lib 376 SHARED_VERSION_CORE = 377 SHARED_VERSION_CPP = 378 SHARED_VERSION_CSHARP = 379 endif 380 381 ifeq ($(wildcard .git),) 382 IS_GIT_FOLDER = false 383 else 384 IS_GIT_FOLDER = true 385 endif 386 387 # Setup zlib dependency 388 389 ifeq ($(wildcard third_party/zlib/zlib.h),) 390 HAS_EMBEDDED_ZLIB = false 391 else 392 HAS_EMBEDDED_ZLIB = true 393 endif 394 395 # for zlib, we support building both from submodule 396 # and from system-installed zlib. In some builds, 397 # embedding zlib is not desirable. 398 # By default we use the system zlib (to match legacy behavior) 399 EMBED_ZLIB ?= false 400 401 ifeq ($(EMBED_ZLIB),true) 402 ZLIB_DEP = $(LIBDIR)/$(CONFIG)/libz.a 403 ZLIB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libz.a 404 ZLIB_MERGE_OBJS = $(LIBZ_OBJS) 405 CPPFLAGS += -Ithird_party/zlib 406 else 407 LIBS += z 408 endif 409 410 # Setup c-ares dependency 411 412 ifeq ($(wildcard third_party/cares/cares/ares.h),) 413 HAS_EMBEDDED_CARES = false 414 else 415 HAS_EMBEDDED_CARES = true 416 endif 417 418 ifeq ($(HAS_EMBEDDED_CARES),true) 419 EMBED_CARES ?= true 420 else 421 # only building with c-ares from submodule is supported 422 DEP_MISSING += cares 423 EMBED_CARES ?= broken 424 endif 425 426 ifeq ($(EMBED_CARES),true) 427 CARES_DEP = $(LIBDIR)/$(CONFIG)/libares.a 428 CARES_MERGE_OBJS = $(LIBARES_OBJS) 429 CARES_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libares.a 430 CPPFLAGS := -Ithird_party/cares -Ithird_party/cares/cares $(CPPFLAGS) 431 endif 432 433 # Setup address_sorting dependency 434 435 ADDRESS_SORTING_DEP = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a 436 ADDRESS_SORTING_MERGE_OBJS = $(LIBADDRESS_SORTING_OBJS) 437 ADDRESS_SORTING_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libaddress_sorting.a 438 CPPFLAGS := -Ithird_party/address_sorting/include $(CPPFLAGS) 439 440 # Setup abseil dependency 441 442 GRPC_ABSEIL_DEP = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a 443 GRPC_ABSEIL_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libgrpc_abseil.a 444 ifeq ($(HOST_IS_X86_64),true) 445 ABSL_RANDOM_HWAES_FLAGS = -maes -msse4 446 else 447 ABSL_RANDOM_HWAES_FLAGS = 448 endif 449 450 # Setup re2 dependency 451 452 RE2_DEP = $(LIBDIR)/$(CONFIG)/libre2.a 453 RE2_MERGE_OBJS = $(LIBRE2_OBJS) 454 RE2_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libre2.a 455 456 # Setup upb dependency 457 458 UPB_DEP = $(LIBDIR)/$(CONFIG)/libupb.a 459 UPB_MERGE_OBJS = $(LIBUPB_OBJS) 460 UPB_MERGE_LIBS = $(LIBDIR)/$(CONFIG)/libupb.a 461 462 # Setup boringssl dependency 463 464 ifeq ($(wildcard third_party/boringssl-with-bazel/src/include/openssl/ssl.h),) 465 HAS_EMBEDDED_OPENSSL = false 466 else 467 HAS_EMBEDDED_OPENSSL = true 468 endif 469 470 ifeq ($(HAS_EMBEDDED_OPENSSL),true) 471 EMBED_OPENSSL ?= true 472 else 473 # only support building boringssl from submodule 474 DEP_MISSING += openssl 475 EMBED_OPENSSL ?= broken 476 endif 477 478 ifeq ($(EMBED_OPENSSL),true) 479 OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a 480 OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a 481 OPENSSL_MERGE_OBJS += $(LIBBORINGSSL_OBJS) 482 # need to prefix these to ensure overriding system libraries 483 CPPFLAGS := -Ithird_party/boringssl-with-bazel/src/include $(CPPFLAGS) 484 ifeq ($(DISABLE_ALPN),true) 485 CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 486 LIBS_SECURE = $(OPENSSL_LIBS) 487 endif # DISABLE_ALPN 488 endif # EMBED_OPENSSL 489 490 LDLIBS_SECURE += $(addprefix -l, $(LIBS_SECURE)) 491 492 ifeq ($(MAKECMDGOALS),clean) 493 NO_DEPS = true 494 endif 495 496 .SECONDARY = %.pb.h %.pb.cc 497 498 ifeq ($(DEP_MISSING),) 499 all: static shared\ 500 % for tgt in filtered_targets: 501 % if tgt.build == 'all': 502 $(BINDIR)/$(CONFIG)/${tgt.name}\ 503 % endif 504 % endfor 505 506 dep_error: 507 @echo "You shouldn't see this message - all of your dependencies are correct." 508 else 509 all: dep_error git_update stop 510 511 dep_error: 512 @echo 513 @echo "DEPENDENCY ERROR" 514 @echo 515 @echo "You are missing system dependencies that are essential to build grpc," 516 @echo "and the third_party directory doesn't have them:" 517 @echo 518 @echo " $(DEP_MISSING)" 519 @echo 520 @echo "Installing the development packages for your system will solve" 521 @echo "this issue. Please consult INSTALL to get more information." 522 @echo 523 @echo "If you need information about why these tests failed, run:" 524 @echo 525 @echo " make run_dep_checks" 526 @echo 527 endif 528 529 git_update: 530 ifeq ($(IS_GIT_FOLDER),true) 531 @echo "Additionally, since you are in a git clone, you can download the" 532 @echo "missing dependencies in third_party by running the following command:" 533 @echo 534 @echo " git submodule update --init" 535 @echo 536 endif 537 538 openssl_dep_error: openssl_dep_message git_update stop 539 540 openssl_dep_message: 541 @echo 542 @echo "DEPENDENCY ERROR" 543 @echo 544 @echo "The target you are trying to run requires an OpenSSL implementation." 545 @echo "Your system doesn't have one, and either the third_party directory" 546 @echo "doesn't have it, or your compiler can't build BoringSSL." 547 @echo 548 @echo "Please consult BUILDING.md to get more information." 549 @echo 550 @echo "If you need information about why these tests failed, run:" 551 @echo 552 @echo " make run_dep_checks" 553 @echo 554 555 systemtap_dep_error: 556 @echo 557 @echo "DEPENDENCY ERROR" 558 @echo 559 @echo "Under the '$(CONFIG)' configutation, the target you are trying " 560 @echo "to build requires systemtap 2.7+ (on Linux) or dtrace (on other " 561 @echo "platforms such as Solaris and *BSD). " 562 @echo 563 @echo "Please consult BUILDING.md to get more information." 564 @echo 565 566 install_not_supported_message: 567 @echo 568 @echo "Installing via 'make' is no longer supported. Use cmake or bazel instead." 569 @echo 570 @echo "Please consult BUILDING.md to get more information." 571 @echo 572 573 install_not_supported_error: install_not_supported_message stop 574 575 stop: 576 @false 577 578 % for tgt in filtered_targets: 579 ${tgt.name}: $(BINDIR)/$(CONFIG)/${tgt.name} 580 % endfor 581 582 run_dep_checks: 583 @echo "run_dep_checks target has been deprecated." 584 585 static: static_c static_cxx 586 587 static_c: cache.mk \ 588 % for lib in filtered_libs: 589 % if 'Makefile' in lib.get('build_system', ['Makefile']): 590 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): 591 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 592 % endif 593 % endif 594 % endfor 595 596 597 static_cxx: cache.mk \ 598 % for lib in filtered_libs: 599 % if 'Makefile' in lib.get('build_system', ['Makefile']): 600 % if lib.build == 'all' and lib.language == 'c++': 601 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 602 % endif 603 % endif 604 % endfor 605 606 607 static_csharp: static_c \ 608 % for lib in filtered_libs: 609 % if 'Makefile' in lib.get('build_system', ['Makefile']): 610 % if lib.build == 'all' and lib.language == 'csharp': 611 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 612 % endif 613 % endif 614 % endfor 615 616 617 shared: shared_c shared_cxx 618 619 shared_c: cache.mk\ 620 % for lib in filtered_libs: 621 % if 'Makefile' in lib.get('build_system', ['Makefile']): 622 % if lib.build == 'all' and lib.language == 'c' and not lib.get('external_deps', None): 623 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)\ 624 % endif 625 % endif 626 % endfor 627 628 shared_cxx: cache.mk\ 629 % for lib in filtered_libs: 630 % if 'Makefile' in lib.get('build_system', ['Makefile']): 631 % if lib.build == 'all' and lib.language == 'c++': 632 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)\ 633 % endif 634 % endif 635 % endfor 636 637 638 shared_csharp: shared_c \ 639 % for lib in filtered_libs: 640 % if 'Makefile' in lib.get('build_system', ['Makefile']): 641 % if lib.build == 'all' and lib.language == 'csharp': 642 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)\ 643 % endif 644 % endif 645 % endfor 646 647 grpc_csharp_ext: shared_csharp 648 649 privatelibs: privatelibs_c privatelibs_cxx 650 651 privatelibs_c: \ 652 % for lib in filtered_libs: 653 % if 'Makefile' in lib.get('build_system', ['Makefile']): 654 % if lib.build == 'private' and lib.language == 'c' and not lib.get('external_deps', None) and not lib.boringssl: 655 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 656 % endif 657 % endif 658 % endfor 659 660 ifeq ($(EMBED_OPENSSL),true) 661 privatelibs_cxx: \ 662 % for lib in filtered_libs: 663 % if 'Makefile' in lib.get('build_system', ['Makefile']): 664 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None): 665 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 666 % endif 667 % endif 668 % endfor 669 670 else 671 privatelibs_cxx: \ 672 % for lib in filtered_libs: 673 % if 'Makefile' in lib.get('build_system', ['Makefile']): 674 % if lib.build == 'private' and lib.language == 'c++' and not lib.get('external_deps', None) and not lib.boringssl: 675 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a\ 676 % endif 677 % endif 678 % endfor 679 680 endif 681 682 683 strip: strip-static strip-shared 684 685 strip-static: strip-static_c strip-static_cxx 686 687 strip-shared: strip-shared_c strip-shared_cxx 688 689 strip-static_c: static_c 690 ifeq ($(CONFIG),opt) 691 % for lib in filtered_libs: 692 % if 'Makefile' in lib.get('build_system', ['Makefile']): 693 % if lib.language == "c": 694 % if lib.build == "all": 695 % if not lib.get('external_deps', None): 696 $(E) "[STRIP] Stripping lib${lib.name}.a" 697 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 698 % endif 699 % endif 700 % endif 701 % endif 702 % endfor 703 endif 704 705 strip-static_cxx: static_cxx 706 ifeq ($(CONFIG),opt) 707 % for lib in filtered_libs: 708 % if 'Makefile' in lib.get('build_system', ['Makefile']): 709 % if lib.language == "c++": 710 % if lib.build == "all": 711 $(E) "[STRIP] Stripping lib${lib.name}.a" 712 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 713 % endif 714 % endif 715 % endif 716 % endfor 717 endif 718 719 strip-shared_c: shared_c 720 ifeq ($(CONFIG),opt) 721 % for lib in filtered_libs: 722 % if 'Makefile' in lib.get('build_system', ['Makefile']): 723 % if lib.language == "c": 724 % if lib.build == "all": 725 % if not lib.get('external_deps', None): 726 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" 727 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) 728 % endif 729 % endif 730 % endif 731 % endif 732 % endfor 733 endif 734 735 strip-shared_cxx: shared_cxx 736 ifeq ($(CONFIG),opt) 737 % for lib in filtered_libs: 738 % if 'Makefile' in lib.get('build_system', ['Makefile']): 739 % if lib.language == "c++": 740 % if lib.build == "all": 741 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" 742 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) 743 % endif 744 % endif 745 % endif 746 % endfor 747 endif 748 749 strip-shared_csharp: shared_csharp 750 ifeq ($(CONFIG),opt) 751 % for lib in filtered_libs: 752 % if 'Makefile' in lib.get('build_system', ['Makefile']): 753 % if lib.language == "csharp": 754 % if lib.build == "all": 755 $(E) "[STRIP] Stripping $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)" 756 $(Q) $(STRIP) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) 757 % endif 758 % endif 759 % endif 760 % endfor 761 endif 762 763 cache.mk:: 764 $(E) "[MAKE] Generating $@" 765 $(Q) echo "$(CACHE_MK)" | tr , '\n' >$@ 766 767 ifeq ($(CONFIG),stapprof) 768 src/core/profiling/stap_timers.c: $(GENDIR)/src/core/profiling/stap_probes.h 769 ifeq ($(HAS_SYSTEMTAP),true) 770 $(GENDIR)/src/core/profiling/stap_probes.h: src/core/profiling/stap_probes.d 771 $(E) "[DTRACE] Compiling $<" 772 $(Q) mkdir -p `dirname $@` 773 $(Q) $(DTRACE) -C -h -s $< -o $@ 774 else 775 $(GENDIR)/src/core/profiling/stap_probes.h: systemtap_dep_error stop 776 endif 777 endif 778 779 $(OBJDIR)/$(CONFIG)/%.o : %.c 780 $(E) "[C] Compiling $<" 781 $(Q) mkdir -p `dirname $@` 782 $(Q) $(CC) $(CPPFLAGS) $(CFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 783 784 $(OBJDIR)/$(CONFIG)/%.o : $(GENDIR)/%.pb.cc 785 $(E) "[CXX] Compiling $<" 786 $(Q) mkdir -p `dirname $@` 787 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 788 789 $(OBJDIR)/$(CONFIG)/src/compiler/%.o : src/compiler/%.cc 790 $(E) "[HOSTCXX] Compiling $<" 791 $(Q) mkdir -p `dirname $@` 792 $(Q) $(HOST_CXX) $(HOST_CXXFLAGS) $(HOST_CPPFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 793 794 $(OBJDIR)/$(CONFIG)/src/core/%.o : src/core/%.cc 795 $(E) "[CXX] Compiling $<" 796 $(Q) mkdir -p `dirname $@` 797 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 798 799 $(OBJDIR)/$(CONFIG)/test/core/%.o : test/core/%.cc 800 $(E) "[CXX] Compiling $<" 801 $(Q) mkdir -p `dirname $@` 802 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(COREFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 803 804 $(OBJDIR)/$(CONFIG)/%.o : %.cc 805 $(E) "[CXX] Compiling $<" 806 $(Q) mkdir -p `dirname $@` 807 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 808 809 $(OBJDIR)/$(CONFIG)/%.o : %.cpp 810 $(E) "[CXX] Compiling $<" 811 $(Q) mkdir -p `dirname $@` 812 $(Q) $(CXX) $(CPPFLAGS) $(CXXFLAGS) -MMD -MF $(addsuffix .dep, $(basename $@)) -c -o $@ $< 813 814 install: install_not_supported_error 815 816 install_c: install_not_supported_error 817 818 install_cxx: install_not_supported_error 819 820 install_csharp: install_not_supported_error 821 822 install-static: install_not_supported_error 823 824 install-certs: install_not_supported_error 825 826 clean: 827 $(E) "[CLEAN] Cleaning build directories." 828 $(Q) $(RM) -rf $(OBJDIR) $(LIBDIR) $(BINDIR) $(GENDIR) cache.mk 829 830 831 # The various libraries 832 833 % for lib in filtered_libs: 834 % if 'Makefile' in lib.get('build_system', ['Makefile']): 835 ${makelib(lib)} 836 % endif 837 % endfor 838 839 # Add private ABSEIL target which contains all sources used by all baselib libraries. 840 <% 841 # Collect all abseil source and header files used by gpr, grpc, so on. 842 used_abseil_rules = set() 843 for lib in libs: 844 if lib.get("baselib"): 845 for dep in lib.transitive_deps: 846 if is_absl_lib(dep): 847 used_abseil_rules.add(dep) 848 used_abseil_srcs = [] 849 used_abseil_hdrs = [] 850 for lib in libs: 851 if lib.name in used_abseil_rules: 852 used_abseil_srcs.extend(lib.get("src", [])) 853 used_abseil_hdrs.extend(lib.get("hdr", [])) 854 # Create `grpc_abseil` rule with collected files. 855 lib_type = type(libs[0]) 856 grpc_abseil_lib = lib_type({ 857 "name": "grpc_abseil", 858 "build": "private", 859 "language": "c", 860 "defaults": "abseil", 861 "src": sorted(used_abseil_srcs), 862 "hdr": sorted(used_abseil_hdrs), 863 "secure": False, 864 }) 865 %> 866 ${makelib(grpc_abseil_lib)} 867 868 <%def name="makelib(lib)"> 869 # start of build recipe for library "${lib.name}" (generated by makelib(lib) template function) 870 LIB${lib.name.upper()}_SRC = \\ 871 872 % for src in lib.src: 873 ${src} \\ 874 875 % endfor 876 877 % if "public_headers" in lib: 878 % if lib.language == "c++": 879 PUBLIC_HEADERS_CXX += \\ 880 881 % else: 882 PUBLIC_HEADERS_C += \\ 883 884 % endif 885 % for hdr in lib.public_headers: 886 ${hdr} \\ 887 888 % endfor 889 % endif 890 891 LIB${lib.name.upper()}_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIB${lib.name.upper()}_SRC)))) 892 893 % if lib.get('defaults', None): 894 % for name, value in defaults.get(lib.defaults).items(): 895 $(LIB${lib.name.upper()}_OBJS): ${name} += ${value} 896 % endfor 897 % endif 898 899 ## If the library requires OpenSSL, let's add some restrictions. 900 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 901 ifeq ($(NO_SECURE),true) 902 903 # You can't build secure libraries if you don't have OpenSSL. 904 905 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: openssl_dep_error 906 907 % if lib.build == "all": 908 $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}): openssl_dep_error 909 % endif 910 911 else 912 913 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP) \ 914 ## The else here corresponds to the if secure earlier. 915 % else: 916 $(LIBDIR)/$(CONFIG)/lib${lib.name}.a: \ 917 % if lib.name not in ['z', 'ares', 'address_sorting', 're2', 'upb', 'grpc_abseil']: 918 $(ZLIB_DEP) \ 919 $(CARES_DEP) \ 920 $(ADDRESS_SORTING_DEP) \ 921 $(RE2_DEP) \ 922 $(UPB_DEP) \ 923 $(GRPC_ABSEIL_DEP) \ 924 % endif 925 % endif 926 $(LIB${lib.name.upper()}_OBJS) \ 927 % if lib.get('baselib', False): 928 $(LIBGPR_OBJS) \ 929 $(LIBGRPC_ABSEIL_OBJS) \ 930 $(ZLIB_MERGE_OBJS) \ 931 $(CARES_MERGE_OBJS) \ 932 $(ADDRESS_SORTING_MERGE_OBJS) \ 933 $(RE2_MERGE_OBJS) \ 934 $(UPB_MERGE_OBJS) \ 935 % if lib.get('secure', 'check') == True: 936 $(OPENSSL_MERGE_OBJS) \ 937 % endif 938 % endif 939 940 $(E) "[AR] Creating $@" 941 $(Q) mkdir -p `dirname $@` 942 $(Q) rm -f $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 943 $(Q) $(AR) $(ARFLAGS) $(LIBDIR)/$(CONFIG)/lib${lib.name}.a $(LIB${lib.name.upper()}_OBJS) \ 944 % if lib.get('baselib', False): 945 $(LIBGPR_OBJS) \ 946 $(LIBGRPC_ABSEIL_OBJS) \ 947 $(ZLIB_MERGE_OBJS) \ 948 $(CARES_MERGE_OBJS) \ 949 $(ADDRESS_SORTING_MERGE_OBJS) \ 950 $(RE2_MERGE_OBJS) \ 951 $(UPB_MERGE_OBJS) \ 952 % if lib.get('secure', 'check') == True: 953 $(OPENSSL_MERGE_OBJS) \ 954 % endif 955 % endif 956 957 ifeq ($(SYSTEM),Darwin) 958 $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/lib${lib.name}.a 959 endif 960 961 <% 962 ld = '$(LDXX)' 963 964 out_mingbase = '$(LIBDIR)/$(CONFIG)/' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')' 965 out_libbase = '$(LIBDIR)/$(CONFIG)/lib' + lib.name + '$(SHARED_VERSION_' + lang_to_var[lib.language] + ')' 966 967 common = '$(LIB' + lib.name.upper() + '_OBJS)' 968 969 link_libs = '' 970 lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)' 971 mingw_libs = '' 972 mingw_lib_deps = ' $(ZLIB_DEP) $(CARES_DEP) $(ADDRESS_SORTING_DEP) $(RE2_DEP) $(UPB_DEP) $(GRPC_ABSEIL_DEP)' 973 if lib.get('deps_linkage', None) == 'static': 974 for dep in lib.get('deps', []): 975 if is_absl_lib(dep): continue 976 lib_archive = '$(LIBDIR)/$(CONFIG)/lib' + dep + '.a' 977 common = common + ' ' + lib_archive 978 lib_deps = lib_deps + ' ' + lib_archive 979 mingw_lib_deps = mingw_lib_deps + ' ' + lib_archive 980 else: 981 for dep in lib.get('deps', []): 982 if is_absl_lib(dep): continue 983 dep_lib = None 984 for dl in libs: 985 if dl.name == dep: 986 dep_lib = dl 987 assert dep_lib, 'lib %s not found (in %s)' % (dep, lib.name) 988 link_libs = link_libs + ' -l' + dep 989 lib_deps = lib_deps + ' $(LIBDIR)/$(CONFIG)/lib' + dep + '.$(SHARED_EXT_' + lang_to_var[dep_lib.language] + ')' 990 mingw_libs = mingw_libs + ' -l' + dep + '$(SHARED_VERSION_' + lang_to_var[dep_lib.language] + ')-dll' 991 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] + ')' 992 993 security = lib.get('secure', 'check') 994 if security == True: 995 common = common + ' $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE)' 996 common = common + ' $(ZLIB_MERGE_LIBS) $(CARES_MERGE_LIBS) $(ADDRESS_SORTING_MERGE_LIBS) $(RE2_MERGE_LIBS) $(UPB_MERGE_LIBS) $(GRPC_ABSEIL_MERGE_LIBS)' 997 998 if security in [True, 'check']: 999 for src in lib.src: 1000 sources_that_need_openssl.add(src) 1001 else: 1002 for src in lib.src: 1003 sources_that_don_t_need_openssl.add(src) 1004 1005 if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1006 lib_deps = lib_deps + ' $(OPENSSL_DEP)' 1007 mingw_lib_deps = mingw_lib_deps + ' $(OPENSSL_DEP)' 1008 1009 ldflags = '$(LDFLAGS)' 1010 if lib.get('LDFLAGS', None): 1011 ldflags += ' ' + lib['LDFLAGS'] 1012 1013 common = common + ' $(LDLIBS)' 1014 %> 1015 1016 % if lib.build == "all": 1017 ifeq ($(SYSTEM),MINGW32) 1018 ${out_mingbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps} 1019 $(E) "[LD] Linking $@" 1020 $(Q) mkdir -p `dirname $@` 1021 $(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} 1022 else 1023 ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}): $(LIB${lib.name.upper()}_OBJS) ${lib_deps} 1024 $(E) "[LD] Linking $@" 1025 $(Q) mkdir -p `dirname $@` 1026 ifeq ($(SYSTEM),Darwin) 1027 $(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} 1028 else 1029 $(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} 1030 $(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} 1031 $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so 1032 endif 1033 endif 1034 % endif 1035 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1036 ## If the lib was secure, we have to close the Makefile's if that tested 1037 ## the presence of OpenSSL. 1038 1039 endif 1040 % endif 1041 1042 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1043 ifneq ($(NO_SECURE),true) 1044 % endif 1045 ifneq ($(NO_DEPS),true) 1046 -include $(LIB${lib.name.upper()}_OBJS:.o=.dep) 1047 endif 1048 % if lib.get('secure', 'check') == True or lib.get('secure', 'check') == 'check': 1049 endif 1050 % endif 1051 # end of build recipe for library "${lib.name}" 1052 </%def> 1053 1054 # TODO(jtattermusch): is there a way to get around this hack? 1055 ifneq ($(OPENSSL_DEP),) 1056 # This is to ensure the embedded OpenSSL is built beforehand, properly 1057 # installing headers to their final destination on the drive. We need this 1058 # otherwise parallel compilation will fail if a source is compiled first. 1059 % for src in sorted(sources_that_need_openssl): 1060 % if src not in sources_that_don_t_need_openssl: 1061 ${src}: $(OPENSSL_DEP) 1062 % endif 1063 % endfor 1064 endif 1065 1066 .PHONY: all strip tools \ 1067 dep_error openssl_dep_error openssl_dep_message git_update stop \ 1068 buildtests buildtests_c buildtests_cxx \ 1069 test test_c test_cxx \ 1070 install install_c install_cxx install_csharp install-static install-certs \ 1071 strip strip-shared strip-static \ 1072 strip_c strip-shared_c strip-static_c \ 1073 strip_cxx strip-shared_cxx strip-static_cxx \ 1074 dep_c dep_cxx bins_dep_c bins_dep_cxx \ 1075 clean 1076 1077 .PHONY: printvars 1078 printvars: 1079 @$(foreach V,$(sort $(.VARIABLES)), \ 1080 $(if $(filter-out environment% default automatic, \ 1081 $(origin $V)),$(warning $V=$($V) ($(value $V))))) 1082