Skip to content

Commit d488ab9

Browse files
committed
scripts: create installable sdk file
Add scripts to create an installable SDK. inspired by the yocto based SDK. Signed-off-by: Anas Nashif <[email protected]>
1 parent ac1c122 commit d488ab9

File tree

2 files changed

+362
-0
lines changed

2 files changed

+362
-0
lines changed

scripts/make_zephyr_sdk.sh

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
#!/bin/sh
2+
#
3+
# The folder "toolchains" should contain the toolchains and host tools
4+
# This script merges all files into a single installable file.
5+
#
6+
# SDK should follow a vM.m versioning scheme
7+
#
8+
# Major versions for big interface/usage changes
9+
# Minor versions for additions of interfaces, transparent changes
10+
#
11+
# Default installation directory should be /opt/zephyr-sdk/
12+
#
13+
14+
15+
# Edit as needed:
16+
version_major=0
17+
version_minor=10
18+
subversion_minor=0
19+
prerelease=beta3
20+
21+
if [ "$1" != "" ] ; then
22+
product_name=$1
23+
else
24+
product_name=zephyr-sdk
25+
fi
26+
27+
# Create ./setup.sh
28+
29+
if [ "$subversion_minor" -ne "0" ]; then
30+
sdk_version=$version_major.$version_minor.$subversion_minor
31+
else
32+
sdk_version=$version_major.$version_minor
33+
fi
34+
35+
if [ -n "$prerelease" ]; then
36+
sdk_version=${sdk_version}-${prerelease}
37+
fi
38+
39+
setup=toolchains/setup.sh
40+
default_dir=/opt/${product_name}/
41+
toolchain_name=${product_name}-${sdk_version}-setup.run
42+
version_dir=info-zephyr-sdk-${sdk_version}
43+
44+
# Identify files present in toolchains folder
45+
46+
parse_toolchain_name()
47+
{
48+
local varname=$1
49+
local arch=$2
50+
local num
51+
local filename
52+
53+
num=$(ls toolchains | grep $arch | wc -l)
54+
if [ "$num" -gt "1" ]; then
55+
echo "Error: Multiple toolchains for \"$arch\" "
56+
exit 1
57+
fi
58+
59+
if [ "$num" -eq "0" ]; then
60+
echo "Warning: Missing toolchain for \"$arch\" "
61+
fi
62+
63+
filename=$(ls toolchains | grep $arch)
64+
eval "$varname=\$filename"
65+
}
66+
67+
parse_toolchain_name file_gcc_arm arm
68+
parse_toolchain_name file_gcc_arc arc
69+
parse_toolchain_name file_gcc_x86 i586
70+
parse_toolchain_name file_gcc_iamcu iamcu
71+
parse_toolchain_name file_gcc_mips mips32r2
72+
parse_toolchain_name file_gcc_nios2 nios2
73+
parse_toolchain_name file_gcc_xtensa xtensa
74+
parse_toolchain_name file_gcc_riscv32 riscv32
75+
parse_toolchain_name file_hosttools hosttools
76+
77+
# Host tools are non-optional
78+
if [ -z "$file_hosttools" ]; then
79+
echo "Error: Missing host tools!"
80+
exit 1
81+
fi
82+
83+
echo '#!/bin/bash' > $setup
84+
echo "DEFAULT_INSTALL_DIR=$default_dir" >> $setup
85+
echo "TOOLCHAIN_NAME=$toolchain_name" >> $setup
86+
echo "VERSION_DIR=$version_dir" >> $setup
87+
echo "SDK_VERSION=${sdk_version}" >> $setup
88+
89+
cat template_dir >>$setup
90+
91+
if [ -n "$file_gcc_x86" ]; then
92+
echo "tar -C \$target_sdk_dir ./$file_gcc_x86 > /dev/null &" >> $setup
93+
echo "spinner \$! \"Installing x86 tools...\"" >> $setup
94+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
95+
echo "echo \"\"" >>$setup
96+
fi
97+
98+
if [ -n "$file_gcc_arm" ]; then
99+
echo "tar -C \$target_sdk_dir ./$file_gcc_arm > /dev/null &" >> $setup
100+
echo "spinner \$! \"Installing arm tools...\"" >> $setup
101+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
102+
echo "echo \"\"" >>$setup
103+
fi
104+
105+
if [ -n "$file_gcc_arc" ]; then
106+
echo "tar -C \$target_sdk_dir ./$file_gcc_arc > /dev/null &" >> $setup
107+
echo "spinner \$! \"Installing arc tools...\"" >> $setup
108+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
109+
echo "echo \"\"" >>$setup
110+
fi
111+
112+
if [ -n "$file_gcc_iamcu" ]; then
113+
echo "tar -C \$target_sdk_dir ./$file_gcc_iamcu > /dev/null &" >> $setup
114+
echo "spinner \$! \"Installing iamcu tools...\"" >> $setup
115+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
116+
echo "echo \"\"" >>$setup
117+
fi
118+
119+
if [ -n "$file_gcc_mips" ]; then
120+
echo "tar -C \$target_sdk_dir ./$file_gcc_mips > /dev/null &" >> $setup
121+
echo "spinner \$! \"Installing mips tools...\"" >> $setup
122+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
123+
echo "echo \"\"" >>$setup
124+
fi
125+
126+
if [ -n "$file_gcc_nios2" ]; then
127+
echo "tar -C \$target_sdk_dir ./$file_gcc_nios2 > /dev/null &" >> $setup
128+
echo "spinner \$! \"Installing nios2 tools...\"" >> $setup
129+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
130+
echo "echo \"\"" >>$setup
131+
fi
132+
133+
if [ -n "$file_gcc_xtensa" ]; then
134+
echo "tar -C \$target_sdk_dir -xf ./$file_gcc_xtensa > /dev/null &" >> $setup
135+
echo "spinner \$! \"Installing xtensa tools...\"" >> $setup
136+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
137+
echo "echo \"\"" >>$setup
138+
fi
139+
140+
if [ -n "$file_gcc_riscv32" ]; then
141+
echo "tar -C \$target_sdk_dir -xf ./$file_gcc_riscv32 > /dev/null &" >> $setup
142+
echo "spinner \$! \"Installing riscv32 tools...\"" >> $setup
143+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
144+
echo "echo \"\"" >>$setup
145+
fi
146+
147+
if [ -n "$file_hosttools" ]; then
148+
echo "./$file_hosttools -y -d \$target_sdk_dir > /dev/null &" >> $setup
149+
echo "spinner \$! \"Installing additional host tools...\"" >> $setup
150+
echo "[ \$? -ne 0 ] && echo \"Error(s) encountered during installation.\" && exit 1" >>$setup
151+
echo "echo \"\"" >>$setup
152+
fi
153+
154+
155+
echo "" >>$setup
156+
echo "do_cleanup" >>$setup
157+
echo "" >>$setup
158+
159+
echo "echo \"Success installing SDK. SDK is ready to be used.\"" >>$setup
160+
chmod 777 $setup
161+
162+
makeself toolchains/ $toolchain_name "SDK for Zephyr" ./setup.sh

