1# Copyright (C) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13print("target_os", target_os) 14print("target_name", target) 15group("default_deps") { 16 public_configs = [ ":default_config" ] 17 public_deps = [] 18} 19config("default_config") { 20 include_dirs = [ 21 "..", 22 "../include", 23 ] 24} 25config("trace_cfg") { 26 cflags_cc = [ 27 "-std=c++17", 28 29 # "-std=gnu++17", 30 "-fvisibility=hidden", 31 "-Wno-unused-variable", 32 ] 33 if (!is_test) { 34 cflags_cc += [ 35 "-fno-rtti", 36 "-fno-exceptions", 37 ] 38 } 39} 40 41config("visibility_hidden") { 42 cflags = [ "-fvisibility=hidden" ] 43} 44 45config("default") { 46 cflags_c = [] 47 cflags_cc = [] 48 libs = [] 49 50 cflags = [ 51 "-fstrict-aliasing", 52 "-g", 53 "-Wformat", 54 "-Wno-unused-variable", 55 ] 56 57 if (is_linux || is_macx) { 58 cflags += [ 59 "-Wa,--noexecstack", 60 "-fcolor-diagnostics", 61 "-fdiagnostics-show-template-tree", 62 "-ftrapv", 63 ] 64 if (!use_wasm) { 65 cflags += [ 66 "-fstack-protector-strong", 67 "-fstack-protector-all", 68 "-D_FORTIFY_SOURCE=2 -O2", 69 "-D SUPPORTTHREAD", # if support thread 70 71 # "-D HAVE_ELF_H", 72 "-D target_cpu_x64", 73 74 # "-D HAVE_LINK_H", 75 # "-D_GNU_SOURCE", 76 "-DHAVE_CONFIG_H", 77 "-DNDEBUG", 78 "-DCC_IS_CLANG", 79 ] 80 # with_libunwind = true 81 } 82 if (!use_wasm && !is_win && !is_macx && !is_test) { 83 cflags += [ "-D HAVE_LIBUNWIND" ] 84 } 85 86 cflags += [ "-D USE_VTABLE" ] 87 if (use_wasm) { 88 cflags += [ 89 "-D IS_WASM", 90 91 # "-D HAVE_LIBUNWIND", 92 "-D target_cpu_x64", 93 "-DHAVE_CONFIG_H", 94 "-DNDEBUG", 95 "-DCC_IS_CLANG", 96 "-D__x86_64__", 97 ] 98 } 99 cflags += [ "-D BINDER_ASYNC" ] 100 libs += [ "pthread" ] 101 if (!is_macx) { 102 libs += [ "rt" ] 103 } 104 if (!is_win) { 105 cflags += [ 106 "-fPIE", 107 "-fPIC", 108 ] 109 } 110 } 111 if (is_win) { 112 cflags += [ "-D is_mingw" ] 113 defines = [ "WIN32_LEAN_AND_MEAN" ] 114 libs += [ "wsock32" ] 115 libs += [ "Ws2_32" ] 116 cflags += [ 117 "-D SECUREC_IS_DLL_LIBRARY", 118 "-D __KERNEL__", 119 ] 120 } 121 if (with_perf) { 122 cflags += [ "-D WITH_PERF" ] 123 } 124 if (with_ebpf_help_table) { 125 cflags += [ "-D WITH_EBPF_HELP" ] 126 } 127} 128 129config("symbols") { 130 cflags = [ "-O0" ] 131 if (is_linux || is_macx) { 132 cflags += [ "-funwind-tables" ] 133 } 134} 135 136config("release") { 137 cflags = [ 138 "-fdata-sections", 139 "-ffunction-sections", 140 ] 141 142 cflags += [ "-O3" ] 143 ldflags = [ "-fstack-protector" ] 144 if (!is_macx) { 145 ldflags += [ "-Wl,-O1" ] 146 if (!is_win) { 147 ldflags += [ 148 "-fuse-ld=gold", 149 "-Wl,--gc-sections", 150 ] 151 } 152 } 153 154 if (!is_win && !is_macx) { 155 ldflags += [ 156 "-fPIC", 157 "-fpie", 158 "-pie", 159 ] 160 } 161 defines = [ "NDEBUG" ] 162} 163 164config("shared_library") { 165 if (!is_win) { 166 ldflags = [ "-fPIC" ] 167 } 168} 169 170config("executable") { 171 print("use_wasm", use_wasm) 172 ldflags = [] 173 174 if (is_linux || (is_macx && !use_wasm)) { 175 ldflags += [] 176 } 177 if (!is_macx && !use_wasm && !is_win) { 178 ldflags = [ 179 "-Wl,--disable-new-dtags", 180 "-Wl,-z,noexecstack", 181 "-lrt", 182 "-fuse-ld=gold", 183 "-Wl,-z,now", 184 "-Wl,-z,relro", 185 ] 186 } 187 if (!is_macx && !use_wasm) { 188 ldflags += [ "-fpie" ] 189 } 190 if (!is_macx && !use_wasm && !is_win) { 191 ldflags += [ "-pie" ] 192 } 193 194 if (is_macx) { 195 ldflags += [ 196 "-fdata-sections", 197 "-ffunction-sections", 198 ] 199 if (!use_wasm) { 200 ldflags += [ "-Wl,-U,__sanitizer_options_link_helper" ] 201 } 202 } 203 if (!is_debug && !is_macx) { 204 ldflags += [ "-s" ] 205 } else if (!is_debug && is_macx) { 206 ldflags += [ "-dead_strip" ] 207 } 208} 209