-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.sh
executable file
·194 lines (179 loc) · 4.38 KB
/
setup.sh
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/bash
# Function to sanitize the directory name by removing the trailing slash if it exists
sanitize_directory() {
local dir_name="$1"
# Remove trailing slash using string manipulation
sanitized_dir="${dir_name%/}"
echo "$sanitized_dir"
}
# Function to set the default board ID or use the provided one
set_board_id() {
if [ -z "$2" ]; then
board_id="frdm_mcxn947/mcxn947/cpu0"
else
board_id="$2"
fi
}
# Function to prompt the user and check the response
prompt_user() {
local prompt_message="$1"
local response
read -p "$prompt_message (y/n): " response
if [[ "$response" != "y" && "$response" != "Y" ]]; then
echo "Operation cancelled."
exit 1
fi
}
# Create the .vscode directory if it doesn't exist
create_vscode_directory() {
local subfolder="$1"
if [ -d "$subfolder/.vscode" ]; then
prompt_user "The directory '$subfolder/.vscode' already exists. Do you want to remake it?"
rm -rf "$subfolder/.vscode"
fi
mkdir "$subfolder/.vscode"
echo "Created .vscode directory in $subfolder."
}
# Create cmake-kits.json
create_cmake_kits() {
local subfolder="$1"
cat <<EOF > "$subfolder/.vscode/cmake-kits.json"
[
{
"name": "Zephyr build tool",
"environmentVariables": {
"ZEPHYR_BASE": "",
"ZEPHYR_SDK_INSTALL_DIR": ""
},
"cmakeSettings": {
"BOARD": "$board_id"
},
"keep": true
}
]
EOF
echo "cmake-kits.json created."
}
# Create cmake-variants.json
create_cmake_variants() {
local subfolder="$1"
cat <<EOF > "$subfolder/.vscode/cmake-variants.json"
{
"build_type": {
"default": "debug",
"choices": {
"debug": {
"short": "debug",
"buildType": "debug"
},
"release": {
"short": "release",
"buildType": "release"
}
}
}
}
EOF
echo "cmake-variants.json created."
}
# Create launch.json
create_launch_json() {
local subfolder="$1"
cat <<EOF > "$subfolder/.vscode/launch.json"
{
"configurations": [
{
"type": "cppdbg",
"name": "Debug project configuration",
"request": "launch",
"cwd": "\${workspaceRoot}",
"MIMode": "gdb",
"setupCommands": [
{"text": "set remotetimeout 600"},
{"text": "set debug-file-directory"}
],
"program": "",
"miDebuggerServerAddress": "",
"variables": {
"mcuxStopAtSymbol": "main",
"mcuxSerialNumber": "",
"mcuxAttach": "false",
"mcuxRemoteProbeType": ""
},
"logging": {
"engineLogging": false
}
}
]
}
EOF
echo "launch.json created."
}
# Create mcuxpresso-tools.json
create_mcuxpresso_tools() {
local subfolder="$1"
cat <<EOF > "$subfolder/.vscode/mcuxpresso-tools.json"
{
"version": "1.1",
"toolchainPath": "",
"toolchainVersion": "",
"linkedProjects": [],
"trustZoneType": "none",
"multicoreType": "none",
"debug": {
"linkserver": {},
"pemicro": {},
"segger": {}
},
"projectType": "zephyr-workspace",
"sdk": {
"boardId": "$board_id",
"version": "",
"path": ""
}
}
EOF
echo "mcuxpresso-tools.json created."
}
# Create settings.json
create_settings_json() {
local subfolder="$1"
cat <<EOF > "$subfolder/.vscode/settings.json"
{
"cmake.configureOnOpen": false,
"C_Cpp.errorSquiggles": "disabled",
"cmake.preferredGenerators": [
"Ninja",
"Unix Makefiles",
"MinGW Makefiles"
],
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"cmake.sourceDirectory": "\${workspaceFolder}"
}
EOF
echo "settings.json created."
}
# Main function to orchestrate the creation of all files
create_vscode_configs() {
local subfolder="$(sanitize_directory "$1")"
# Check if subfolder name was provided
if [ -z "$subfolder" ]; then
echo "Error: Please provide a subfolder name as an argument."
exit 1
fi
# Set the board ID
set_board_id "$@"
# Check if the input directory exists
if [ ! -d "$subfolder" ]; then
echo "Error: The directory '$subfolder' does not exist."
exit 1
fi
create_vscode_directory "$subfolder"
create_cmake_kits "$subfolder"
create_cmake_variants "$subfolder"
create_launch_json "$subfolder"
create_mcuxpresso_tools "$subfolder"
create_settings_json "$subfolder"
}
# Call the main function with the script arguments
create_vscode_configs "$@"