Makefile 7.6 KB
Newer Older
M
mamingshuai 已提交
1 2
# Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
# Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
W
wenjun 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
#    conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
#    of conditions and the following disclaimer in the documentation and/or other materials
#    provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used
#    to endorse or promote products derived from this software without specific prior written
#    permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

30
LITEOSTOPDIR := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
31
export LITEOSTOPDIR
W
wenjun 已提交
32 33 34 35

APPS = apps
ROOTFS = rootfs
LITEOS_TARGET = liteos
C
Caoruihong 已提交
36
LITEOS_LIBS_TARGET = libs
37
KCONFIG_CMDS := $(notdir $(wildcard $(dir $(shell which menuconfig))*config))
C
Caoruihong 已提交
38 39 40 41 42 43

ohos_kernel ?= liteos_a
$(foreach line,$(shell hb env | sed 's/\[OHOS INFO\]/ohos/g;s/ /_/g;s/:_/=/g' || true),$(eval $(line)))
ifneq ($(ohos_kernel),liteos_a)
$(error The selected product ($(ohos_product)) is not a liteos_a kernel type product)
endif
W
wenjun 已提交
44

45
ifeq ($(PRODUCT_PATH),)
C
Caoruihong 已提交
46
PRODUCT_PATH:=$(ohos_product_path)
47
endif
C
Caoruihong 已提交
48

49
ifeq ($(DEVICE_PATH),)
C
Caoruihong 已提交
50
DEVICE_PATH:=$(ohos_device_path)
51 52 53 54 55 56
endif

ifeq ($(TEE:1=y),y)
tee = _tee
endif
ifeq ($(RELEASE:1=y),y)
57
CONFIG ?= $(PRODUCT_PATH)/kernel_configs/release$(tee).config
58
else
59
CONFIG ?= $(PRODUCT_PATH)/kernel_configs/debug$(tee).config
M
mamingshuai 已提交
60 61
endif

C
Caoruihong 已提交
62
KCONFIG_CONFIG ?= $(CONFIG)
C
Caoruihong 已提交
63
SYSROOT_PATH ?= $(OUT)/sysroot
64 65
LITEOS_MENUCONFIG_H ?= $(LITEOSTOPDIR)/config.h
LITEOS_CONFIG_FILE ?= $(LITEOSTOPDIR)/.config
M
mamingshuai 已提交
66

67 68 69 70 71 72 73 74 75 76 77 78 79 80
# export los_config.mk related environment variables
export LITEOS_MENUCONFIG_H
export LITEOS_CONFIG_FILE

# export subdir Makefile related environment variables
export SYSROOT_PATH
export PRODUCT_PATH
export DEVICE_PATH

# export kconfig related environment variables
export CONFIG_=LOSCFG_
export srctree=$(LITEOSTOPDIR)

include $(LITEOSTOPDIR)/config.mk
M
mamingshuai 已提交
81 82

ifeq ($(LOSCFG_STORAGE_SPINOR), y)
W
wenjun 已提交
83 84
FSTYPE = jffs2
endif
M
mamingshuai 已提交
85
ifeq ($(LOSCFG_STORAGE_EMMC), y)
W
wenjun 已提交
86 87
FSTYPE = vfat
endif
M
mamingshuai 已提交
88 89 90
ifeq ($(LOSCFG_STORAGE_SPINAND), y)
FSTYPE = yaffs2
endif
91
ifeq ($(LOSCFG_PLATFORM_QEMU_ARM_VIRT_CA7), y)
M
mamingshuai 已提交
92
FSTYPE = jffs2
93
endif
W
wenjun 已提交
94 95 96
ROOTFS_DIR = $(OUT)/rootfs
ROOTFS_ZIP = $(OUT)/rootfs.zip

C
Caoruihong 已提交
97 98 99 100 101 102 103 104
define HELP =
Usage: make [TARGET]... [PARAMETER=VALUE]...

