1570af302Sopenharmony_ci# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
2570af302Sopenharmony_ci# Copyright (c) 2020-2022 Huawei Device Co., Ltd. All rights reserved.
3570af302Sopenharmony_ci#
4570af302Sopenharmony_ci# Redistribution and use in source and binary forms, with or without modification,
5570af302Sopenharmony_ci# are permitted provided that the following conditions are met:
6570af302Sopenharmony_ci#
7570af302Sopenharmony_ci# 1. Redistributions of source code must retain the above copyright notice, this list of
8570af302Sopenharmony_ci#    conditions and the following disclaimer.
9570af302Sopenharmony_ci#
10570af302Sopenharmony_ci# 2. Redistributions in binary form must reproduce the above copyright notice, this list
11570af302Sopenharmony_ci#    of conditions and the following disclaimer in the documentation and/or other materials
12570af302Sopenharmony_ci#    provided with the distribution.
13570af302Sopenharmony_ci#
14570af302Sopenharmony_ci# 3. Neither the name of the copyright holder nor the names of its contributors may be used
15570af302Sopenharmony_ci#    to endorse or promote products derived from this software without specific prior written
16570af302Sopenharmony_ci#    permission.
17570af302Sopenharmony_ci#
18570af302Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19570af302Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20570af302Sopenharmony_ci# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21570af302Sopenharmony_ci# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22570af302Sopenharmony_ci# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23570af302Sopenharmony_ci# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24570af302Sopenharmony_ci# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25570af302Sopenharmony_ci# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26570af302Sopenharmony_ci# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27570af302Sopenharmony_ci# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28570af302Sopenharmony_ci# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29570af302Sopenharmony_ci
30570af302Sopenharmony_ciimport("//kernel/liteos_m/liteos.gni")
31570af302Sopenharmony_ciimport("//third_party/optimized-routines/optimized-routines.gni")
32570af302Sopenharmony_ciimport("musl.gni")
33570af302Sopenharmony_ci
34570af302Sopenharmony_cilibc = "musl-c"
35570af302Sopenharmony_cilibm = "musl-m"
36570af302Sopenharmony_ci
37570af302Sopenharmony_ciLITEOS_MENUCONFIG_H = rebase_path("$root_out_dir/config.h")
38570af302Sopenharmony_ci
39570af302Sopenharmony_ciconfig("include") {
40570af302Sopenharmony_ci  include_dirs = [ "include" ]
41570af302Sopenharmony_ci}
42570af302Sopenharmony_ci
43570af302Sopenharmony_cistatic_library(libc) {
44570af302Sopenharmony_ci  sources = MUSL_LIBC_SRC
45570af302Sopenharmony_ci
46570af302Sopenharmony_ci  include_dirs = [
47570af302Sopenharmony_ci    "src/include",
48570af302Sopenharmony_ci    "src/internal",
49570af302Sopenharmony_ci  ]
50570af302Sopenharmony_ci
51570af302Sopenharmony_ci  include_dirs += [
52570af302Sopenharmony_ci    "//kernel/liteos_m/kernel/arch/include",
53570af302Sopenharmony_ci    "//kernel/liteos_m/kernel/include",
54570af302Sopenharmony_ci    "//kernel/liteos_m/utils",
55570af302Sopenharmony_ci  ]
56570af302Sopenharmony_ci
57570af302Sopenharmony_ci  cflags = [
58570af302Sopenharmony_ci    "-imacros",
59570af302Sopenharmony_ci    "$LITEOS_MENUCONFIG_H",
60570af302Sopenharmony_ci  ]
61570af302Sopenharmony_ci
62570af302Sopenharmony_ci  if (defined(LOSCFG_ARCH_ARM_AARCH32)) {
63570af302Sopenharmony_ci    sources += MUSL_LIBC_OPT_SRC_FOR_ARM
64570af302Sopenharmony_ci    if (LOSCFG_ARCH_ARM_VER == "armv7-m" || LOSCFG_ARCH_ARM_VER == "armv8-m") {
65570af302Sopenharmony_ci      sources -= [
66570af302Sopenharmony_ci        "$MUSLPORTINGDIR/src/string/strcpy.c",
67570af302Sopenharmony_ci        "$MUSLPORTINGDIR/src/string/strlen.c",
68570af302Sopenharmony_ci      ]
69570af302Sopenharmony_ci      sources += OPTRT_STRING_ARM_SRC_FILES_FOR_ARMV7_M
70570af302Sopenharmony_ci      asmflags = [ "-D__strlen_armv6t2=strlen" ]
71570af302Sopenharmony_ci      if (defined(LOSCFG_KERNEL_LMS)) {
72570af302Sopenharmony_ci        asmflags += [ "-D__strcpy_arm=__strcpy" ]
73570af302Sopenharmony_ci      } else {
74570af302Sopenharmony_ci        asmflags += [ "-D__strcpy_arm=strcpy" ]
75570af302Sopenharmony_ci      }
76570af302Sopenharmony_ci
77570af302Sopenharmony_ci      if (LOSCFG_ARCH_ARM_VER == "armv8-m") {
78570af302Sopenharmony_ci        sources -= [
79570af302Sopenharmony_ci          "$MUSLPORTINGDIR/src/string/memcmp.c",
80570af302Sopenharmony_ci          "$MUSLPORTINGDIR/src/string/memset.c",
81570af302Sopenharmony_ci        ]
82570af302Sopenharmony_ci        sources += MUSL_LIBC_OPT_SRC_FOR_ARMV8_M
83570af302Sopenharmony_ci      }
84570af302Sopenharmony_ci
85570af302Sopenharmony_ci      cflags += asmflags
86570af302Sopenharmony_ci    }
87570af302Sopenharmony_ci  }
88570af302Sopenharmony_ci
89570af302Sopenharmony_ci  public_configs = [ ":include" ]
90570af302Sopenharmony_ci}
91570af302Sopenharmony_ci
92570af302Sopenharmony_cistatic_library(libm) {
93570af302Sopenharmony_ci  sources = MUSL_LIBM_SRC
94570af302Sopenharmony_ci
95570af302Sopenharmony_ci  include_dirs = [
96570af302Sopenharmony_ci    "src/include",
97570af302Sopenharmony_ci    "src/internal",
98570af302Sopenharmony_ci  ]
99570af302Sopenharmony_ci
100570af302Sopenharmony_ci  public_configs = [ ":include" ]
101570af302Sopenharmony_ci}
102570af302Sopenharmony_ci
103570af302Sopenharmony_cigroup("kernel") {
104570af302Sopenharmony_ci  public_deps = [
105570af302Sopenharmony_ci    ":$libc",
106570af302Sopenharmony_ci    ":$libm",
107570af302Sopenharmony_ci  ]
108570af302Sopenharmony_ci}
109