-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsmart-env
More file actions
executable file
·125 lines (104 loc) · 2.98 KB
/
smart-env
File metadata and controls
executable file
·125 lines (104 loc) · 2.98 KB
1
2
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/sh
# Smart Build Environment Setup Script
#
# Copyright (C) 2024 RT-Thread
#
# SPDX-License-Identifier: GPL-2.0-or-later
if [ -n "$BASH_SOURCE" ]; then
THIS_SCRIPT=$BASH_SOURCE
elif [ -n "$ZSH_NAME" ]; then
THIS_SCRIPT=$0
else
THIS_SCRIPT="$(pwd)/smart-env"
if [ ! -e "$THIS_SCRIPT" ]; then
echo "Error: $THIS_SCRIPT doesn't exist!" >&2
echo "Please run this script in smart-env's directory." >&2
exit 1
fi
fi
if [ -n "$BBSERVER" ]; then
unset BBSERVER
fi
if [ -z "$ZSH_NAME" ] && [ "$0" = "$THIS_SCRIPT" ]; then
echo "Error: This script needs to be sourced. Please run as '. $THIS_SCRIPT'" >&2
exit 1
fi
# 设置 SMARTROOT 为项目根目录
if [ -z "$SMARTROOT" ]; then
SMARTROOT=$(dirname "$THIS_SCRIPT")
SMARTROOT=$(readlink -f "$SMARTROOT")
fi
unset THIS_SCRIPT
# 设置 OEROOT 为 oe-core 目录
OEROOT="$SMARTROOT/oe-core"
if [ ! -d "$OEROOT" ]; then
echo "Error: OpenEmbedded Core directory ($OEROOT) not found!" >&2
unset SMARTROOT OEROOT
return 1
fi
# 设置 BITBAKE 为 bitbake 目录
if [ ! -d "$SMARTROOT/bitbake" ]; then
echo "Error: BitBake directory not found!" >&2
unset SMARTROOT OEROOT
return 1
fi
# 设置构建目录
if [ -z "$1" ]; then
BUILDDIR="$SMARTROOT/build"
else
BUILDDIR="$SMARTROOT/$1"
fi
# 设置环境变量
export SMARTROOT OEROOT BUILDDIR
export PATH="$SMARTROOT/bitbake/bin:$PATH"
export PYTHONPATH="$SMARTROOT/bitbake/lib:$OEROOT/meta/lib:$PYTHONPATH"
# 创建构建目录
if [ ! -d "$BUILDDIR/conf" ]; then
mkdir -p "$BUILDDIR/conf"
# 创建 local.conf
cat > "$BUILDDIR/conf/local.conf" << EOF
# 机器配置,支持 qemuarm64 和 qemuriscv64
MACHINE ??= "qemuarm64"
# 编译器配置
SDKMACHINE ?= "x86_64"
# 构建配置
BB_NUMBER_THREADS ?= "\${@oe.utils.cpu_count()}"
PARALLEL_MAKE ?= "-j \${@oe.utils.cpu_count()}"
# 下载和缓存目录
DL_DIR ?= "\${TOPDIR}/downloads"
SSTATE_DIR ?= "\${TOPDIR}/sstate-cache"
# 临时目录
TMPDIR = "\${TOPDIR}/tmp"
EOF
# 创建 bblayers.conf,使用绝对路径
cat > "$BUILDDIR/conf/bblayers.conf" << EOF
# POKY_BBLAYERS_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
POKY_BBLAYERS_CONF_VERSION = "2"
BBPATH = "\${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " \\
$SMARTROOT/oe-core/meta \\
$SMARTROOT/meta-smart \\
"
EOF
fi
cd "$BUILDDIR" || return 1
# 不再清理 SMARTROOT,因为它在 bitbake 过程中可能会被用到
unset OEROOT
echo
echo "=== Smart Build Environment Initialized ==="
echo "Build directory: $BUILDDIR"
echo "Current machine: $(grep '^MACHINE' conf/local.conf | cut -d'"' -f2)"
echo
echo "Common build commands:"
echo " Build everything (recommended for first time):"
echo " $ bitbake smart -c build_all"
echo
echo " Others:"
echo " $ bitbake smart -c build_kernel"
echo " $ bitbake smart-gcc -c install_toolchain"
echo " $ bitbake busybox -c build_rootfs"
echo
echo "Ready to build. Happy hacking!"
echo "==================================="