Targets:
    help:       display this help and exit
    clean:      clean compiled objects
    cleanall:   clean all build outputs
    all:        make liteos kernel image and rootfs image (Default target)
105 106
    $(APPS):       build all apps
    $(ROOTFS):     make a original rootfs image
C
Caoruihong 已提交
107 108 109
    $(LITEOS_LIBS_TARGET):       compile all kernel modules (libraries)
    $(LITEOS_TARGET):     make liteos kernel image
    update_config:  update product kernel config (use menuconfig)
110
    xxconfig:   invoke xxconfig command of kconfiglib (xxconfig is one of $(KCONFIG_CMDS))
C
Caoruihong 已提交
111 112 113 114 115 116

Parameters:
    FSTYPE:     value should be one of (jffs2 vfat yaffs2)
    TEE:        boolean value(1 or y for true), enable tee
    RELEASE:    boolean value(1 or y for true), build release version
    CONFIG:     kernel config file to be use
117
    args:       arguments for xxconfig command
C
Caoruihong 已提交
118 119 120 121
endef
export HELP

all: $(LITEOS_TARGET) $(ROOTFS)
W
wenjun 已提交
122 123

help:
C
Caoruihong 已提交
124
	$(HIDE)echo "$$HELP"
W
wenjun 已提交
125

126
sysroot:
C
Caoruihong 已提交
127
	$(HIDE)echo "sysroot:" $(abspath $(SYSROOT_PATH))
128
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
C
Caoruihong 已提交
129 130 131 132 133 134 135 136 137 138 139 140
ifeq ($(origin SYSROOT_PATH),file)
	$(HIDE)mkdir -p $(SYSROOT_PATH)/build && cd $(SYSROOT_PATH)/build && \
	ln -snf $(LITEOSTOPDIR)/../../prebuilts/lite/sysroot/build/Makefile && \
	$(MAKE) TARGETS=liteos_a_user \
		ARCH=$(ARCH) \
		TARGET=$(LOSCFG_LLVM_TARGET) \
		ARCH_CFLAGS="$(LITEOS_CORE_COPTS) -w" \
		TOPDIR="$(LITEOSTOPDIR)/../.." \
		SYSROOTDIR="$(SYSROOT_PATH)" \
		CLANG="$(LITEOS_COMPILER_PATH)clang" \
		BUILD_ALL_MULTILIB=false \
		BUILD_DEBUG=$(if $(patsubst y,,$(or $(RELEASE:1=y),n)),true,false)
141 142 143
endif
endif

144
$(filter-out menuconfig,$(KCONFIG_CMDS)):
145
	$(HIDE)$@ $(args)
W
wenjun 已提交
146

147 148
$(LITEOS_CONFIG_FILE): $(KCONFIG_CONFIG)
	$(HIDE)env KCONFIG_CONFIG=$< genconfig --config-out $@ --header-path $(LITEOS_MENUCONFIG_H)
W
wenjun 已提交
149

150 151
update_config menuconfig:
	$(HIDE)test -f "$(CONFIG)" && cp -v "$(CONFIG)" .config && menuconfig $(args) && savedefconfig --out "$(CONFIG)"
W
wenjun 已提交
152

C
Caoruihong 已提交
153
$(LITEOS_LIBS_TARGET): sysroot
154
	$(HIDE)for dir in $(LIB_SUBDIRS); do $(MAKE) -C $$dir all || exit 1; done
C
Caoruihong 已提交
155 156 157 158

$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET)
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).map
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).objsize
159
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).bin
C
Caoruihong 已提交
160 161 162 163 164 165 166 167 168
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).sym.sorted
$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).asm
#$(LITEOS_TARGET): $(OUT)/$(LITEOS_TARGET).size

$(OUT)/$(LITEOS_TARGET): $(LITEOS_LIBS_TARGET)
	$(LD) $(LITEOS_LDFLAGS) $(LITEOS_TABLES_LDFLAGS) -Map=$@.map -o $@ --start-group $(LITEOS_LIBDEP) --end-group
