1# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 2# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without modification, 5# are permitted provided that the following conditions are met: 6# 7# 1. Redistributions of source code must retain the above copyright notice, this list of 8# conditions and the following disclaimer. 9# 10# 2. Redistributions in binary form must reproduce the above copyright notice, this list 11# of conditions and the following disclaimer in the documentation and/or other materials 12# provided with the distribution. 13# 14# 3. Neither the name of the copyright holder nor the names of its contributors may be used 15# to endorse or promote products derived from this software without specific prior written 16# permission. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 20# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 23# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30import("//build/lite/config/component/lite_component.gni") 31import("//kernel/liteos_a/liteos.gni") 32import("$THIRDPARTY_MKSH_DIR/mksh.gni") 33 34group("mksh") { 35 deps = [ ":build_mksh" ] 36} 37 38copy("copy_mksh_src") { 39 sources = MKSH_SRC_DIR 40 outputs = [ "$target_out_dir/mksh_build" ] 41} 42 43build_ext_component("build_mksh") { 44 deps = [ ":copy_mksh_src" ] 45 deps += [ "$THIRDPARTY_MUSL_DIR:sysroot_lite" ] 46 exec_path = rebase_path("$target_out_dir/mksh_build") 47 48 cflags = [ 49 "-flto", 50 "-fdata-sections", 51 "-ffunction-sections", 52 "-fstack-protector-strong", 53 "-D_FORTIFY_SOURCE=2", 54 "-DMKSH_DISABLE_TTY_WARNING", 55 "-DMKSH_SMALL=1", 56 "-DMKSH_ASSUME_UTF8=1", 57 "-DMKSH_SMALL_BUT_FAST=0", 58 "-DMKSH_S_NOVI=1", 59 "-DHAVE_CAN_FSTACKPROTECTORSTRONG=1", 60 "-DMKSH_LESS_CMDLINE_EDITING", 61 "-DMKSH_LESS_BUILDINS", 62 "-DMKSH_NO_INITCOMS", 63 "-DADAPT_FOR_LITEOS_A", 64 ] 65 if (defined(LOSCFG_COMPILER_CLANG_LLVM)) { 66 cflags += [ "-Oz" ] 67 } else { 68 cflags += [ "-O2" ] 69 } 70 cflags = string_join(" ", cflags) 71 72 extra_flags = string_join(" ", target_arch_cflags) 73 if (ohos_build_compiler == "clang") { 74 extra_flags += " --target=$target_triple" 75 extra_flags += " --sysroot=" + rebase_path(ohos_current_sysroot) 76 } 77 78 command = "rm -rf .git && env" 79 command += " CC=\"$ohos_current_cc_command\"" 80 command += " TARGET_OS=OpenHarmony" 81 command += " CFLAGS=\"$cflags $extra_flags\"" 82 command += " LDFLAGS=\"-Wl,--gc-sections -flto -O2\"" 83 command += " sh ./Build.sh -r" 84 85 # copy mksh and .mkshrc to out dir 86 command += " && mkdir -p " 87 command += rebase_path("$root_out_dir/bin", exec_path) 88 command += " && install -D mksh " 89 command += rebase_path("$root_out_dir/unstripped/bin/mksh", exec_path) 90 command += " && $ohos_current_strip_command mksh -o " 91 command += rebase_path("$root_out_dir/bin/mksh", exec_path) 92 command += " && install -D .mkshrc " 93 command += rebase_path("$root_out_dir/etc/.mkshrc", exec_path) 94 95 outputs = [ 96 "$root_out_dir/unstripped/bin/mksh", 97 "$root_out_dir/bin/mksh", 98 "$root_out_dir/etc/.mkshrc", 99 ] 100} 101