BUILD.gn 5.0 KB
Newer Older
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
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
#    conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#    of conditions and the following disclaimer in the documentation and/or other materials
#    provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
#    to endorse or promote products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import("//build/lite/config/component/lite_component.gni")

32 33
targets = ""
if (ohos_kernel_type == "liteos_a") {
C
Caoruihong 已提交
34
  targets = "liteos_a_user"
35
} else if (ohos_kernel_type == "linux") {
C
Caoruihong 已提交
36
  targets = "linux_user"
37 38 39 40 41
}

assert(targets != "", "Unsupported ohos_kernel_type: $ohos_kernel_type")

sysroot_path = rebase_path(ohos_current_sysroot)
42
arch_cflags = string_join(" ", target_arch_cflags)
43

44
build_ext_component("build_sysroot") {
45 46
  no_default_deps = true
  deps = []
C
Caoruihong 已提交
47 48 49 50
  exec_path = rebase_path(target_out_dir)
  if (!defined(board_configed_sysroot) || board_configed_sysroot == "") {
    makefile = rebase_path("Makefile", exec_path)
    command = "make TOPDIR=$ohos_root_path SYSROOTDIR=$sysroot_path TARGETS=$targets -f $makefile"
C
Caoruihong 已提交
51 52 53 54 55 56
    command += " ARCH=$arch ARCH_CFLAGS=\"$arch_cflags\""
    if (ohos_build_compiler == "clang") {
      command += " CLANG=\"$ohos_current_cc_command\" TARGET=$target_triple"
    } else {
      command += " GCC=\"$ohos_current_cc_command\""
    }
57
    if (ohos_build_type == "debug") {
58
      command += " BUILD_DEBUG=true"
59
    }
C
Caoruihong 已提交
60
    if (ohos_kernel_type == "linux") {
Z
Zachery Wu 已提交
61
      deps += [ "//kernel/linux/build:linux_kernel" ]
C
Caoruihong 已提交
62
      command += " LINUXDIR=" + rebase_path("$root_out_dir/kernel/linux-4.19")
63 64
      command += " PREBUILTLINUXHDRDIR=" + rebase_path(
                     "//kernel/linux/patches/linux-4.19/prebuilts/usr/include")
65
    }
C
Caoruihong 已提交
66 67 68
  } else {
    command = "true"
  }
69

C
Caoruihong 已提交
70 71 72 73 74 75 76 77 78 79 80
  # copy C/C++ runtime libraries to lib out dir
  if (ohos_build_compiler == "clang") {
    libcpp = "\$($ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc++.so)"
    libc = "\$($ohos_current_cc_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags -print-file-name=libc.so)"
    libgcc = ""
  } else {
    libcpp = "\$($ohos_current_cxx_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libstdc++.so.6)"
    libc = "\$($ohos_current_cc_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libc.so)"
    libgcc = "\$($ohos_current_cc_command --sysroot=$sysroot_path $arch_cflags -print-file-name=libgcc_s.so)"
  }

C
Caoruihong 已提交
81
  lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path)
C
Caoruihong 已提交
82
  command += " && mkdir -p $lib_out_dir && sh -c \"cp -f $libcpp $libc $libgcc $lib_out_dir\""
C
Caoruihong 已提交
83

C
Caoruihong 已提交
84 85 86 87 88 89 90 91 92 93 94 95
  if (ohos_build_compiler == "clang") {
    outputs = [
      "$root_out_dir/unstripped/usr/lib/libc.so",
      "$root_out_dir/unstripped/usr/lib/libc++.so",
    ]
  } else {
    outputs = [
      "$root_out_dir/unstripped/usr/lib/libc.so",
      "$root_out_dir/unstripped/usr/lib/libstdc++.so.6",
      "$root_out_dir/unstripped/usr/lib/libgcc_s.so",
    ]
  }
C
Caoruihong 已提交
96 97 98 99 100
}

action_foreach("strip") {
  deps = [ ":build_sysroot" ]
  script = "//build/lite/run_shell_cmd.py"
C
Caoruihong 已提交
101 102
  set_sources_assignment_filter([ "*.txt" ])
  sources = get_target_outputs(deps[0])
103
  outputs = [ "$root_out_dir/libs/{{source_file_part}}" ]
C
Caoruihong 已提交
104 105 106 107
  args = [
    "$ohos_current_strip_command",
    "{{source}}",
    "-o",
108
    rebase_path("$root_out_dir/libs/{{source_file_part}}", root_build_dir),
C
Caoruihong 已提交
109
  ]
110 111 112
}

config("sysroot_flags") {
C
Caoruihong 已提交
113 114 115 116 117 118 119 120 121 122 123
  if (ohos_build_compiler == "clang") {
    cflags = [
      "--target=$target_triple",
      "--sysroot=$sysroot_path",
    ]
  } else {
    cflags = [
      "--sysroot=$sysroot_path",
      "-specs=musl-gcc.specs",
    ]
  }
C
Caoruihong 已提交
124 125 126
  cflags_cc = cflags
  ldflags = cflags
  asmflags = cflags
127 128 129
}

group("build") {
C
Caoruihong 已提交
130 131
  all_dependent_configs = [ ":sysroot_flags" ]
  deps = [ ":build_sysroot" ]
132
}