1#
2# Copyright (c) 2024 Huawei Device Co., Ltd.
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16import("//build/ohos.gni")
17import("FreeBSD.gni")
18
19config("free_bsd_config") {
20  include_dirs = [ "//third_party/FreeBSD" ]
21}
22
23ohos_static_library("libfreebsd_static") {
24  branch_protector_ret = "pac_ret"
25  output_name = "libfreebsd_static"
26  sources = [ "lib/libc/gen/fts.c" ]
27  if (use_libfuzzer && !is_mac) {
28    cflags = []
29  } else {
30    cflags = [
31      "-fno-emulated-tls",
32      "-fno-lto",
33      "-fno-whole-program-vtables",
34    ]
35
36    cflags += [
37      "-D_GNU_SOURCE",
38      "-DHAVE_REALLOCARRAY",
39      "-w",
40    ]
41  }
42  if (host_cpu == "arm64" && host_os == "linux") {
43    cflags += [ "-DWITH_FREEBSD" ]
44  }
45  public_configs = [ ":free_bsd_config" ]
46}
47
48static_library("ld128_static") {
49  sources = [
50    "lib/msun/ld128/e_lgammal_r.c",
51    "lib/msun/ld128/e_powl.c",
52    "lib/msun/ld128/k_cosl.c",
53    "lib/msun/ld128/k_sinl.c",
54    "lib/msun/ld128/s_erfl.c",
55    "lib/msun/ld128/s_expl.c",
56    "lib/msun/ld128/s_logl.c",
57    "lib/msun/src/e_acoshl.c",
58    "lib/msun/src/e_coshl.c",
59    "lib/msun/src/e_lgammal.c",
60    "lib/msun/src/e_sinhl.c",
61    "lib/msun/src/s_asinhl.c",
62    "lib/msun/src/s_tanhl.c",
63  ]
64
65  defines = [ "LD128_ENABLE" ]
66  include_dirs = [
67    "//third_party/FreeBSD/lib/msun/ld128",
68    "//third_party/FreeBSD/lib/msun/src",
69    "//third_party/FreeBSD/lib/libc/include",
70    "//third_party/FreeBSD/sys",
71  ]
72
73  configs -= build_inherited_configs
74  configs += [ "//build/config/components/musl:soft_musl_config" ]
75  cflags = [
76    "-mllvm",
77    "-instcombine-max-iterations=0",
78    "-ffp-contract=fast",
79    "-O3",
80    "-fPIC",
81    "-fstack-protector-strong",
82  ]
83}
84
85freebsd_files = [
86  "contrib/gdtoa/strtod.c",
87  "contrib/gdtoa/gethex.c",
88  "contrib/gdtoa/smisc.c",
89  "contrib/gdtoa/misc.c",
90  "contrib/gdtoa/strtord.c",
91  "contrib/gdtoa/hexnan.c",
92  "contrib/gdtoa/gmisc.c",
93  "contrib/gdtoa/hd_init.c",
94  "contrib/gdtoa/strtodg.c",
95  "contrib/gdtoa/ulp.c",
96  "contrib/gdtoa/strtof.c",
97  "contrib/gdtoa/sum.c",
98  "lib/libc/gdtoa/glue.c",
99  "lib/libc/stdio/parsefloat.c",
100]
101
102static_library("libc_static") {
103  sources = [
104    "contrib/tcp_wrappers/strcasecmp.c",
105    "lib/libc/gen/arc4random.c",
106    "lib/libc/gen/arc4random_uniform.c",
107    "lib/libc/stdlib/qsort.c",
108    "lib/libc/stdlib/strtoimax.c",
109    "lib/libc/stdlib/strtoul.c",
110    "lib/libc/stdlib/strtoumax.c",
111  ]
112  if (!is_llvm_build) {
113    sources += [ "contrib/libexecinfo/unwind.c" ]
114  }
115  if (musl_arch == "arm") {
116    sources += freebsd_files
117  } else if (musl_arch == "aarch64") {
118    sources += [ "lib/msun/src/s_frexpl.c" ]
119    if (!defined(ARM_FEATURE_SVE) && !defined(ARM_FEATURE_MTE)) {
120      sources += freebsd_files
121    }
122  } else {
123    not_needed([ "freebsd_files" ])
124  }
125  cflags = [
126    "-O3",
127    "-fPIC",
128    "-fstack-protector-strong",
129  ]
130
131  if (!(use_libfuzzer || is_mac || is_asan || use_clang_coverage)) {
132    cflags += [ "-flto" ]
133  }
134  if (!defined(include_dirs)) {
135    include_dirs = []
136  }
137  if (musl_arch == "aarch64") {
138    include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ]
139  } else if (musl_arch == "arm") {
140    include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ]
141  }
142  include_dirs += [ "//third_party/FreeBSD/lib/libc/include" ]
143  include_dirs += [ "//third_party/FreeBSD/contrib/libexecinfo" ]
144  include_dirs += [ "//third_party/FreeBSD/crypto/openssh/openbsd-compat" ]
145
146  configs -= build_inherited_configs
147  configs += [ "//build/config/components/musl:soft_musl_config" ]
148}
149