BUILD.gn 4.6 KB
Newer Older
M
mamingshuai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

config("cpu_arch") {
  cflags = []
  if (board_arch != "") {
    cflags += [ "-march=$board_arch" ]
  }
  if (board_cpu != "") {
    cflags += [ "-mcpu=$board_cpu" ]
  }
  cflags_cc = cflags
  ldflags = cflags
}

config("language_c") {
  cflags_c = [ "-std=c99" ]
}

config("language_cpp") {
  cflags_cc = [ "-std=c++11" ]
}

config("kernel_macros") {
  if (ohos_kernel_type == "liteos_a") {
    defines = [
      "__LITEOS__",
      "__LITEOS_A__",
    ]
  } else if (ohos_kernel_type == "liteos_m") {
    defines = [
      "__LITEOS__",
      "__LITEOS_M__",
    ]
  } else if (ohos_kernel_type == "linux") {
46 47 48 49
    defines = [
      "__linux__",
      "__LINUX__",
    ]
M
mamingshuai 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
  }
}

config("werror") {
  cflags = [ "-Werror" ]
  cflags_cc = cflags
}

config("common") {
  defines = [ "_XOPEN_SOURCE=700" ]
  cflags = [
    "-nostdlib",
    "-fno-common",
    "-fno-builtin",
    "-fno-strict-aliasing",
    "-Wall",
  ]
  cflags_cc = cflags
  ldflags = [ "-lc" ]
  cflags += [ "-fsigned-char" ]
}

config("security") {
  defines = [ "_FORTIFY_SOURCE=2" ]

  cflags = [ "-fstack-protector-all" ]
  cflags_cc = cflags

  ldflags = [
    "-Wl,-z,now",
    "-Wl,-z,relro",
    "-Wl,-z,noexecstack",
  ]
}

config("exceptions") {
  cflags_cc = [ "-fexceptions" ]
  cflags_objcc = cflags_cc
}

config("no_exceptions") {
  cflags_cc = [ "-fno-exceptions" ]
  cflags_objcc = cflags_cc
  ldflags = cflags_cc
}

config("stack_protector") {
  cflags = [ "-fstack-protector-all" ]
  cflags_cc = cflags
}

config("static_pie_config") {
  cflags = [ "-fPIE" ]
  cflags_cc = cflags
}

config("shared_library_config") {
  cflags = [ "-fPIC" ]
  cflags_cc = cflags
}

config("pie_executable_config") {
  ldflags = [ "-pie" ]
}

115 116 117
clang_dir = ""
target_kernel = ""
if(ohos_current_toolchain == "ohos_clang") {
M
mamingshuai 已提交
118 119 120
  if (ohos_build_compiler_dir != "") {
    clang_dir = rebase_path("${ohos_build_compiler_dir}")
  }
121 122 123 124

  if (ohos_kernel_type == "liteos_a") {
    target_kernel = "arm-liteos"
  } else if (ohos_kernel_type == "linux") {
125
    target_kernel = "arm-linux-ohosmusl"
126
  }
127 128 129 130 131 132 133 134 135 136
  copy("ohos_clang_runtime") {
    sources = [
      "${clang_dir}/lib/${target_kernel}/c++/libc++.so",
      "${ohos_root_path}prebuilts/lite/sysroot/usr/lib/${target_kernel}/libc.so",
    ]
    outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
  }
}

config("ohos_clang") {
M
mamingshuai 已提交
137 138
  include_dirs = [
    "${clang_dir}/include/c++/v1",
139
    "//prebuilts/lite/sysroot/usr/include/${target_kernel}",
M
mamingshuai 已提交
140 141 142
  ]

  cflags = [
143
    "--target=${target_kernel}",
M
mamingshuai 已提交
144 145 146 147
    "--sysroot=${ohos_root_path}prebuilts/lite/sysroot",
  ]
  cflags_cc = cflags
  ldflags = cflags
148
  if (ohos_kernel_type == "linux") {
149 150 151 152
    defines = [
        "_LIBCPP_HAS_MUSL_LIBC",
        "__BUILD_LINUX_WITH_CLANG",
    ]
153
  }
M
mamingshuai 已提交
154 155

  ldflags += [
156 157 158
    "-L${clang_dir}/lib/${target_kernel}/c++",
    "-L${ohos_root_path}prebuilts/lite/sysroot/usr/lib/${target_kernel}",
    "-L${clang_dir}/lib/clang/9.0.0/lib/${target_kernel}",
M
mamingshuai 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
    "-lclang_rt.builtins",
    "-lc",
    "-lc++",
    "-lc++abi",
    "--sysroot=${ohos_root_path}prebuilts/lite/sysroot",
  ]
}

config("release") {
  defines = [ "OHOS_RELEASE" ]
}

config("debug") {
  defines = [ "OHOS_DEBUG" ]
}

config("clang_opt") {
  cflags = [
    "-Oz",
    "-flto",
  ]
  cflags_cc = cflags
}

config("gcc_opt") {
  cflags = [ "-Os" ]
  cflags_cc = cflags
}

config("default_link_path") {
  out_dir = rebase_path(root_build_dir)
  ldflags = [
    "-L${out_dir}",
    "-Wl,-rpath-link=${out_dir}",
  ]
}

config("board_config") {
  cflags = []
  cflags_cc = []
  ldflags = []
  include_dirs = []
201
  defines = []
M
mamingshuai 已提交
202 203 204 205 206 207 208 209 210
  cflags += board_cflags
  if (board_configed_sysroot != "") {
    cflags += [ "--sysroot=${board_configed_sysroot}" ]
    cflags_cc += [ "--sysroot=${board_configed_sysroot}" ]
    ldflags += [ "--sysroot=${board_configed_sysroot}" ]
  }
  cflags_cc += board_cxx_flags
  ldflags += board_ld_flags
  include_dirs += board_include_dirs
211 212 213
  if (defined(board_macro_defines)) {
    defines += board_macro_defines
  }
M
mamingshuai 已提交
214
}
215 216 217 218 219 220

config("board_exe_ld_flags") {
  ldflags = []
  if (defined(board_exe_ld_flags)) {
    ldflags += board_exe_ld_flags
  }
221
}