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