scripts/template_dir

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
2+
target_sdk_dir=""
3+
post_install_cleanup=1
4+
confirm=0
5+
6+
usage () {
7+
cat << EOF
8+
Usage : $TOOLCHAIN_NAME < -- options >
9+
10+
11+
Options:
12+
-h
13+
Display this help and exit.
14+
15+
-d <dir>
16+
Specify the absolute path of the SDK installation directory.
17+
18+
-y
19+
Automatic yes to prompts; assume "yes" as answer to all prompts.
20+
21+
EOF
22+
}
23+
24+
verify_os () {
25+
case "$(uname -s)" in
26+
27+
Darwin)
28+
echo 'OS X is not supported!'
29+
exit 1
30+
;;
31+
32+
# Linux, the only supported OS
33+
34+
Linux)
35+
#echo 'Linux'
36+
;;
37+
38+
# Other OS ...
39+
# see https://en.wikipedia.org/wiki/Uname#Examples
40+
# Don't allow to install on any of them, this includes cygwin, Windows,
41+
# Solaris etc.
42+
43+
*)
44+
echo 'Unsupported OS'
45+
exit 1
46+
;;
47+
esac
48+
}
49+
50+
while [ "$1" != "" ]; do
51+
case $1 in
52+
-h )
53+
usage
54+
exit 0
55+
;;
56+
-d )
57+
shift
58+
target_sdk_dir=$1
59+
;;
60+
-nocleanup )
61+
post_install_cleanup=0;
62+
;;
63+
-y )
64+
confirm="y";
65+
;;
66+
* )
67+
echo "Error: Invalid argument \"$1\""
68+
usage
69+
exit 1
70+
;;
71+
esac
72+
shift
73+
done
74+
75+
spinner()
76+
{
77+
local pid=$1
78+
local delay=0.175
79+
local spinstr='|/-\'
80+
local infotext=$2
81+
while kill -0 $pid 2>/dev/null ; do
82+
local temp=${spinstr#?}
83+
printf " [%c] %s" "$spinstr" "$infotext"
84+
local spinstr=$temp${spinstr%"$temp"}
85+
sleep $delay
86+
printf "\b\b\b\b\b\b"
87+
for i in $(seq 1 ${#infotext}); do
88+
printf "\b"
89+
done
90+
done
91+
printf " [*] %s" "$infotext"
92+
printf " \b\b\b\b"
93+
}
94+
95+
do_cleanup()
96+
{
97+
cd $target_sdk_dir
98+
if [ $post_install_cleanup = "1" ]; then
99+
#rm site-config*
100+
rm environment-setup*
101+
fi
102+
install -d -m 0755 $VERSION_DIR
103+
mv version-* $VERSION_DIR
104+
echo "$SDK_VERSION" > sdk_version
105+
chmod 0644 sdk_version
106+
}
107+
108+
# Read the input "y"
109+
read_confirm () {
110+
echo "The directory $target_sdk_dir/sysroots will be removed! "
111+
if [ "$confirm" != "y" ]; then
112+
echo "Do you want to continue (y/n)? "
113+
while read confirm; do
114+
[ "$confirm" = "Y" -o "$confirm" = "y" -o "$confirm" = "n" \
115+
-o "$confirm" = "N" ] && break
116+
echo "Invalid input \"$confirm\", please input 'y' or 'n': "
117+
done
118+
else
119+
echo
120+
fi
121+
}
122+
123+
verify_os
124+
125+
which python3 2>&1 > /dev/null
126+
if [ $? -ne 0 ]; then
127+
echo "ERROR: required python3 binary not in PATH" 1>&2
128+
exit 1
129+
fi
130+
131+
which xz 2>&1 > /dev/null
132+
if [ $? -ne 0 ]; then
133+
echo "ERROR: required xz binary not in PATH" 1>&2
134+
exit 1
135+
fi
136+
137+
if [ "$target_sdk_dir" = "" ]; then
138+
read -e -p "Enter target directory for SDK (default: $DEFAULT_INSTALL_DIR): " target_sdk_dir
139+
[ "$target_sdk_dir" = "" ] && target_sdk_dir=$DEFAULT_INSTALL_DIR
140+
fi
141+
142+
eval target_sdk_dir=$target_sdk_dir
143+
144+
if [[ $target_sdk_dir != /* ]]; then
145+
echo "The target directory path ($target_sdk_dir) must be an absolute path. Abort!"
146+
exit 1;
147+
fi
148+
149+
eval target_sdk_dir=$(echo "$target_sdk_dir"|sed 's/ /\\ /g')
150+
if [ -d "$target_sdk_dir" ]; then
151+
target_sdk_dir=$(cd "$target_sdk_dir"; pwd)
152+
else
153+
target_sdk_dir=$(readlink -m "$target_sdk_dir")
154+
fi
155+
156+
if [ -n "$(echo $target_sdk_dir|grep ' ')" ]; then
157+
echo "The target directory path ($target_sdk_dir) contains spaces. Abort!"
158+
exit 1
159+
fi
160+
161+
echo "Installing SDK to $target_sdk_dir"
162+
163+
if [ -d $target_sdk_dir ]; then
164+
# If the directory exists, test for write permission
165+
if [ ! -w $target_sdk_dir ] ; then
166+
echo "No permission, please run as 'sudo'"
167+
exit 1
168+
else
169+
# wipe the directory first
170+
if [ -d $target_sdk_dir/sysroots ]; then
171+
read_confirm
172+
if [ "$confirm" = "y" -o "$confirm" = "Y" ]; then
173+
rm -rf $target_sdk_dir/sysroots/
174+
rm -rf $target_sdk_dir/info-zephyr-sdk*/
175+
rm -fr $target_sdk_dir/sdk_version
176+
else
177+
# Abort the installation
178+
echo "SDK installation aborted!"
179+
exit 1
180+
fi
181+
fi
182+
fi
183+
else
184+
echo "Creating directory $target_sdk_dir"
185+
# Try to create the directory (this will not succeed if user doesn't have rights)
186+
if install -d -m 0751 $target_sdk_dir >/dev/null 2>&1 ; then
187+
echo "Success"
188+
else
189+
echo "No permission, please run as 'sudo'"
190+
exit 1
191+
fi
192+
fi
193+
194+
if (( EUID != 0 )); then
195+
umask 0002
196+
#else
197+
# umask 0022
198+
fi
199+
200+

0 commit comments

Comments
 (0)