• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
102template("freebsd_libc_template") {
103  __use_flto = invoker.freebsd_use_flto
104  static_library(target_name) {
105    sources = [
106      "contrib/tcp_wrappers/strcasecmp.c",
107      "lib/libc/gen/arc4random.c",
108      "lib/libc/gen/arc4random_uniform.c",
109      "lib/libc/stdlib/qsort.c",
110      "lib/libc/stdlib/strtoimax.c",
111      "lib/libc/stdlib/strtoul.c",
112      "lib/libc/stdlib/strtoumax.c",
113    ]
114    if (!is_llvm_build) {
115      sources += [ "contrib/libexecinfo/unwind.c" ]
116    }
117    if (musl_arch == "arm") {
118      sources += freebsd_files
119    } else if (musl_arch == "aarch64") {
120      sources += [ "lib/msun/src/s_frexpl.c" ]
121      if (!defined(ARM_FEATURE_SVE) && !defined(ARM_FEATURE_MTE)) {
122        sources += freebsd_files
123      }
124    } else {
125      not_needed([ "freebsd_files" ])
126    }
127    cflags = [
128      "-O3",
129      "-fPIC",
130      "-fstack-protector-strong",
131    ]
132
133    if (!(use_libfuzzer || is_mac || is_asan || use_clang_coverage) &&
134        __use_flto) {
135      cflags += [ "-flto" ]
136    } else {
137      not_needed([ "__use_flto" ])
138    }
139    if (!defined(include_dirs)) {
140      include_dirs = []
141    }
142    if (musl_arch == "aarch64") {
143      include_dirs += [ "//third_party/FreeBSD/lib/libc/aarch64" ]
144    } else if (musl_arch == "arm") {
145      include_dirs += [ "//third_party/FreeBSD/lib/libc/arm" ]
146    }
147    include_dirs += [ "//third_party/FreeBSD/lib/libc/include" ]
148    include_dirs += [ "//third_party/FreeBSD/contrib/libexecinfo" ]
149    include_dirs += [ "//third_party/FreeBSD/crypto/openssh/openbsd-compat" ]
150
151    configs -= build_inherited_configs
152    configs += [ "//build/config/components/musl:soft_musl_config" ]
153  }
154}
155
156freebsd_libc_template("libc_static") {
157  freebsd_use_flto = true
158}
159
160freebsd_libc_template("libc_static_noflto") {
161  freebsd_use_flto = false
162}
163