| # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| declare_args() { |
| # Set this to false if you'd like to disable -Werror. |
| enable_werror = true |
| |
| # Set this to false if you want to disable Large File Support (LFS). |
| enable_lfs = true |
| } |
| |
| _cflags_no_exceptions = [ |
| "-fno-exceptions", |
| "-fno-unwind-tables", |
| "-fno-asynchronous-unwind-tables", |
| ] |
| |
| config("no_exceptions") { |
| cflags_cc = _cflags_no_exceptions |
| cflags_c = _cflags_no_exceptions |
| } |
| |
| config("compiler_defaults") { |
| defines = [] |
| libs = [] |
| |
| include_dirs = [ |
| "${root_gen_dir}/include", |
| "${platform2_root}", |
| "${platform2_root}/../platform", |
| ] |
| cflags = [ |
| "-Wall", |
| "-Wno-psabi", |
| "-Wunused", |
| "-Wno-unused-parameter", |
| "-ggdb3", |
| "-fstack-protector-strong", |
| "-Wformat=2", |
| "-fvisibility=internal", |
| "-Wa,--noexecstack", |
| ] |
| cflags_c = [ "-std=gnull" ] + external_cppflags + external_cxxflags |
| cflags_cc = [ "-std=gnu++14" ] + external_cppflags + external_cxxflags |
| ldflags = external_ldflags + [ |
| "-Wl,-z,relro", |
| "-Wl,-z,noexecstack", |
| "-Wl,-z,now", |
| "-Wl,--as-needed", |
| ] |
| if (enable_werror) { |
| cflags += [ "-Werror" ] |
| } |
| if (use.cros_host) { |
| defines += [ "NDEBUG" ] |
| } |
| if (enable_lfs) { |
| defines += [ |
| # Enable support for new LFS funcs (ftello/etc...). |
| "_LARGEFILE_SOURCE", |
| |
| # Enable support for 64bit variants (off64_t/fseeko64/etc...). |
| "_LARGEFILE64_SOURCE", |
| |
| # Default to 64bit variants (off_t is defined as off64_t). |
| "_FILE_OFFSET_BITS=64", |
| ] |
| } |
| |
| # Remove no_exceptions flags given as arguments |
| # making the config pluggable. |
| # See BUILDCONFIG.gn. |
| cflags_cc -= _cflags_no_exceptions |
| cflags_c -= _cflags_no_exceptions |
| |
| if (!use.cros_host) { |
| include_dirs += [ "${sysroot}/usr/include" ] |
| cflags += [ "--sysroot=${sysroot}" ] |
| ldflags += [ "--sysroot=${sysroot}" ] |
| } |
| if (use.profiling) { |
| cflags += [ |
| "-fprofile-instr-generate", |
| "-fcoverage-mapping", |
| ] |
| ldflags += [ |
| "-fprofile-instr-generate", |
| "-fcoverage-mapping", |
| ] |
| } |
| if (use.tcmalloc) { |
| libs += [ "-ltcmalloc" ] |
| } |
| } |
| |
| config("executable_config") { |
| cflags = [ "-fPIE" ] |
| ldflags = [ "-pie" ] |
| } |
| |
| config("static_library_config") { |
| cflags = [ "-fPIE" ] |
| } |
| |
| config("shared_library_config") { |
| cflags = [ "-fPIC" ] |
| } |
| |
| if (use.test) { |
| config("test") { |
| libs = [] |
| libs += exec_script("//common-mk/args_generator_wrapper.py", |
| [ |
| "gtest-config", |
| "--libs", |
| ], |
| "list lines") |
| libs += exec_script("//common-mk/args_generator_wrapper.py", |
| [ |
| "gmock-config", |
| "--libs", |
| ], |
| "list lines") |
| } |
| } |