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