$(OUT)/$(LITEOS_TARGET).map: $(OUT)/$(LITEOS_TARGET)
$(OUT)/$(LITEOS_TARGET).objsize: $(LITEOS_LIBS_TARGET)
	$(SIZE) -t --common $(OUT)/lib/*.a >$@
169
$(OUT)/$(LITEOS_TARGET).bin: $(OUT)/$(LITEOS_TARGET)
C
Caoruihong 已提交
170 171 172 173 174 175 176 177
	$(OBJCOPY) -O binary $< $@
$(OUT)/$(LITEOS_TARGET).sym.sorted: $(OUT)/$(LITEOS_TARGET)
	$(OBJDUMP) -t $< |sort >$@
$(OUT)/$(LITEOS_TARGET).asm: $(OUT)/$(LITEOS_TARGET)
	$(OBJDUMP) -d $< >$@
$(OUT)/$(LITEOS_TARGET).size: $(OUT)/$(LITEOS_TARGET)
	$(NM) -S --size-sort $< >$@

C
Caoruihong 已提交
178
$(APPS): sysroot
W
wenjun 已提交
179 180
	$(HIDE)$(MAKE) -C apps all

C
Caoruihong 已提交
181
$(ROOTFS): $(APPS)
182
	$(HIDE)mkdir -p $(OUT)/musl
W
wenjun 已提交
183
ifeq ($(LOSCFG_COMPILER_CLANG_LLVM), y)
C
Caoruihong 已提交
184 185
	$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl
	$(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libc++.so) $(OUT)/musl
W
wenjun 已提交
186
else
C
Caoruihong 已提交
187 188 189
	$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libc.so) $(OUT)/musl
	$(HIDE)cp -fp $$($(CC) $(LITEOS_CFLAGS) -print-file-name=libgcc_s.so.1) $(OUT)/musl
	$(HIDE)cp -fp $$($(GPP) $(LITEOS_CXXFLAGS) -print-file-name=libstdc++.so.6) $(OUT)/musl
W
wenjun 已提交
190
endif
191
	$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsdir.sh $(OUT) $(ROOTFS_DIR)
192
	$(HIDE)shopt -s nullglob && $(STRIP) $(ROOTFS_DIR)/bin/* $(ROOTFS_DIR)/lib/*
W
wenjun 已提交
193
ifneq ($(VERSION),)
194
	$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/releaseinfo.sh "$(VERSION)" $(ROOTFS_DIR)
W
wenjun 已提交
195
endif
196
	$(HIDE)$(LITEOS_SCRIPTPATH)/make_rootfs/rootfsimg.sh $(ROOTFS_DIR) $(FSTYPE)
W
wenjun 已提交
197 198 199
	$(HIDE)cd $(ROOTFS_DIR)/.. && zip -r $(ROOTFS_ZIP) $(ROOTFS)

clean:
C
Caoruihong 已提交
200
	$(HIDE)if [ -d $(SYSROOT_PATH)/build ]; then $(MAKE) -C $(SYSROOT_PATH)/build clean; fi
201 202
	$(HIDE)for dir in $(LIB_SUBDIRS) apps; do $(MAKE) -C $$dir clean || exit 1; done
	$(HIDE)$(RM) $(LITEOS_MENUCONFIG_H)
C
Caoruihong 已提交
203
	$(HIDE)echo "clean $(LOSCFG_PLATFORM) finish"
W
wenjun 已提交
204

205
cleanall: clean
206
	$(HIDE)$(RM) $(LITEOSTOPDIR)/out $(LITEOS_CONFIG_FILE)
207
	$(HIDE)echo "clean all done"
W
wenjun 已提交
208

209 210
.PHONY: all clean cleanall sysroot help update_config
.PHONY: $(LITEOS_TARGET) $(ROOTFS) $(APPS) $(KCONFIG_CMDS) $(LITEOS_LIBS_TARGET) $(KCONFIG_CONFIG)