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 30LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))) 31export LITEOSTOPDIR 32 33APPS = apps 34ROOTFS = rootfs 35LITEOS_TARGET = liteos 36LITEOS_LIBS_TARGET = libs 37KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config)) 38 39ohos_kernel ?= liteos_a 40$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line))) 41ifneq ($(ohos_kernel),liteos_a) 42$(error The selected product ($(ohos_product)) is not a liteos_a kernel type product) 43endif 44 45ifeq ($(PRODUCT_PATH),) 46PRODUCT_PATH:=$(ohos_product_path) 47endif 48 49ifeq ($(DEVICE_PATH),) 50DEVICE_PATH:=$(ohos_device_path) 51endif 52 53ifeq ($(TEE:1=y),y) 54tee = _tee 55endif 56ifeq ($(RELEASE:1=y),y) 57CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config 58else 59CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config 60endif 61 62KCONFIG_CONFIG ?= $(CONFIG) 63SYSROOT_PATH ?= $(OUT)/sysroot 64LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h 65LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config 66 67# export los_config.mk related environment variables 68export LITEOS_MENUCONFIG_H 69export LITEOS_CONFIG_FILE 70 71# export subdir Makefile related environment variables 72export SYSROOT_PATH 73export PRODUCT_PATH 74export DEVICE_PATH 75 76# export kconfig related environment variables 77export CONFIG_=LOSCFG_ 78export srctree=$(LITEOSTOPDIR) 79 80include $(LITEOSTOPDIR)/config.mk 81 82ifeq ($(LOSCFG_STORAGE_SPINOR), y) 83FSTYPE = jffs2 84endif 85ifeq ($(LOSCFG_STORAGE_EMMC), y) 86FSTYPE = vfat 87endif 88ifeq ($(LOSCFG_STORAGE_SPINAND), y) 89FSTYPE = yaffs2 90endif 91ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y) 92FSTYPE = jffs2 93endif 94ROOTFS_DIR = $(OUT)/rootfs 95ROOTFS_ZIP = $(OUT)/rootfs.zip 96 97define HELP = 98Usage: make [TARGET]... [PARAMETER=VALUE]... 99 100Targets: 101 help: display this help and exit 102 clean: clean compiled objects 103 cleanall: clean all build outputs 104 all: make liteos kernel image and rootfs image (Default target) 105 $(APPS): build all apps 106 $(ROOTFS): make a original rootfs image 107 $(LITEOS_LIBS_TARGET): compile all kernel modules (libraries) 108 $(LITEOS_TARGET): make liteos kernel image 109 update_config: update product kernel config (use menuconfig) 110 xxconfig: invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS)) 111 112Parameters: 113 FSTYPE: value should be one of (jffs2 vfat yaffs2) 114 TEE: boolean value(1 or y for true), enable tee 115 RELEASE: boolean value(1 or y for true), build release version 116 CONFIG: kernel config file to be use 117 args: arguments for xxconfig command 118endef 119export HELP 120 121all: $(LITEOS_TARGET) $(ROOTFS) 122 123help: 124 $(HIDE)echo "$$HELP" 125 126sysroot: 127 $(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH)) 128ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) 129ifeq ($(origin SYSROOT_PATH),file) 130 $(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \ 131 ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \ 132 $(MAKE) TARGETS=liteos_a_user \ 133 ARCH=$(ARCH) \ 134 TARGET=$(LOSCFG_LLVM_TARGET) \ 135 ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \ 136 TOPDIR="$(LITEOSTOPDIR)/../.." \ 137 SYSROOTDIR="$(SYSROOT_PATH)" \ 138 CLANG="$(LITEOS_COMPILER_PATH)clang" \ 139 BUILD_ALL_MULTILIB=false \ 140 BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false) 141endif 142endif 143 144$(filter-out menuconfig,$(KCONFIG_CMDS)): 145 $(HIDE)$@ $(args) 146 147$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG) 148 $(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H) 149 150update_config menuconfig: 151 $(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)" 152 153$(LITEOS_LIBS_TARGET): sysroot 154 $(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done 155 156$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET) 157$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).map 158#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).objsize 159$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).bin 160$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).sym.sorted 161$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).asm 162#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).size 163 164$(OUT)/$(LITEOS_TARGET): $(LITEOS_LIBS_TARGET) 165 $(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) -Map=$@.map -o $@ --start-group $(LITEOS_LIBDEP) --end-group 166$(OUT)/$(LITEOS_TARGET).map: $(OUT)/$(LITEOS_TARGET) 167$(OUT)/$(LITEOS_TARGET).objsize: $(LITEOS_LIBS_TARGET) 168 $(SIZE) -t --common $(OUT)/lib/*.a >$@ 169$(OUT)/$(LITEOS_TARGET).bin: $(OUT)/$(LITEOS_TARGET) 170 $(OBJCOPY) -O binary $< $@ 171$(OUT)/$(LITEOS_TARGET).sym.sorted: $(OUT)/$(LITEOS_TARGET) 172 $(OBJDUMP) -t $< |sort >$@ 173$(OUT)/$(LITEOS_TARGET).asm: $(OUT)/$(LITEOS_TARGET) 174 $(OBJDUMP) -d $< >$@ 175$(OUT)/$(LITEOS_TARGET).size: $(OUT)/$(LITEOS_TARGET) 176 $(NM) -S --size-sort $< >$@ 177 178$(APPS): sysroot 179 $(HIDE)$(MAKE) -C apps all 180 181$(ROOTFS): $(APPS) 182 $(HIDE)mkdir -p $(OUT)/musl 183ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y) 184 $(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl 185 $(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl 186else 187 $(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl 188 $(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libgcc_s.so.1) $(OUT)/musl 189 $(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libstdc++.so.6) $(OUT)/musl 190endif 191 $(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR) 192 $(HIDE)shopt -s nullglob && $(STRIP) $(ROOTFS_DIR)/bin/* $(ROOTFS_DIR)/lib/* 193ifneq ($(VERSION),) 194 $(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR) 195endif 196 $(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE) 197 $(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS) 198 199clean: 200 $(HIDE)if [ -d $(SYSROOT_PATH)/build ]; then $(MAKE) -C $(SYSROOT_PATH)/build clean; fi 201 $(HIDE)for dir in $(LIB_SUBDIRS) apps; do $(MAKE) -C $$dir clean || exit 1; done 202 $(HIDE)$(RM) $(LITEOS_MENUCONFIG_H) 203 $(HIDE)echo "clean $(LOSCFG_PLATFORM) finish" 204 205cleanall: clean 206 $(HIDE)$(RM) $(LITEOSTOPDIR)/out $(LITEOS_CONFIG_FILE) 207 $(HIDE)echo "clean all done" 208 209.PHONY: all clean cleanall sysroot help update_config 210.PHONY: $(LITEOS_TARGET) $(ROOTFS) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET) $(KCONFIG_CONFIG) 211