From c54bfa16e3907482c252e9738192df869c63326e Mon Sep 17 00:00:00 2001 From: Caoruihong Date: Fri, 30 Jul 2021 10:08:25 +0800 Subject: [PATCH] feat: enable gn build for toybox and mksh toybox and mksh are built by gn now, and make build for toybox and mksh are disabled now. Signed-off-by: Caoruihong Change-Id: I46810ab418344d9841ec55cb9f1ad2dc2d15b008 --- Makefile | 7 +++--- apps/BUILD.gn | 6 ++--- apps/mksh/BUILD.gn | 53 ++++++++++++++++++++++++++++++++++++++++++-- apps/module.mk | 4 ++-- apps/toybox/BUILD.gn | 37 +++++++++++++++++++++++++++++-- 5 files changed, 95 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index b0b1014e..c0e14748 100644 --- a/Makefile +++ b/Makefile @@ -152,8 +152,9 @@ $(LITEOS_LIBS_TARGET): $(__LIBS) sysroot $(HIDE)echo "=============== make lib done ===============" ##### make menuconfig ##### -menuconfig: - $(HIDE)menuconfig +KCONFIG_CMDS = $(notdir $(wildcard $(dir $(shell which menuconfig))*config)) +$(KCONFIG_CMDS): + $(HIDE)$@ $(args) ##### menuconfig end ####### $(LITEOS_MENUCONFIG_H): .config @@ -229,4 +230,4 @@ update_config: $(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig && savedefconfig --out "$(CONFIG)" .PHONY: all lib clean cleanall $(LITEOS_TARGET) debug release help update_all_config update_config -.PHONY: prepare sysroot cleanrootfs $(ROOTFS) $(ROOTFSDIR) $(APPS) menuconfig $(LITEOS_LIBS_TARGET) $(__LIBS) $(OUT) +.PHONY: prepare sysroot cleanrootfs $(ROOTFS) $(ROOTFSDIR) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET) $(__LIBS) $(OUT) diff --git a/apps/BUILD.gn b/apps/BUILD.gn index 3e197007..2edc1d0c 100644 --- a/apps/BUILD.gn +++ b/apps/BUILD.gn @@ -35,13 +35,13 @@ group("apps") { if (defined(LOSCFG_SHELL)) { deps += [ "shell", - #"mksh", - #"toybox", + "mksh", + "toybox", ] } if (defined(LOSCFG_USER_INIT_DEBUG)) { - #deps += [ "init" ] + deps += [ "init" ] } if (defined(LOSCFG_NET_LWIP_SACK_TFTP)) { diff --git a/apps/mksh/BUILD.gn b/apps/mksh/BUILD.gn index a09888e5..12e6691e 100644 --- a/apps/mksh/BUILD.gn +++ b/apps/mksh/BUILD.gn @@ -34,7 +34,56 @@ group("mksh") { deps = [ ":build_mksh" ] } +copy("copy_mksh_src") { + sources = [ "$LITEOSTHIRDPARTY/mksh" ] + outputs = [ "$target_out_dir/mksh_build" ] +} + build_ext_component("build_mksh") { - exec_path = rebase_path(target_out_dir) - command = "make -C $LITEOSTHIRDPARTY/mksh" + deps = [ ":copy_mksh_src" ] + deps += [ "//prebuilts/lite/sysroot" ] + exec_path = rebase_path("$target_out_dir/mksh_build") + + cflags = [ + "-flto", + "-fdata-sections", + "-ffunction-sections", + "-Oz", + "-fstack-protector-strong", + "-D_FORTIFY_SOURCE=2", + "-DMKSH_DISABLE_TTY_WARNING", + "-DMKSH_SMALL=1", + "-DMKSH_ASSUME_UTF8=1", + "-DMKSH_SMALL_BUT_FAST=0", + "-DMKSH_S_NOVI=1", + "-DHAVE_CAN_FSTACKPROTECTORSTRONG=1", + "-DMKSH_LESS_CMDLINE_EDITING", + "-DMKSH_LESS_BUILDINS", + "-DMKSH_NO_INITCOMS", + "-DADAPT_FOR_LITEOS_A", + ] + cflags = string_join(" ", cflags) + + extra_flags = string_join(" ", target_arch_cflags) + if (ohos_build_compiler == "clang") { + extra_flags += " --target=$target_triple" + extra_flags += " --sysroot=" + rebase_path(ohos_current_sysroot) + } + + command = "rm -rf .git && env" + command += " CC=\"$ohos_current_cc_command\"" + command += " TARGET_OS=OpenHarmony" + command += " CFLAGS=\"$cflags $extra_flags\"" + command += " LDFLAGS=\"-Wl,--gc-sections -flto -O2\"" + command += " sh ./Build.sh -r" + + # copy mksh and .mkshrc to out dir + command += " && mkdir -p " + command += rebase_path("$root_out_dir/bin", exec_path) + command += " " + command += rebase_path("$root_out_dir/etc", exec_path) + command += " && $ohos_current_strip_command mksh -o " + command += rebase_path("$root_out_dir/bin/mksh", exec_path) + command += " && cp -f .mkshrc " + command += rebase_path("$root_out_dir/etc", exec_path) } diff --git a/apps/module.mk b/apps/module.mk index 5b246a45..285a1bc4 100644 --- a/apps/module.mk +++ b/apps/module.mk @@ -33,8 +33,8 @@ APP_SUBDIRS := ifeq ($(LOSCFG_SHELL), y) APP_SUBDIRS += shell -APP_SUBDIRS += mksh -APP_SUBDIRS += toybox +#APP_SUBDIRS += mksh +#APP_SUBDIRS += toybox endif ifeq ($(LOSCFG_USER_INIT_DEBUG), y) diff --git a/apps/toybox/BUILD.gn b/apps/toybox/BUILD.gn index 8438e89e..1edb7d05 100644 --- a/apps/toybox/BUILD.gn +++ b/apps/toybox/BUILD.gn @@ -34,7 +34,40 @@ group("toybox") { deps = [ ":build_toybox" ] } +copy("copy_toybox_src") { + sources = [ "$LITEOSTHIRDPARTY/toybox" ] + outputs = [ "$target_out_dir/toybox_build" ] +} + +copy("copy_toybox_config") { + deps = [ ":copy_toybox_src" ] + sources = [ "liteos_a_custom.config" ] + outputs = [ "$target_out_dir/{{source_file_part}}" ] +} + build_ext_component("build_toybox") { - exec_path = rebase_path(target_out_dir) - command = "make -C $LITEOSTHIRDPARTY/toybox" + deps = [ ":copy_toybox_src", ":copy_toybox_config" ] + deps += [ "//prebuilts/lite/sysroot" ] + exec_path = rebase_path("$target_out_dir/toybox_build") + + cflags = [ + "-fstack-protector-strong", + "-D_FORTIFY_SOURCE=2", + ] + cflags = string_join(" ", cflags) + + extra_flags = string_join(" ", target_arch_cflags) + if (ohos_build_compiler == "clang") { + extra_flags += " --target=$target_triple" + extra_flags += " --sysroot=" + rebase_path(ohos_current_sysroot) + } + + command = "rm -rf .git && cp -rfp porting/liteos_a/. . && env" + command += " CC=\"$ohos_current_cc_command\"" + command += " STRIP=\"$ohos_current_strip_command\"" + command += " OUTNAME=toybox" + command += " CFLAGS=\"$cflags $extra_flags\"" + command += " make toybox" + command += " && install -D toybox " + command += rebase_path("$root_out_dir/bin/toybox", exec_path) } -- GitLab