• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1if (is_lite_system && current_os == "ohos") {
2  group("sysroot_lite") {
3    print("ohos_build_compiler:", ohos_build_compiler)
4    print("ohos_kernel_type:", ohos_kernel_type)
5
6    # Mini system of liteos_a needs not prepare for build, so set "kernel_is_prebuilt is true" in
7    # config.json to avoid it.
8    if (!is_mini_system && !ohos_kernel_is_prebuilt) {
9      deps = [ "scripts/build_lite:build" ]
10    } else if (!ohos_kernel_is_prebuilt) {
11      if (ohos_kernel_type == "liteos_m") {
12        all_dependent_configs = [
13          "//kernel/liteos_m:public",
14          "//kernel/liteos_m:kconfig_config",
15        ]
16      } else if (ohos_kernel_type == "uniproton") {
17        all_dependent_configs = [
18          "//kernel/uniproton:os_config",
19          "//kernel/uniproton:kconfig_config",
20        ]
21      }
22    }
23  }
24} else {
25  import("musl_template.gni")
26
27  group("musl_all") {
28    deps = [
29      ":musl_headers",
30      ":soft_libs",
31    ]
32  }
33
34  ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}-test.ini") {
35    source =
36        "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}-test.ini"
37  }
38
39  ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}.ini") {
40    source = "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}.ini"
41    install_images = [
42      "system",
43      "updater",
44      "ramdisk",
45    ]
46  }
47
48  group("musl_ns_config") {
49    deps = [
50      ":ld-musl-namespace-${musl_arch}-test.ini",
51      ":ld-musl-namespace-${musl_arch}.ini",
52    ]
53  }
54
55  group("musl_libs") {
56    deps = [
57      ":musl_headers",
58      ":musl_sysparam",
59      ":musl_sysparam_dac",
60      ":soft_libs",
61    ]
62  }
63
64  ohos_prebuilt_etc("musl_sysparam") {
65    source = "${musl_porting_dir}/etc/musl.para"
66    relative_install_dir = "param"
67  }
68
69  ohos_prebuilt_etc("musl_sysparam_dac") {
70    source = "${musl_porting_dir}/etc/musl.para.dac"
71    relative_install_dir = "param"
72  }
73
74  musl_libs("soft_libs") {
75  }
76
77  group("musl_headers") {
78    deps = [
79      ":copy_uapi",
80      ":create_alltypes_h",
81      ":create_syscall_h",
82      ":create_version_h",
83      ":musl_copy_inc_arpa",
84      ":musl_copy_inc_bits",
85      ":musl_copy_inc_fortify",
86      ":musl_copy_inc_hook",
87      ":musl_copy_inc_info",
88      ":musl_copy_inc_net",
89      ":musl_copy_inc_netinet",
90      ":musl_copy_inc_netpacket",
91      ":musl_copy_inc_root",
92      ":musl_copy_inc_scsi",
93      ":musl_copy_inc_sys",
94      ":musl_copy_inc_trace",
95      ":musl_ns_config",
96    ]
97  }
98
99  action("create_porting_src") {
100    script = "scripts/porting.sh"
101
102    sources_dir = [ "//third_party/musl" ]
103
104    outdir = [ "${target_out_dir}/${musl_ported_dir}" ]
105
106    src_files = musl_src_arch_file
107    src_files += musl_src_file
108    src_files += musl_src_ldso
109    src_files += musl_inc_bits_files
110    src_files += musl_inc_arpa_files
111    src_files += musl_inc_net_files
112    src_files += musl_inc_netinet_files
113    src_files += musl_inc_netpacket_files
114    src_files += musl_inc_scsi_files
115    src_files += musl_inc_sys_files
116    src_files += musl_inc_fortify_files
117    src_files += musl_inc_root_files
118    src_files += [
119      "crt/${musl_arch}/crti.s",
120      "crt/${musl_arch}/crtn.s",
121      "crt/Scrt1.c",
122      "crt/crt1.c",
123      "crt/rcrt1.c",
124      "tools/mkalltypes.sed",
125      "arch/${musl_arch}/bits/alltypes.h.in",
126      "arch/${musl_arch}/bits/syscall.h.in",
127      "include/alltypes.h.in",
128      "VERSION",
129      "tools/version.sh",
130      "tools/install.sh",
131      "scripts/install.py",
132      "scripts/create_alltypes.sh",
133      "scripts/create_vesion.sh",
134      "scripts/create_syscall.sh",
135    ]
136
137    args = [ "-i" ] + rebase_path(sources_dir)
138    args += [ "-o" ] + rebase_path(outdir)
139    args += [ "-p" ] + [ "${musl_target_os}" ]
140
141    foreach(i, src_files) {
142      foreach(s, musl_src_porting_file) {
143        if (i == s) {
144          src_files -= [ "${s}" ]
145        }
146      }
147    }
148
149    outputs = []
150    foreach(s, src_files) {
151      outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
152    }
153
154    foreach(s, musl_src_porting_file) {
155      outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
156    }
157
158    inputs = []
159    foreach(s, src_files) {
160      inputs += [ "${musl_dir}/${s}" ]
161    }
162
163    foreach(s, musl_src_porting_file) {
164      inputs += [ "${musl_porting_dir}/${s}" ]
165    }
166  }
167
168  action("create_alltypes_h") {
169    script = "${target_out_dir}/${musl_ported_dir}/scripts/create_alltypes.sh"
170
171    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/alltypes.h" ]
172
173    sources = [ "${target_out_dir}/${musl_ported_dir}/tools/mkalltypes.sed" ]
174    sources += [
175      "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/alltypes.h.in",
176      "${target_out_dir}/${musl_ported_dir}/include/alltypes.h.in",
177    ]
178
179    args = [ "-o" ] + rebase_path(outputs, root_build_dir)
180    args += rebase_path(sources, root_build_dir)
181
182    deps = [ ":create_porting_src" ]
183  }
184
185  action("create_version_h") {
186    script = "${target_out_dir}/${musl_ported_dir}/scripts/create_vesion.sh"
187
188    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/version.h" ]
189
190    sources = [
191      "${target_out_dir}/${musl_ported_dir}/VERSION",
192      "${target_out_dir}/${musl_ported_dir}/tools/version.sh",
193    ]
194
195    args = rebase_path(sources, root_build_dir)
196    args +=
197        [ rebase_path("${target_out_dir}/${musl_inc_out_dir}", root_build_dir) ]
198
199    deps = [ ":create_porting_src" ]
200  }
201
202  action("create_syscall_h") {
203    script = "${target_out_dir}/${musl_ported_dir}/scripts/create_syscall.sh"
204
205    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/syscall.h" ]
206
207    sources = [ "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/syscall.h.in" ]
208
209    args = rebase_path(sources, root_build_dir)
210    args += rebase_path(outputs, root_build_dir)
211
212    deps = [ ":create_porting_src" ]
213  }
214
215  # if uapi_dir does not exist, then make uapi from linux_kernel_dir
216  if (exec_script("/bin/sh",
217                  [
218                    "-c",
219                    "if [ ! -d " + rebase_path(uapi_dir) +
220                        " ]; then echo true; else echo false; fi",
221                  ],
222                  "value")) {
223    kernel_dir = rebase_path(linux_kernel_dir)
224    kernel_out_dir = "${kernel_dir}/make_output"
225    uapi_dir = "${kernel_out_dir}/usr/include"
226    make_uapi_cmd = "rm -rf ${uapi_dir}"
227    make_uapi_cmd += " && make -C ${kernel_dir} -sj headers O=${kernel_out_dir} ARCH=${target_cpu}"
228    make_uapi_cmd += " && cp -f ${kernel_dir}/drivers/staging/android/uapi/ashmem.h ${uapi_dir}/linux/ashmem.h"
229    make_uapi_cmd += " && sed -i '/#define _INPUT_H/i#define _UAPI_INPUT_H' ${uapi_dir}/linux/input.h"
230    make_uapi_cmd += " && sed -i '/struct __kernel_sockaddr_storage/i#define sockaddr_storage __kernel_sockaddr_storage' ${uapi_dir}/linux/socket.h"
231    args_make_uapi = [ "-c" ]
232    args_make_uapi += [ make_uapi_cmd ]
233    exec_script("/bin/sh", args_make_uapi, "value")
234    uapi_from = "make"
235  } else {
236    uapi_from = "local"
237  }
238
239  uapi_full_path = rebase_path(uapi_dir)
240  arguments_uapi = [ "-c" ]
241
242  # exclude these files because they need special treatment
243  if (uapi_from == "make") {
244    exclude_files = "^asm\$|^scsi\$"
245  } else {
246    exclude_files = "^asm-arm\$|^asm-arm64\$|^scsi\$"
247  }
248
249  arguments_uapi +=
250      [ "ls ${uapi_full_path} | grep -Ev " + "\"" + "${exclude_files}" + "\"" ]
251  uspi_files = exec_script("/bin/sh", arguments_uapi, "list lines")
252
253  # Generate a copy target for each file
254  foreach(file, uspi_files) {
255    copy("copy_uapi_${file}") {
256      sources = [ "${uapi_dir}/${file}" ]
257      outputs = [ "${target_out_dir}/${musl_inc_out_dir}/${file}" ]
258    }
259  }
260
261  group("copy_uapi_scsi") {
262    deps = []
263    sources = []
264    outputs = []
265    uapi_scsi_dir = rebase_path("${uapi_dir}/scsi")
266    arguments_scsi = [ "-c" ]
267    arguments_scsi += [ "ls ${uapi_scsi_dir}" ]
268    uapi_scsi_files = exec_script("/bin/sh", arguments_scsi, "list lines")
269
270    # Generate a copy target for each file in scsi dir to avoid being influenced by musl_copy_inc_scsi output
271    foreach(file, uapi_scsi_files) {
272      copy("copy_uapi_scsi_${file}") {
273        sources += [ "${uapi_dir}/scsi/${file}" ]
274        outputs += [ "${target_out_dir}/${musl_inc_out_dir}/scsi/${file}" ]
275      }
276      deps += [ ":copy_uapi_scsi_${file}" ]
277    }
278  }
279
280  copy("copy_uapi_asm") {
281    if (uapi_from == "local") {
282      if ("${musl_arch}" == "arm") {
283        file_name = "asm-arm"
284      } else {  # aarch64 and x86_64 use same file
285        file_name = "asm-arm64"
286      }
287      sources = [ "${uapi_dir}/${file_name}/asm" ]
288    } else {
289      sources = [ "${uapi_dir}/asm" ]
290    }
291    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/asm" ]
292  }
293
294  group("copy_uapi") {
295    deps = [ ":copy_uapi_scsi" ]
296
297    # We need do different processing for asm according to the source of uapi
298    deps += [ ":copy_uapi_asm" ]
299    foreach(file, uspi_files) {
300      deps += [ ":copy_uapi_${file}" ]
301    }
302  }
303
304  copy("musl_copy_inc_bits") {
305    sources = []
306    sources_orig = musl_inc_bits_files
307    foreach(s, sources_orig) {
308      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
309    }
310    outputs =
311        [ "${target_out_dir}/${musl_inc_out_dir}/bits/{{source_file_part}}" ]
312    deps = [ ":create_porting_src" ]
313  }
314
315  copy("musl_copy_inc_arpa") {
316    sources = []
317    sources_orig = musl_inc_arpa_files
318    foreach(s, sources_orig) {
319      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
320    }
321    outputs =
322        [ "${target_out_dir}/${musl_inc_out_dir}/arpa/{{source_file_part}}" ]
323    deps = [ ":create_porting_src" ]
324  }
325
326  copy("musl_copy_inc_net") {
327    sources = []
328    sources_orig = musl_inc_net_files
329    foreach(s, sources_orig) {
330      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
331    }
332    outputs =
333        [ "${target_out_dir}/${musl_inc_out_dir}/net/{{source_file_part}}" ]
334    deps = [ ":create_porting_src" ]
335  }
336
337  copy("musl_copy_inc_netinet") {
338    sources = []
339    sources_orig = musl_inc_netinet_files
340    foreach(s, sources_orig) {
341      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
342    }
343    outputs =
344        [ "${target_out_dir}/${musl_inc_out_dir}/netinet/{{source_file_part}}" ]
345    deps = [ ":create_porting_src" ]
346  }
347
348  copy("musl_copy_inc_netpacket") {
349    sources = []
350    sources_orig = musl_inc_netpacket_files
351    foreach(s, sources_orig) {
352      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
353    }
354    outputs = [
355      "${target_out_dir}/${musl_inc_out_dir}/netpacket/{{source_file_part}}",
356    ]
357    deps = [ ":create_porting_src" ]
358  }
359
360  copy("musl_copy_inc_scsi") {
361    sources = []
362    sources_orig = musl_inc_scsi_files
363    foreach(s, sources_orig) {
364      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
365    }
366    outputs =
367        [ "${target_out_dir}/${musl_inc_out_dir}/scsi/{{source_file_part}}" ]
368    deps = [ ":create_porting_src" ]
369  }
370
371  copy("musl_copy_inc_sys") {
372    sources = []
373    sources_orig = musl_inc_sys_files
374    foreach(s, sources_orig) {
375      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
376    }
377    outputs =
378        [ "${target_out_dir}/${musl_inc_out_dir}/sys/{{source_file_part}}" ]
379    deps = [ ":create_porting_src" ]
380  }
381
382  copy("musl_copy_inc_trace") {
383    sources = []
384    sources_orig = musl_inc_trace_files
385    foreach(s, sources_orig) {
386      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
387    }
388    outputs =
389        [ "${target_out_dir}/${musl_inc_out_dir}/trace/{{source_file_part}}" ]
390    deps = [ ":create_porting_src" ]
391  }
392
393  copy("musl_copy_inc_info") {
394    sources = []
395    sources_orig = musl_inc_info_files
396    foreach(s, sources_orig) {
397      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
398    }
399    outputs =
400        [ "${target_out_dir}/${musl_inc_out_dir}/info/{{source_file_part}}" ]
401    deps = [ ":create_porting_src" ]
402  }
403
404  copy("musl_copy_inc_fortify") {
405    sources = []
406    sources_orig = musl_inc_fortify_files
407    foreach(s, sources_orig) {
408      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
409    }
410    outputs =
411        [ "${target_out_dir}/${musl_inc_out_dir}/fortify/{{source_file_part}}" ]
412    deps = [ ":create_porting_src" ]
413  }
414
415  copy("musl_copy_inc_root") {
416    sources = []
417    sources_orig = musl_inc_root_files
418    foreach(s, sources_orig) {
419      sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ]
420    }
421    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ]
422    deps = [ ":create_porting_src" ]
423  }
424
425  copy("musl_copy_inc_hook") {
426    sources = musl_inc_hook_files
427    outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ]
428  }
429
430  group("libctest") {
431    testonly = true
432    deps = [ "libc-test:musl_libc_test" ]
433  }
434
435  group("benchmark-musl") {
436    deps = [ "Benchmark/musl:benchmark_musl_group" ]
437  }
438}
439