1 | # !kmk_ash
|
---|
2 | # $Id: gen-vscode-workspace.sh 95313 2022-06-20 17:18:18Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Script for generating a Visual Studio Code (vscode) workspace.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2022 Oracle Corporation
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | # available from http://www.virtualbox.org. This file is free software;
|
---|
12 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | # General Public License (GPL) as published by the Free Software
|
---|
14 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | #
|
---|
18 |
|
---|
19 | #
|
---|
20 | # Some constants.
|
---|
21 | #
|
---|
22 | MY_CAT="kmk_cat"
|
---|
23 | MY_CP="kmk_cp"
|
---|
24 | MY_MKDIR="kmk_mkdir"
|
---|
25 | MY_MV="kmk_mv"
|
---|
26 | MY_SED="kmk_sed"
|
---|
27 | MY_RM="kmk_rm"
|
---|
28 | MY_SLEEP="kmk_sleep"
|
---|
29 | MY_EXPR="kmk_expr"
|
---|
30 | MY_SVN="svn"
|
---|
31 |
|
---|
32 | #MY_SORT="kmk_cat"
|
---|
33 | MY_SORT="sort"
|
---|
34 |
|
---|
35 | #
|
---|
36 | # Globals.
|
---|
37 | #
|
---|
38 | MY_PROJECT_FILES=""
|
---|
39 | MY_OUT_DIRS="\
|
---|
40 | out/${KBUILD_TARGET}.${KBUILD_TARGET_ARCH}/${KBUILD_TYPE} \
|
---|
41 | out/${KBUILD_TARGET}.${KBUILD_TARGET_ARCH}/debug \
|
---|
42 | out/${KBUILD_TARGET}.${KBUILD_TARGET_ARCH}/release \
|
---|
43 | out/linux.amd64/debug \
|
---|
44 | out/linux.x86/debug \
|
---|
45 | out/win.amd64/debug \
|
---|
46 | out/win.x86/debug \
|
---|
47 | out/darwin.amd64/debug \
|
---|
48 | out/darwin.x86/debug \
|
---|
49 | out/haiku.amd64/debug \
|
---|
50 | out/haiku.x86/debug \
|
---|
51 | out/solaris.amd64/debug \
|
---|
52 | out/solaris.x86/debug";
|
---|
53 |
|
---|
54 |
|
---|
55 | #
|
---|
56 | # Parameters w/ defaults.
|
---|
57 | #
|
---|
58 | MY_ROOT_DIR=".."
|
---|
59 | MY_VSCODE_DIR=".vscode"
|
---|
60 | MY_VSCODE_FILE_DOT_EXT=".json"
|
---|
61 | MY_OUT_DIR=${MY_VSCODE_DIR}
|
---|
62 | MY_PRJ_PRF="VBox-"
|
---|
63 | MY_WS_NAME="virtualbox.code-workspace"
|
---|
64 | MY_DBG=""
|
---|
65 | MY_WINDOWS_HOST=""
|
---|
66 | MY_OPT_MINIMAL=""
|
---|
67 | MY_OPT_USE_WILDCARDS="yes"
|
---|
68 |
|
---|
69 |
|
---|
70 | ##
|
---|
71 | # Gets the absolute path to an existing directory.
|
---|
72 | #
|
---|
73 | # @param $1 The path.
|
---|
74 | my_abs_dir()
|
---|
75 | {
|
---|
76 | if test -n "${PWD}"; then
|
---|
77 | MY_ABS_DIR=`cd ${MY_ROOT_DIR}/${1} && echo ${PWD}`
|
---|
78 |
|
---|
79 | else
|
---|
80 | # old cygwin shell has no PWD and need adjusting.
|
---|
81 | MY_ABS_DIR=`cd ${MY_ROOT_DIR}/${1} && pwd | ${MY_SED} -e 's,^/cygdrive/\(.\)/,\1:/,'`
|
---|
82 | fi
|
---|
83 | if test -z "${MY_ABS_DIR}"; then
|
---|
84 | MY_ABS_DIR="${1}"
|
---|
85 | fi
|
---|
86 | }
|
---|
87 |
|
---|
88 | ##
|
---|
89 | # Gets the file name part of a path.
|
---|
90 | #
|
---|
91 | # @param $1 The path.
|
---|
92 | my_get_name()
|
---|
93 | {
|
---|
94 | SAVED_IFS=$IFS
|
---|
95 | IFS=":/ "
|
---|
96 | set $1
|
---|
97 | while test $# -gt 1 -a -n "${2}";
|
---|
98 | do
|
---|
99 | shift;
|
---|
100 | done
|
---|
101 |
|
---|
102 | IFS=$SAVED_IFS
|
---|
103 | #echo "$1"
|
---|
104 | export MY_GET_NAME=$1
|
---|
105 | }
|
---|
106 |
|
---|
107 | ##
|
---|
108 | # Gets the newest version of a library (like openssl).
|
---|
109 | #
|
---|
110 | # @param $1 The library base path relative to root.
|
---|
111 | my_get_newest_ver()
|
---|
112 | {
|
---|
113 | cd "${MY_ROOT_DIR}" > /dev/null
|
---|
114 | latest=
|
---|
115 | for ver in "$1"*;
|
---|
116 | do
|
---|
117 | if test -z "${latest}" || "${MY_EXPR}" "${ver}" ">" "${latest}" > /dev/null; then
|
---|
118 | latest="${ver}"
|
---|
119 | fi
|
---|
120 | done
|
---|
121 | if test -z "${latest}"; then
|
---|
122 | echo "error: could not find any version of: $1" >&2;
|
---|
123 | exit 1;
|
---|
124 | fi
|
---|
125 | echo "${latest}"
|
---|
126 | return 0;
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | ##
|
---|
131 | # Generate file entry for the specified file if it was found to be of interest.
|
---|
132 | #
|
---|
133 | # @param $1 The output file name base.
|
---|
134 | # @param $2 The file name.
|
---|
135 | # @param $3 Optional folder override.
|
---|
136 | my_file()
|
---|
137 | {
|
---|
138 | # sort and filter by file type.
|
---|
139 | case "$2" in
|
---|
140 | # drop these.
|
---|
141 | *.kup|*~|*.pyc|*.exe|*.sys|*.dll|*.o|*.obj|*.lib|*.a|*.ko)
|
---|
142 | return 0
|
---|
143 | ;;
|
---|
144 |
|
---|
145 | # by prefix or directory component.
|
---|
146 | tst*|*/testcase/*)
|
---|
147 | MY_FOLDER="$1-Testcases.lst"
|
---|
148 | ;;
|
---|
149 |
|
---|
150 | # by extension.
|
---|
151 | *.c|*.cpp|*.m|*.mm|*.pl|*.py|*.as|*.c.h|*.cpp.h|*.java)
|
---|
152 | MY_FOLDER="$1-Sources.lst"
|
---|
153 | ;;
|
---|
154 |
|
---|
155 | *.h|*.hpp|*.mm)
|
---|
156 | MY_FOLDER="$1-Headers.lst"
|
---|
157 | ;;
|
---|
158 |
|
---|
159 | *.asm|*.s|*.S|*.inc|*.mac)
|
---|
160 | MY_FOLDER="$1-Assembly.lst"
|
---|
161 | ;;
|
---|
162 |
|
---|
163 | *)
|
---|
164 | MY_FOLDER="$1-Others.lst"
|
---|
165 | ;;
|
---|
166 | esac
|
---|
167 | if test -n "$3";
|
---|
168 | then
|
---|
169 | MY_FOLDER="$1-$3.lst"
|
---|
170 | fi
|
---|
171 |
|
---|
172 | ## @todo only files which are in subversion.
|
---|
173 | # if ${MY_SVN} info "${2}" > /dev/null 2>&1; then
|
---|
174 | my_get_name "${2}"
|
---|
175 | echo ' <!-- sortkey: '"${MY_GET_NAME}"' --> <F N="'"${2}"'"/>' >> "${MY_FOLDER}"
|
---|
176 | # fi
|
---|
177 | }
|
---|
178 |
|
---|
179 | ##
|
---|
180 | # Generate file entry for the specified file if it was found to be of interest.
|
---|
181 | #
|
---|
182 | # @param $1 The output file name base.
|
---|
183 | # @param $2 The wildcard spec.
|
---|
184 | # @param $3 Optional folder override.
|
---|
185 | my_wildcard()
|
---|
186 | {
|
---|
187 | if test -n "$3"; then
|
---|
188 | MY_FOLDER="$1-$3.lst"
|
---|
189 | else
|
---|
190 | MY_FOLDER="$1-All.lst"
|
---|
191 | fi
|
---|
192 | EXCLUDES="*.log;*.kup;*~;*.bak;*.bak?;*.pyc;*.exe;*.sys;*.dll;*.o;*.obj;*.lib;*.a;*.ko;*.class;*.cvsignore;*.done;*.project;*.actionScriptProperties;*.scm-settings;*.svnpatch.rej;*.svn-base;.svn/*;*.gitignore;*.gitattributes;*.gitmodules;*.swagger-codegen-ignore;*.png;*.bmp;*.jpg"
|
---|
193 | echo ' <F N="'"${2}"'/*" Recurse="1" Excludes="'"${EXCLUDES}"'"/>' >> "${MY_FOLDER}"
|
---|
194 | }
|
---|
195 |
|
---|
196 | ##
|
---|
197 | # Generate file entries for the specified sub-directory tree.
|
---|
198 | #
|
---|
199 | # @param $1 The output filename.
|
---|
200 | # @param $2 The sub-directory.
|
---|
201 | # @param $3 Optional folder override.
|
---|
202 | my_sub_tree()
|
---|
203 | {
|
---|
204 | if test -n "$MY_DBG"; then echo "dbg: my_sub_tree: ${2}"; fi
|
---|
205 |
|
---|
206 | # Skip .svn directories.
|
---|
207 | case "$2" in
|
---|
208 | */.svn|*/.svn)
|
---|
209 | return 0
|
---|
210 | ;;
|
---|
211 | esac
|
---|
212 |
|
---|
213 | # Process the files in the directory.
|
---|
214 | for f in $2/*;
|
---|
215 | do
|
---|
216 | if test -d "${f}";
|
---|
217 | then
|
---|
218 | my_sub_tree "${1}" "${f}" "${3}"
|
---|
219 | else
|
---|
220 | my_file "${1}" "${f}" "${3}"
|
---|
221 | fi
|
---|
222 | done
|
---|
223 | return 0;
|
---|
224 | }
|
---|
225 |
|
---|
226 | ##
|
---|
227 | # Function generating an (intermediate) project task.
|
---|
228 | #
|
---|
229 | # @param $1 The project file name.
|
---|
230 | # @param $2 Build config name.
|
---|
231 | # @param $3 Task group to assign task to.
|
---|
232 | # @param $4 kBuild extra args.
|
---|
233 | # @param $5 kBuild working directory to set.
|
---|
234 | # If empty, the file's directory will be used.
|
---|
235 | # @param $6 kBuild per-task options.
|
---|
236 | # Leave empty if not being used.
|
---|
237 | my_generate_project_task()
|
---|
238 | {
|
---|
239 | MY_FILE="${1}";
|
---|
240 | MY_CFG_NAME="${2}";
|
---|
241 | MY_TASK_GROUP="${3}";
|
---|
242 | MY_KMK_EXTRAS="${4}";
|
---|
243 | MY_KMK_CWD="${5}";
|
---|
244 | MY_KMK_TASK_ARGS="${6}";
|
---|
245 | shift; shift; shift; shift; shift; shift;
|
---|
246 |
|
---|
247 | if [ -z "$MY_KMK_CWD" ]; then
|
---|
248 | MY_KMK_CWD='${fileDirname}'
|
---|
249 | fi
|
---|
250 |
|
---|
251 | MY_TASK_LABEL="${MY_TASK_GROUP}: ${MY_CFG_NAME}"
|
---|
252 |
|
---|
253 | echo ' {' >> "${MY_FILE}"
|
---|
254 | echo ' "type": "shell",' >> "${MY_FILE}"
|
---|
255 | echo ' "label": "'${MY_TASK_LABEL}'",' >> "${MY_FILE}"
|
---|
256 | echo ' "command": "'${MY_KMK_CMD}'",' >> "${MY_FILE}"
|
---|
257 | echo ' "args": [' >> "${MY_FILE}"
|
---|
258 | echo ' ' ${MY_KMK_ARGS} ',' >> "${MY_FILE}"
|
---|
259 | if [ -n "${MY_KMK_EXTRAS}" ]; then
|
---|
260 | echo ' '${MY_KMK_EXTRAS}' ,' >> "${MY_FILE}"
|
---|
261 | fi
|
---|
262 | echo ' "-C",' >> "${MY_FILE}"
|
---|
263 | echo ' "'${MY_KMK_CWD}'"' >> "${MY_FILE}"
|
---|
264 | if [ -n "${MY_KMK_TASK_ARGS}" ]; then
|
---|
265 | echo ' ', ${MY_KMK_TASK_ARGS} >> "${MY_FILE}"
|
---|
266 | fi
|
---|
267 | echo ' ],' >> "${MY_FILE}"
|
---|
268 | echo ' "options": {' >> "${MY_FILE}"
|
---|
269 | echo ' "cwd": "'${MY_KMK_CWD}'"' >> "${MY_FILE}"
|
---|
270 | echo ' },' >> "${MY_FILE}"
|
---|
271 | echo ' "problemMatcher": [' >> "${MY_FILE}"
|
---|
272 | echo ' "$gcc"' >> "${MY_FILE}"
|
---|
273 | echo ' ],' >> "${MY_FILE}"
|
---|
274 | echo ' "presentation": {' >> "${MY_FILE}"
|
---|
275 | echo ' "reveal": "always",' >> "${MY_FILE}"
|
---|
276 | echo ' "clear": true,' >> "${MY_FILE}"
|
---|
277 | echo ' "panel": "dedicated"' >> "${MY_FILE}"
|
---|
278 | echo ' },' >> "${MY_FILE}"
|
---|
279 | echo ' "detail": "compiler: /bin/clang++-9"' >> "${MY_FILE}"
|
---|
280 | echo ' },' >> "${MY_FILE}"
|
---|
281 | }
|
---|
282 |
|
---|
283 | ##
|
---|
284 | # Function generating a project build config.
|
---|
285 | #
|
---|
286 | # @param $1 The project file name.
|
---|
287 | # @param $2 Build config name.
|
---|
288 | # @param $3 Extra kBuild command line options, variant 1.
|
---|
289 | # @param $4 Extra kBuild command line options, variant 2.
|
---|
290 | # @param $4+ Include directories.
|
---|
291 | # @param $N --end-includes
|
---|
292 | my_generate_project_config()
|
---|
293 | {
|
---|
294 | MY_FILE="${1}";
|
---|
295 | MY_CFG_NAME="${2}";
|
---|
296 | MY_KMK_EXTRAS1="${3}";
|
---|
297 | MY_KMK_EXTRAS2="${4}";
|
---|
298 | MY_KMK_EXTRAS3="${5}";
|
---|
299 | MY_KMK_EXTRAS4="${6}";
|
---|
300 | shift; shift; shift; shift; shift; shift;
|
---|
301 |
|
---|
302 | ## @todo Process includes.
|
---|
303 | while test $# -ge 1 -a "${1}" != "--end-includes";
|
---|
304 | do
|
---|
305 | for f in $1;
|
---|
306 | do
|
---|
307 | my_abs_dir ${f}
|
---|
308 | #echo "Includes: ${MY_ABS_DIR}/"
|
---|
309 | done
|
---|
310 | shift
|
---|
311 | done
|
---|
312 | shift
|
---|
313 |
|
---|
314 | #
|
---|
315 | # Build tasks.
|
---|
316 | #
|
---|
317 | MY_TASK_CWD='${fileDirname}'
|
---|
318 | MY_TASK_ARGS='"-o", "${file}"'
|
---|
319 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Compile1" "${MY_KMK_EXTRAS1}" \
|
---|
320 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
321 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
322 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Compile2" "${MY_KMK_EXTRAS2}" \
|
---|
323 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
324 | fi
|
---|
325 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
326 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Compile3" "${MY_KMK_EXTRAS3}" \
|
---|
327 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
328 | fi
|
---|
329 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
330 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Compile4" "${MY_KMK_EXTRAS4}" \
|
---|
331 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
332 | fi
|
---|
333 | MY_TASK_CWD='${workspaceFolder}'
|
---|
334 | MY_TASK_ARGS=""
|
---|
335 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Build1" "${MY_KMK_EXTRAS1}" \
|
---|
336 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
337 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
338 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Build2" "${MY_KMK_EXTRAS2}" \
|
---|
339 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
340 | fi
|
---|
341 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
342 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Build3" "${MY_KMK_EXTRAS3}" \
|
---|
343 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
344 | fi
|
---|
345 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
346 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Build4" "${MY_KMK_EXTRAS4}" \
|
---|
347 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
348 | fi
|
---|
349 |
|
---|
350 | MY_TASK_CWD='${workspaceFolder}'
|
---|
351 | MY_TASK_ARGS='"rebuild"'
|
---|
352 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Rebuild1" "${MY_KMK_EXTRAS1}" \
|
---|
353 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
354 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
355 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Rebuild2" "${MY_KMK_EXTRAS2}" \
|
---|
356 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
357 | fi
|
---|
358 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
359 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Rebuild3" "${MY_KMK_EXTRAS3}" \
|
---|
360 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
361 | fi
|
---|
362 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
363 | my_generate_project_task "${MY_FILE}" "${MY_CFG_NAME}" "Rebuild4" "${MY_KMK_EXTRAS4}" \
|
---|
364 | "${MY_TASK_CWD}" "${MY_TASK_ARGS}"
|
---|
365 | fi
|
---|
366 |
|
---|
367 | #
|
---|
368 | # Generate compound tasks that invokes all needed sub tasks.
|
---|
369 | #
|
---|
370 | # Note: We include "VBox" in the label so that the command is easier to find
|
---|
371 | # in the command pallette.
|
---|
372 | #
|
---|
373 | echo ' {' >> "${MY_FILE}"
|
---|
374 | echo ' "label": "VBox Compile: '${MY_CFG_NAME}'",' >> "${MY_FILE}"
|
---|
375 | echo ' "dependsOrder": "sequence",' >> "${MY_FILE}"
|
---|
376 | echo ' "dependsOn": [ "Compile1: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
377 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
378 | echo ' , "Compile2: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
379 | fi
|
---|
380 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
381 | echo ' , "Compile3: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
382 | fi
|
---|
383 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
384 | echo ' , "Compile4: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
385 | fi
|
---|
386 | echo ' ]' >> "${MY_FILE}"
|
---|
387 | echo ' },' >> "${MY_FILE}"
|
---|
388 | echo ' {' >> "${MY_FILE}"
|
---|
389 | echo ' "label": "VBox Build: '${MY_CFG_NAME}'",' >> "${MY_FILE}"
|
---|
390 | echo ' "dependsOrder": "sequence",' >> "${MY_FILE}"
|
---|
391 | echo ' "dependsOn": [ "Build1: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
392 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
393 | echo ' , "Build2: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
394 | fi
|
---|
395 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
396 | echo ' , "Build3: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
397 | fi
|
---|
398 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
399 | echo ' , "Build4: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
400 | fi
|
---|
401 | echo ' ],' >> "${MY_FILE}"
|
---|
402 | echo ' "group": {' >> "${MY_FILE}"
|
---|
403 | echo ' "kind": "build",' >> "${MY_FILE}"
|
---|
404 | echo ' "isDefault": true' >> "${MY_FILE}"
|
---|
405 | echo ' }' >> "${MY_FILE}"
|
---|
406 | echo ' },' >> "${MY_FILE}"
|
---|
407 | echo ' {' >> "${MY_FILE}"
|
---|
408 | echo ' "label": "VBox Rebuild: '${MY_CFG_NAME}'",' >> "${MY_FILE}"
|
---|
409 | echo ' "dependsOrder": "sequence",' >> "${MY_FILE}"
|
---|
410 | echo ' "dependsOn": [ "Rebuild1: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
411 | if test -n "${MY_KMK_EXTRAS2}"; then
|
---|
412 | echo ' , "Rebuild2: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
413 | fi
|
---|
414 | if test -n "${MY_KMK_EXTRAS3}"; then
|
---|
415 | echo ' , "Rebuild3: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
416 | fi
|
---|
417 | if test -n "${MY_KMK_EXTRAS4}"; then
|
---|
418 | echo ' , "Rebuild4: '${MY_CFG_NAME}'"' >> "${MY_FILE}"
|
---|
419 | fi
|
---|
420 | echo ' ]' >> "${MY_FILE}"
|
---|
421 | echo ' },' >> "${MY_FILE}"
|
---|
422 | }
|
---|
423 |
|
---|
424 |
|
---|
425 | ##
|
---|
426 | # Function generating a project.
|
---|
427 | #
|
---|
428 | # @param $1 The project file name.
|
---|
429 | # @param $2 The project working directory.
|
---|
430 | # @param $3 Dummy separator.
|
---|
431 | # @param $4+ Include directories.
|
---|
432 | # @param $N --end-includes
|
---|
433 | # @param $N+1 Directory sub-trees and files to include in the project.
|
---|
434 | #
|
---|
435 | my_generate_project()
|
---|
436 | {
|
---|
437 | MY_PRJ_NAME=${1}
|
---|
438 | MY_WRK_DIR="${MY_FILE_ROOT_DIR}/${2}"
|
---|
439 | MY_FILE_PATH="${MY_WRK_DIR}/.vscode"
|
---|
440 | shift
|
---|
441 | shift
|
---|
442 | shift
|
---|
443 |
|
---|
444 | # Make sure that the .vscode project dir exists.
|
---|
445 | mkdir -p "$MY_FILE_PATH"
|
---|
446 |
|
---|
447 | MY_FILE="${MY_FILE_PATH}/c_cpp_properties${MY_VSCODE_FILE_DOT_EXT}";
|
---|
448 | echo "Generating ${MY_FILE}..."
|
---|
449 |
|
---|
450 | # Add it to the project list for workspace construction later on.
|
---|
451 | MY_PROJECT_FILES="${MY_PROJECT_FILES} ${MY_PRJ_NAME}:${MY_WRK_DIR}"
|
---|
452 |
|
---|
453 | #
|
---|
454 | # Generate the C/C++ bits.
|
---|
455 | ## @todo Might needs tweaking a bit more as stuff evolves.
|
---|
456 | #
|
---|
457 | echo '{' > "${MY_FILE}"
|
---|
458 | echo ' "configurations": [' >> "${MY_FILE}"
|
---|
459 | echo ' {' >> "${MY_FILE}"
|
---|
460 | echo ' "name": "Linux",' >> "${MY_FILE}"
|
---|
461 | echo ' "includePath": [' >> "${MY_FILE}"
|
---|
462 | echo ' "${workspaceFolder}/**"' >> "${MY_FILE}"
|
---|
463 | echo ' ],' >> "${MY_FILE}"
|
---|
464 | echo ' "defines": [],' >> "${MY_FILE}"
|
---|
465 | echo ' "cStandard": "c17",' >> "${MY_FILE}"
|
---|
466 | echo ' "cppStandard": "c++14",' >> "${MY_FILE}"
|
---|
467 | echo ' "intelliSenseMode": "linux-gcc-x64",' >> "${MY_FILE}"
|
---|
468 | echo ' "compilerPath": "/usr/bin/gcc"' >> "${MY_FILE}"
|
---|
469 | echo ' }' >> "${MY_FILE}"
|
---|
470 | echo ' ],' >> "${MY_FILE}"
|
---|
471 | echo ' "version": 4' >> "${MY_FILE}"
|
---|
472 | echo '}' >> "${MY_FILE}"
|
---|
473 |
|
---|
474 | MY_FILE="${MY_FILE_PATH}/tasks${MY_VSCODE_FILE_DOT_EXT}";
|
---|
475 | echo "Generating ${MY_FILE}..."
|
---|
476 |
|
---|
477 | #
|
---|
478 | # Tasks header.
|
---|
479 | #
|
---|
480 | echo '{' > "${MY_FILE}"
|
---|
481 | echo ' "version": "2.0.0",' >> "${MY_FILE}"
|
---|
482 | echo ' "tasks": [' >> "${MY_FILE}"
|
---|
483 |
|
---|
484 | my_generate_project_config "${MY_FILE}" "Default" "" "" "" "" $*
|
---|
485 | my_generate_project_config "${MY_FILE}" "Debug + hardening" \
|
---|
486 | '"KBUILD_TYPE=debug", "VBOX_WITH_HARDENING=1"' \
|
---|
487 | "" "" "" $*
|
---|
488 | my_generate_project_config "${MY_FILE}" "Release + hardening" \
|
---|
489 | '"KBUILD_TYPE=release", "VBOX_WITH_HARDENING=1"' \
|
---|
490 | "" "" "" $*
|
---|
491 | my_generate_project_config "${MY_FILE}" "Debug+Release + hardening" \
|
---|
492 | '"KBUILD_TYPE=debug", "VBOX_WITH_HARDENING=1"' \
|
---|
493 | '"KBUILD_TYPE=release", "VBOX_WITH_HARDENING=1"' \
|
---|
494 | "" "" $*
|
---|
495 | my_generate_project_config "${MY_FILE}" "Debug w/o hardening" \
|
---|
496 | '"KBUILD_TYPE=debug", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
497 | "" "" "" $*
|
---|
498 | my_generate_project_config "${MY_FILE}" "Release w/o hardening" \
|
---|
499 | '"KBUILD_TYPE=release", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
500 | "" "" "" $*
|
---|
501 | my_generate_project_config "${MY_FILE}" "Debug+Release w/o hardening" \
|
---|
502 | '"KBUILD_TYPE=debug", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
503 | '"KBUILD_TYPE=release", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
504 | "" "" $*
|
---|
505 | my_generate_project_config "${MY_FILE}" "Debug+Release with and without hardening" \
|
---|
506 | '"KBUILD_TYPE=debug", "VBOX_WITH_HARDENING=1"' \
|
---|
507 | '"KBUILD_TYPE=release", "VBOX_WITH_HARDENING=1"' \
|
---|
508 | '"KBUILD_TYPE=debug", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
509 | '"KBUILD_TYPE=release", "VBOX_WITHOUT_HARDENING=1"' \
|
---|
510 | $*
|
---|
511 |
|
---|
512 | #
|
---|
513 | # Tasks footer.
|
---|
514 | #
|
---|
515 | echo ' ]' >> "${MY_FILE}"
|
---|
516 | echo '}' >> "${MY_FILE}"
|
---|
517 |
|
---|
518 | while test $# -ge 1 -a "${1}" != "--end-includes";
|
---|
519 | do
|
---|
520 | shift;
|
---|
521 | done;
|
---|
522 | shift;
|
---|
523 |
|
---|
524 | return 0
|
---|
525 | }
|
---|
526 |
|
---|
527 |
|
---|
528 | ##
|
---|
529 | # Generate the workspace
|
---|
530 | #
|
---|
531 | my_generate_workspace()
|
---|
532 | {
|
---|
533 | MY_FILE="${MY_FILE_ROOT_DIR}/${MY_WS_NAME}"
|
---|
534 | echo "Generating ${MY_FILE}..."
|
---|
535 | echo '{' > "${MY_FILE}"
|
---|
536 | echo ' "folders": [' >> "${MY_FILE}"
|
---|
537 | for i in ${MY_PROJECT_FILES};
|
---|
538 | do
|
---|
539 | MY_PRJ_NAME=$(echo $i | cut -d ":" -f 1)
|
---|
540 | MY_PRJ_PATH=$(echo $i | cut -d ":" -f 2)
|
---|
541 | echo ' {' >> "${MY_FILE}"
|
---|
542 | echo ' "name": "'"${MY_PRJ_NAME}"'",' >> "${MY_FILE}"
|
---|
543 | echo ' "path": "'"${MY_PRJ_PATH}"'",' >> "${MY_FILE}"
|
---|
544 | echo ' },' >> "${MY_FILE}"
|
---|
545 | done
|
---|
546 | echo ' ],' >> "${MY_FILE}"
|
---|
547 | echo ' "settings": {},' >> "${MY_FILE}"
|
---|
548 | echo ' "extensions": {' >> "${MY_FILE}"
|
---|
549 | echo ' "recommendations": ["ms-vscode.cpptools"]' >> "${MY_FILE}"
|
---|
550 | echo ' },' >> "${MY_FILE}"
|
---|
551 | echo '}' >> "${MY_FILE}"
|
---|
552 | return 0
|
---|
553 | }
|
---|
554 |
|
---|
555 |
|
---|
556 | #
|
---|
557 | # Parse arguments.
|
---|
558 | #
|
---|
559 | while test $# -ge 1;
|
---|
560 | do
|
---|
561 | ARG=$1
|
---|
562 | shift
|
---|
563 | case "$ARG" in
|
---|
564 |
|
---|
565 | --rootdir)
|
---|
566 | if test $# -eq 0; then
|
---|
567 | echo "error: missing --rootdir argument." 1>&2
|
---|
568 | exit 1;
|
---|
569 | fi
|
---|
570 | MY_ROOT_DIR="$1"
|
---|
571 | shift
|
---|
572 | ;;
|
---|
573 |
|
---|
574 | --outdir)
|
---|
575 | if test $# -eq 0; then
|
---|
576 | echo "error: missing --outdir argument." 1>&2
|
---|
577 | exit 1;
|
---|
578 | fi
|
---|
579 | MY_OUT_DIR="$1"
|
---|
580 | shift
|
---|
581 | ;;
|
---|
582 |
|
---|
583 | --project-base)
|
---|
584 | if test $# -eq 0; then
|
---|
585 | echo "error: missing --project-base argument." 1>&2
|
---|
586 | exit 1;
|
---|
587 | fi
|
---|
588 | MY_PRJ_PRF="$1"
|
---|
589 | shift
|
---|
590 | ;;
|
---|
591 |
|
---|
592 | --workspace)
|
---|
593 | if test $# -eq 0; then
|
---|
594 | echo "error: missing --workspace argument." 1>&2
|
---|
595 | exit 1;
|
---|
596 | fi
|
---|
597 | MY_WS_NAME="$1"
|
---|
598 | shift
|
---|
599 | ;;
|
---|
600 |
|
---|
601 | --windows-host)
|
---|
602 | MY_WINDOWS_HOST=1
|
---|
603 | ;;
|
---|
604 |
|
---|
605 | --minimal)
|
---|
606 | MY_OPT_MINIMAL=1
|
---|
607 | ;;
|
---|
608 |
|
---|
609 | # usage
|
---|
610 | --h*|-h*|-?|--?)
|
---|
611 | echo "usage: $0 [--rootdir <rootdir>] [--outdir <outdir>] [--project-base <prefix>] [--workspace <name>] [--minimal]"
|
---|
612 | echo ""
|
---|
613 | echo "If --outdir is specified, you must specify a --rootdir relative to it as well."
|
---|
614 | exit 1;
|
---|
615 | ;;
|
---|
616 |
|
---|
617 | # default
|
---|
618 | *)
|
---|
619 | echo "error: Invalid parameter '$ARG'" 1>&2
|
---|
620 | exit 1;
|
---|
621 |
|
---|
622 | esac
|
---|
623 | done
|
---|
624 |
|
---|
625 |
|
---|
626 | #
|
---|
627 | # Save the absolute path to the root directory.
|
---|
628 | #
|
---|
629 | cd "${MY_OUT_DIR}"
|
---|
630 | my_abs_dir "."
|
---|
631 | MY_FILE_ROOT_DIR=${MY_ABS_DIR}
|
---|
632 |
|
---|
633 |
|
---|
634 | #
|
---|
635 | # From now on everything *MUST* succeed.
|
---|
636 | #
|
---|
637 | set -e
|
---|
638 |
|
---|
639 |
|
---|
640 | #
|
---|
641 | # Make sure the output directory exists, is valid and clean.
|
---|
642 | #
|
---|
643 | ${MY_RM} -f \
|
---|
644 | "${MY_OUT_DIR}"*.json \
|
---|
645 | "${MY_FILE_ROOT_DIR}/${MY_WS_NAME}"
|
---|
646 | ${MY_MKDIR} -p "${MY_OUT_DIR}"
|
---|
647 |
|
---|
648 |
|
---|
649 | #
|
---|
650 | # Determine the invocation to conjure up kmk.
|
---|
651 | #
|
---|
652 | my_abs_dir "tools"
|
---|
653 | if test -n "${MY_WINDOWS_HOST}"; then
|
---|
654 | MY_KMK_CMD="cscript.exe"
|
---|
655 | MY_KMK_ARGS='"/Nologo", "'${MY_ABS_DIR}/envSub.vbs'", "--quiet", "--", "kmk.exe"'
|
---|
656 | else
|
---|
657 | MY_KMK_CMD="/usr/bin/env"
|
---|
658 | MY_KMK_ARGS='"LANG=C", "'${MY_ABS_DIR}/env.sh'", "--quiet", "--no-wine", "kmk"'
|
---|
659 | fi
|
---|
660 |
|
---|
661 |
|
---|
662 | #
|
---|
663 | # Generate the projects and workspace.
|
---|
664 | #
|
---|
665 | my_abs_dir "tools/bin"
|
---|
666 | MY_INCLUDE_DIR=${MY_ABS_DIR}
|
---|
667 | . "$MY_INCLUDE_DIR/include-workspace-projects.sh"
|
---|
668 |
|
---|
669 | my_generate_workspace
|
---|
670 |
|
---|
671 | echo "done"
|
---|