From 42bca3f34f2c2db3e8b3a193204a8be9ec68e841 Mon Sep 17 00:00:00 2001 From: arvinzzz Date: Tue, 19 Jul 2022 14:35:52 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20sysroot=E9=83=A8=E4=BB=B6=E5=8C=96?= =?UTF-8?q?=20close:=20#I5HF8S?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: arvinzzz Change-Id: Ie3a53c60ef023eff53a165b6b2c9a4b7cda3fe1e --- BUILD.gn | 602 +++++++++++++++++++----------------- scripts/build_lite/BUILD.gn | 137 ++++++++ scripts/build_lite/Makefile | 183 +++++++++++ 3 files changed, 631 insertions(+), 291 deletions(-) create mode 100644 scripts/build_lite/BUILD.gn create mode 100644 scripts/build_lite/Makefile diff --git a/BUILD.gn b/BUILD.gn index fa522e81..b1892014 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1,349 +1,369 @@ -import("musl_template.gni") - -musl_abi_target = "soft" - -group("musl_all") { - deps = [ - ":a7_hard_neon_libs", - ":a7_soft_libs", - ":a7_softfp_neon_libs", - ":musl_headers", - ":soft_libs", - ] -} +if (is_lite_system && current_os == "ohos") { + group("sysroot_lite") { + print("ohos_build_compiler:", ohos_build_compiler) + print("ohos_kernel_type:", ohos_kernel_type) + + # Mini system of liteos_a needs not prepare for build, so set "kernel_is_prebuilt is true" in + # config.json to avoid it. + if (ohos_kernel_type != "liteos_m" && !ohos_kernel_is_prebuilt) { + deps = [ "scripts/build_lite:build" ] + } else if (!ohos_kernel_is_prebuilt) { + all_dependent_configs = [ + "//kernel/liteos_m:public", + "//kernel/liteos_m:kconfig_config", + ] + } + } +} else { + import("musl_template.gni") + + musl_abi_target = "soft" + + group("musl_all") { + deps = [ + ":a7_hard_neon_libs", + ":a7_soft_libs", + ":a7_softfp_neon_libs", + ":musl_headers", + ":soft_libs", + ] + } -ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}-test.ini") { - source = "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}-test.ini" -} + ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}-test.ini") { + source = + "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}-test.ini" + } -ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}.ini") { - source = "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}.ini" - install_images = [ - "system", - "updater", - ] -} + ohos_prebuilt_etc("ld-musl-namespace-${musl_arch}.ini") { + source = "${musl_porting_dir}/config/ld-musl-namespace-${musl_arch}.ini" + install_images = [ + "system", + "updater", + ] + } -group("musl_ns_config") { - deps = [ - ":ld-musl-namespace-${musl_arch}-test.ini", - ":ld-musl-namespace-${musl_arch}.ini", - ] -} + group("musl_ns_config") { + deps = [ + ":ld-musl-namespace-${musl_arch}-test.ini", + ":ld-musl-namespace-${musl_arch}.ini", + ] + } -group("musl_libs") { - deps = [ - ":${musl_abi_target}_libs", - ":musl_headers", - ] -} + group("musl_libs") { + deps = [ + ":${musl_abi_target}_libs", + ":musl_headers", + ] + } -musl_libs("soft_libs") { - target_abi = "soft" -} + musl_libs("soft_libs") { + target_abi = "soft" + } -musl_libs("a7_soft_libs") { - target_abi = "a7_soft" -} + musl_libs("a7_soft_libs") { + target_abi = "a7_soft" + } -musl_libs("a7_softfp_neon_libs") { - target_abi = "a7_softfp_neon-vfpv4" -} + musl_libs("a7_softfp_neon_libs") { + target_abi = "a7_softfp_neon-vfpv4" + } -musl_libs("a7_hard_neon_libs") { - target_abi = "a7_hard_neon-vfpv4" -} + musl_libs("a7_hard_neon_libs") { + target_abi = "a7_hard_neon-vfpv4" + } -group("musl_headers") { - deps = [ - ":copy_uapi", - ":create_alltypes_h", - ":create_syscall_h", - ":create_version_h", - ":musl_copy_inc_arpa", - ":musl_copy_inc_bits", - ":musl_copy_inc_hook", - ":musl_copy_inc_info", - ":musl_copy_inc_net", - ":musl_copy_inc_netinet", - ":musl_copy_inc_netpacket", - ":musl_copy_inc_root", - ":musl_copy_inc_scsi", - ":musl_copy_inc_sys", - ":musl_copy_inc_trace", - ":musl_ns_config", - ] -} + group("musl_headers") { + deps = [ + ":copy_uapi", + ":create_alltypes_h", + ":create_syscall_h", + ":create_version_h", + ":musl_copy_inc_arpa", + ":musl_copy_inc_bits", + ":musl_copy_inc_hook", + ":musl_copy_inc_info", + ":musl_copy_inc_net", + ":musl_copy_inc_netinet", + ":musl_copy_inc_netpacket", + ":musl_copy_inc_root", + ":musl_copy_inc_scsi", + ":musl_copy_inc_sys", + ":musl_copy_inc_trace", + ":musl_ns_config", + ] + } -action("create_porting_src") { - script = "scripts/porting.sh" - - sources = [ "//third_party/musl" ] - - outdir = [ "${target_out_dir}/${musl_ported_dir}" ] - - src_files = musl_src_arch_file - src_files += musl_src_file - src_files += musl_src_ldso - src_files += musl_inc_bits_files - src_files += musl_inc_arpa_files - src_files += musl_inc_net_files - src_files += musl_inc_netinet_files - src_files += musl_inc_netpacket_files - src_files += musl_inc_scsi_files - src_files += musl_inc_sys_files - src_files += musl_inc_root_files - src_files += [ - "crt/${musl_arch}/crti.s", - "crt/${musl_arch}/crtn.s", - "crt/Scrt1.c", - "crt/crt1.c", - "crt/rcrt1.c", - "tools/mkalltypes.sed", - "arch/${musl_arch}/bits/alltypes.h.in", - "arch/${musl_arch}/bits/syscall.h.in", - "include/alltypes.h.in", - "VERSION", - "tools/version.sh", - "tools/install.sh", - "scripts/install.py", - "scripts/create_alltypes.sh", - "scripts/create_vesion.sh", - "scripts/create_syscall.sh", - ] - - args = [ "-i" ] + rebase_path(sources) - args += [ "-o" ] + rebase_path(outdir) - args += [ "-p" ] + [ "${musl_target_os}" ] - - foreach(i, src_files) { - foreach(s, musl_src_porting_file) { - if (i == s) { - src_files -= [ "${s}" ] + action("create_porting_src") { + script = "scripts/porting.sh" + + sources = [ "//third_party/musl" ] + + outdir = [ "${target_out_dir}/${musl_ported_dir}" ] + + src_files = musl_src_arch_file + src_files += musl_src_file + src_files += musl_src_ldso + src_files += musl_inc_bits_files + src_files += musl_inc_arpa_files + src_files += musl_inc_net_files + src_files += musl_inc_netinet_files + src_files += musl_inc_netpacket_files + src_files += musl_inc_scsi_files + src_files += musl_inc_sys_files + src_files += musl_inc_root_files + src_files += [ + "crt/${musl_arch}/crti.s", + "crt/${musl_arch}/crtn.s", + "crt/Scrt1.c", + "crt/crt1.c", + "crt/rcrt1.c", + "tools/mkalltypes.sed", + "arch/${musl_arch}/bits/alltypes.h.in", + "arch/${musl_arch}/bits/syscall.h.in", + "include/alltypes.h.in", + "VERSION", + "tools/version.sh", + "tools/install.sh", + "scripts/install.py", + "scripts/create_alltypes.sh", + "scripts/create_vesion.sh", + "scripts/create_syscall.sh", + ] + + args = [ "-i" ] + rebase_path(sources) + args += [ "-o" ] + rebase_path(outdir) + args += [ "-p" ] + [ "${musl_target_os}" ] + + foreach(i, src_files) { + foreach(s, musl_src_porting_file) { + if (i == s) { + src_files -= [ "${s}" ] + } } } - } - outputs = [] - foreach(s, src_files) { - outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] - } + outputs = [] + foreach(s, src_files) { + outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } - foreach(s, musl_src_porting_file) { - outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] - } + foreach(s, musl_src_porting_file) { + outputs += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } - inputs = [] - foreach(s, src_files) { - inputs += [ "${musl_dir}/${s}" ] - } + inputs = [] + foreach(s, src_files) { + inputs += [ "${musl_dir}/${s}" ] + } - foreach(s, musl_src_porting_file) { - inputs += [ "${musl_porting_dir}/${s}" ] + foreach(s, musl_src_porting_file) { + inputs += [ "${musl_porting_dir}/${s}" ] + } } -} -action("create_alltypes_h") { - script = "${target_out_dir}/${musl_ported_dir}/scripts/create_alltypes.sh" + action("create_alltypes_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_alltypes.sh" - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/alltypes.h" ] + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/alltypes.h" ] - sources = [ "${target_out_dir}/${musl_ported_dir}/tools/mkalltypes.sed" ] - sources += [ - "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/alltypes.h.in", - "${target_out_dir}/${musl_ported_dir}/include/alltypes.h.in", - ] + sources = [ "${target_out_dir}/${musl_ported_dir}/tools/mkalltypes.sed" ] + sources += [ + "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/alltypes.h.in", + "${target_out_dir}/${musl_ported_dir}/include/alltypes.h.in", + ] - args = [ "-o" ] + rebase_path(outputs, root_build_dir) - args += rebase_path(sources, root_build_dir) + args = [ "-o" ] + rebase_path(outputs, root_build_dir) + args += rebase_path(sources, root_build_dir) - deps = [ ":create_porting_src" ] -} + deps = [ ":create_porting_src" ] + } -action("create_version_h") { - script = "${target_out_dir}/${musl_ported_dir}/scripts/create_vesion.sh" + action("create_version_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_vesion.sh" - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/version.h" ] + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/version.h" ] - sources = [ - "${target_out_dir}/${musl_ported_dir}/VERSION", - "${target_out_dir}/${musl_ported_dir}/tools/version.sh", - ] + sources = [ + "${target_out_dir}/${musl_ported_dir}/VERSION", + "${target_out_dir}/${musl_ported_dir}/tools/version.sh", + ] - args = rebase_path(sources, root_build_dir) - args += - [ rebase_path("${target_out_dir}/${musl_inc_out_dir}", root_build_dir) ] + args = rebase_path(sources, root_build_dir) + args += + [ rebase_path("${target_out_dir}/${musl_inc_out_dir}", root_build_dir) ] - deps = [ ":create_porting_src" ] -} + deps = [ ":create_porting_src" ] + } -action("create_syscall_h") { - script = "${target_out_dir}/${musl_ported_dir}/scripts/create_syscall.sh" + action("create_syscall_h") { + script = "${target_out_dir}/${musl_ported_dir}/scripts/create_syscall.sh" - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/syscall.h" ] + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/bits/syscall.h" ] - sources = [ - "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/syscall.h.in", - ] + sources = [ "${target_out_dir}/${musl_ported_dir}/arch/${musl_arch}/bits/syscall.h.in" ] - args = rebase_path(sources, root_build_dir) - args += rebase_path(outputs, root_build_dir) + args = rebase_path(sources, root_build_dir) + args += rebase_path(outputs, root_build_dir) - deps = [ ":create_porting_src" ] -} + deps = [ ":create_porting_src" ] + } -action("make_uapi") { - kernel_dir = rebase_path(linux_kernel_dir) - kernel_out_dir = rebase_path(get_path_info("${kernel_dir}/", "out_dir")) - uapi_dir = "${kernel_out_dir}/usr/include" - make_uapi_cmd = "rm -rf ${uapi_dir}" - make_uapi_cmd += " && make -C ${kernel_dir} -sj headers O=${kernel_out_dir} ARCH=${target_cpu}" - make_uapi_cmd += " && cp -f ${kernel_dir}/drivers/staging/android/uapi/ashmem.h ${uapi_dir}/linux/ashmem.h" - make_uapi_cmd += " && sed -i '/#define _INPUT_H/i#define _UAPI_INPUT_H' ${uapi_dir}/linux/input.h" - make_uapi_cmd += " && sed -i '/struct __kernel_sockaddr_storage/i#define sockaddr_storage __kernel_sockaddr_storage' ${uapi_dir}/linux/socket.h" - outputs = [ "${target_out_dir}/" + rebase_path(uapi_dir, target_out_dir) ] - script = "/bin/sh" - args = [ "-c" ] - args += [ make_uapi_cmd ] -} + action("make_uapi") { + kernel_dir = rebase_path(linux_kernel_dir) + kernel_out_dir = rebase_path(get_path_info("${kernel_dir}/", "out_dir")) + uapi_dir = "${kernel_out_dir}/usr/include" + make_uapi_cmd = "rm -rf ${uapi_dir}" + make_uapi_cmd += " && make -C ${kernel_dir} -sj headers O=${kernel_out_dir} ARCH=${target_cpu}" + make_uapi_cmd += " && cp -f ${kernel_dir}/drivers/staging/android/uapi/ashmem.h ${uapi_dir}/linux/ashmem.h" + make_uapi_cmd += " && sed -i '/#define _INPUT_H/i#define _UAPI_INPUT_H' ${uapi_dir}/linux/input.h" + make_uapi_cmd += " && sed -i '/struct __kernel_sockaddr_storage/i#define sockaddr_storage __kernel_sockaddr_storage' ${uapi_dir}/linux/socket.h" + outputs = [ "${target_out_dir}/" + rebase_path(uapi_dir, target_out_dir) ] + script = "/bin/sh" + args = [ "-c" ] + args += [ make_uapi_cmd ] + } -# if uapi_dir does not exist, then make uapi from linux_kernel_dir -if (exec_script("/bin/sh", - [ - "-c", - "if [ ! -d " + rebase_path(uapi_dir) + - " ]; then echo true; else echo false; fi", - ], - "value")) { - uapi_dir = get_path_info("${linux_kernel_dir}/", "out_dir") + "/usr/include" - uapi_deps = [ ":make_uapi" ] -} else { - uapi_deps = [] -} + # if uapi_dir does not exist, then make uapi from linux_kernel_dir + if (exec_script("/bin/sh", + [ + "-c", + "if [ ! -d " + rebase_path(uapi_dir) + + " ]; then echo true; else echo false; fi", + ], + "value")) { + uapi_dir = get_path_info("${linux_kernel_dir}/", "out_dir") + "/usr/include" + uapi_deps = [ ":make_uapi" ] + } else { + uapi_deps = [] + } -action("copy_uapi") { - outputs = [ "${target_out_dir}/${musl_inc_out_dir}" ] - inputs = [ uapi_dir ] - deps = uapi_deps - script = "scripts/copy_uapi.sh" - args = [ "-i" ] + rebase_path(inputs) - args += [ "-o" ] + rebase_path(outputs) - args += [ "-t" ] + [ "${musl_arch}" ] -} + action("copy_uapi") { + outputs = [ "${target_out_dir}/${musl_inc_out_dir}" ] + inputs = [ uapi_dir ] + deps = uapi_deps + script = "scripts/copy_uapi.sh" + args = [ "-i" ] + rebase_path(inputs) + args += [ "-o" ] + rebase_path(outputs) + args += [ "-t" ] + [ "${musl_arch}" ] + } -copy("musl_copy_inc_bits") { - sources = [] - sources_orig = musl_inc_bits_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_bits") { + sources = [] + sources_orig = musl_inc_bits_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/bits/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/bits/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_arpa") { - sources = [] - sources_orig = musl_inc_arpa_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_arpa") { + sources = [] + sources_orig = musl_inc_arpa_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/arpa/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/arpa/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_net") { - sources = [] - sources_orig = musl_inc_net_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_net") { + sources = [] + sources_orig = musl_inc_net_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/net/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/net/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_netinet") { - sources = [] - sources_orig = musl_inc_netinet_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_netinet") { + sources = [] + sources_orig = musl_inc_netinet_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/netinet/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/netinet/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_netpacket") { - sources = [] - sources_orig = musl_inc_netpacket_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_netpacket") { + sources = [] + sources_orig = musl_inc_netpacket_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = [ + "${target_out_dir}/${musl_inc_out_dir}/netpacket/{{source_file_part}}", + ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/netpacket/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_scsi") { - sources = [] - sources_orig = musl_inc_scsi_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_scsi") { + sources = [] + sources_orig = musl_inc_scsi_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/scsi/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/scsi/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_sys") { - sources = [] - sources_orig = musl_inc_sys_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_sys") { + sources = [] + sources_orig = musl_inc_sys_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/sys/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/sys/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_trace") { - sources = [] - sources_orig = musl_inc_trace_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_trace") { + sources = [] + sources_orig = musl_inc_trace_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/trace/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/trace/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_info") { - sources = [] - sources_orig = musl_inc_info_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_info") { + sources = [] + sources_orig = musl_inc_info_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = + [ "${target_out_dir}/${musl_inc_out_dir}/info/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = - [ "${target_out_dir}/${musl_inc_out_dir}/info/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_root") { - sources = [] - sources_orig = musl_inc_root_files - foreach(s, sources_orig) { - sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + copy("musl_copy_inc_root") { + sources = [] + sources_orig = musl_inc_root_files + foreach(s, sources_orig) { + sources += [ "${target_out_dir}/${musl_ported_dir}/${s}" ] + } + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ] + deps = [ ":create_porting_src" ] } - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ] - deps = [ ":create_porting_src" ] -} -copy("musl_copy_inc_hook") { - sources = musl_inc_hook_files - outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ] -} + copy("musl_copy_inc_hook") { + sources = musl_inc_hook_files + outputs = [ "${target_out_dir}/${musl_inc_out_dir}/{{source_file_part}}" ] + } -group("libctest") { - testonly = true - deps = [ "libc-test:musl_libc_test" ] + group("libctest") { + testonly = true + deps = [ "libc-test:musl_libc_test" ] + } } diff --git a/scripts/build_lite/BUILD.gn b/scripts/build_lite/BUILD.gn new file mode 100644 index 00000000..41582562 --- /dev/null +++ b/scripts/build_lite/BUILD.gn @@ -0,0 +1,137 @@ +# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 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") + +targets = "" +if (ohos_kernel_type == "liteos_a") { + targets = "liteos_a_user" +} else if (ohos_kernel_type == "linux") { + targets = "linux_user" +} + +assert(targets != "", "Unsupported ohos_kernel_type: $ohos_kernel_type") + +sysroot_path = rebase_path(ohos_current_sysroot) +arch_cflags = string_join(" ", target_arch_cflags) + +build_ext_component("build_sysroot") { + no_default_deps = true + deps = [] + 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" + 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\"" + } + if (ohos_build_type == "debug") { + command += " BUILD_DEBUG=true" + } + if (ohos_kernel_type == "linux") { + deps += [ "//kernel/linux/build:linux_kernel" ] + command += " LINUXDIR=" + rebase_path("$root_out_dir/kernel/linux-4.19") + command += " PREBUILTLINUXHDRDIR=" + rebase_path( + "//kernel/linux/patches/linux-4.19/prebuilts/usr/include") + } + } else { + command = "true" + } + + # copy C/C++ runtime libraries to lib out dir + if (ohos_build_compiler == "clang") { + runtime_libs = [ + "libc++.so", + "libc.so", + ] + compiler_cmd = "$ohos_current_cxx_command --target=$target_triple --sysroot=$sysroot_path $arch_cflags" + } else { + runtime_libs = [ + "libstdc++.so.6", + "libc.so", + "libgcc_s.so.1", + ] + compiler_cmd = + "$ohos_current_cxx_command --sysroot=$sysroot_path $arch_cflags" + } + + libs = [] + outputs = [] + foreach(lib, runtime_libs) { + libs += [ "\$($compiler_cmd -print-file-name=$lib)" ] + outputs += [ "$root_out_dir/unstripped/usr/lib/$lib" ] + } + + lib_out_dir = rebase_path("$root_out_dir/unstripped/usr/lib", exec_path) + command += " && mkdir -p $lib_out_dir && sh -c \"cp -f " + + string_join(" ", libs) + " $lib_out_dir\"" +} + +action_foreach("strip") { + no_default_deps = true + deps = [ ":build_sysroot" ] + script = "//build/lite/run_shell_cmd.py" + set_sources_assignment_filter([ "*.txt" ]) + sources = get_target_outputs(deps[0]) + outputs = [ "$root_out_dir/libs/{{source_file_part}}" ] + args = [ + "$ohos_current_strip_command", + "{{source}}", + "-o", + rebase_path("$root_out_dir/libs/{{source_file_part}}", root_build_dir), + ] +} + +config("sysroot_flags") { + if (ohos_build_compiler == "clang") { + cflags = [ + "--target=$target_triple", + "--sysroot=$sysroot_path", + ] + } else { + cflags = [ + "--sysroot=$sysroot_path", + "-specs=musl-gcc.specs", + ] + } + cflags_cc = cflags + ldflags = cflags + asmflags = cflags +} + +group("build") { + all_dependent_configs = [ ":sysroot_flags" ] + deps = [ + ":build_sysroot", + ":strip", + ] +} diff --git a/scripts/build_lite/Makefile b/scripts/build_lite/Makefile new file mode 100644 index 00000000..f15b9834 --- /dev/null +++ b/scripts/build_lite/Makefile @@ -0,0 +1,183 @@ +# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. +# Copyright (c) 2020-2022 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. + +ARCH = arm +ifneq ($(GCC),) +TARGET = +CROSS_COMPILE = $(GCC:%gcc=%) +CC = $(GCC) $(ARCH_CFLAGS) +MULTILIB = $(patsubst %.,%,$(shell $(CC) -print-multi-directory)) +else +TARGET = $(ARCH)-liteos-ohos +CLANG ?= clang +CROSS_COMPILE = $(CLANG:%clang=%llvm-) +CC = $(CLANG) --target=$(TARGET) $(ARCH_CFLAGS) +MULTILIB = $(patsubst $(dir $(shell $(filter-out $(ARCH_CFLAGS),$(CC)) -print-libgcc-file-name))%,/%,$(dir $(shell $(CC) -print-libgcc-file-name))) +endif +MUSLBUILDDIR = build_$(or $(TARGET),$(ARCH))$(subst /,_,$(MULTILIB:%/=%)) +HIDE = @ +BUILD_DEBUG = false +SED_ARGS = -e '/install-libs:/s/if/and/g' + +TOPDIR = $(shell pwd)/../../../.. +MUSLDIR = $(TOPDIR)/third_party/musl +LINUXKERNELDIR = $(TOPDIR)/kernel/linux/linux-5.10 +OPTRTDIR = $(TOPDIR)/third_party/optimized-routines +NUTTXDIR = $(TOPDIR)/third_party/NuttX +SYSROOTDIR = $(TOPDIR)/third_party/musl +LITEOSADIR = $(TOPDIR)/kernel/liteos_a +LINUXDIR = $(TOPDIR)/kernel/linux/linux-4.19 +LINUXHDRDIR = $(PREBUILTLINUXHDRDIR) + +TARGETS = $(if $(wildcard $(LITEOSADIR)),liteos_a_user,) +TARGETS += $(if $(wildcard $(LINUXDIR)),linux_user,) + +define LINUX_TYPES_H +/* Auto generated file at $(shell date), do NOT edit! */ +#ifndef _LINUX_TYPES_H +#define _LINUX_TYPES_H +#include +typedef uint32_t __u32, __le32; +#endif +endef +export LINUX_TYPES_H + +ifeq ($(ARCH),arm) +ARCH_CFLAGS = -mfloat-abi=softfp -mcpu=cortex-a7 -mfpu=neon-vfpv4 +else +$(warning *** warning: ARCH $(ARCH) has not been tested yet, use with cautions!) +ARCH_CFLAGS = +endif + +CFLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wl,-z,relro,-z,now,-z,noexecstack -Wl,--build-id=sha1 + +.PHONY: $(TARGETS:%=musl_copy_for_%) +.PHONY: $(TARGETS:%=musl_patch_for_%) +.PHONY: $(TARGETS:%=musl_install_for_%) +.PHONY: $(TARGETS:%=linux_header_install_for_%) +.PHONY: $(TARGETS:%=nuttx_header_install_for_%) +.PHONY: $(TARGETS:%=optimized_routines_install_for_%) +.PHONY: all clean distclean + +all: $(TARGETS:%=musl_install_for_%) + +$(TARGETS:%=musl_copy_for_%): + $(HIDE) mkdir -p $@ + $(HIDE) cp -rfu $(MUSLDIR)/[^p]* $@ + +optimized_routines_install_for_liteos_a_user: musl_copy_for_liteos_a_user +ifneq ($(ARCH),) + $(HIDE) cp -rfp $(OPTRTDIR)/string/$(ARCH)/* $> $ $ $/dev/null && \ + sed $(SED_ARGS) Makefile | make -f- -sj install + +ifeq ($(wildcard $(LINUXHDRDIR)),) +LINUXHDRDIR = $(shell pwd)/linux_header_install_for_linux_user/usr/include +linux_header_install_for_linux_user: + $(HIDE) make -sj headers_install ARCH=$(ARCH) O=$(shell pwd)/$@ -C $(LINUXDIR) +musl_patch_for_linux_user: linux_header_install_for_linux_user +endif + +musl_patch_for_linux_user: musl_copy_for_linux_user + $(HIDE) cp -rfp $(MUSLDIR)/porting/linux/user/* $/dev/null && \ + sed $(SED_ARGS) Makefile | make -f- -sj install + $(HIDE) cp -rfp $(LINUXHDRDIR)/* $(SYSROOTDIR)/usr/include/$(TARGET) + $(HIDE) if [ -d $(LINUXHDRDIR)/asm-$(ARCH)/asm ]; then ln -snf asm-$(ARCH)/asm $(SYSROOTDIR)/usr/include/$(TARGET)/; fi + +clean: + $(HIDE) rm -rf musl_copy_for_* linux_header_install_for_* + +distclean: clean + $(HIDE) rm -rf $(SYSROOTDIR)/lib $(SYSROOTDIR)/usr -- GitLab