{
	// See https://go.microsoft.com/fwlink/?LinkId=733558
	// for the documentation about the tasks.json format
	"version": "2.0.0",
	"tasks": [

		{
			"label": "build-extras",
			"type": "shell",
			"command": "./build.sh",
			"args": ["debug_build"],
			"problemMatcher": {
				"owner": "cpp",
				"fileLocation": ["relative", "/"],
				"pattern": [
					{
					  "regexp": ".",
					  "file": 1,
					  "location": 2,
					  "message": 3
					}
				]
			},
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"presentation": {
				"echo": true,
				"reveal": "always",
				"focus": true,
				"panel": "dedicated",
				"showReuseMessage": true,
				"clear": true,
			}
		},

		{
			"label": "qemu",
			// "dependsOn": "build-extras",
			"type":"shell",
			"isBackground":true,
			"runOptions": {
				"instanceLimit": 1
			},
			"command": [
				"qemu-system-arm",
				"-kernel ./debug/project.elf",
				"-machine mps2-an385",
				"-d cpu_reset",
				"-nographic",
				"-monitor null",
				"-semihosting",
				"--semihosting-config enable=on,target=native",
				"-serial stdio",
				"-s",
				"-S",
			],
			"presentation": {
				"echo": true,
				"reveal": "always",
				"focus": true,
				"panel": "dedicated",
				"showReuseMessage": true,
				"clear": true,
			},
			"problemMatcher":
			{
				"owner": "external",
				"pattern": [
					{
						"regexp": ".",
						"file": 1,
						"location": 2,
						"message": 3
					}
				],
				"background": {
					"activeOnStart": true,
					"beginsPattern": ".",
					"endsPattern": "."
				}
			}
		},

		{
			"label": "killallqemu",
			"type":"shell",
			"isBackground": true,
			"command": "killall",
			"args": ["qemu-system-arm"],
			"presentation": {
				"echo": false,
				"reveal": "never",
				"focus": false,
				"showReuseMessage": false,
				"clear": true,
			},
		},

		{
			"label": "JLinkGDBServer",
			"type": "shell",
			"isBackground": true,
			"command": "./build.sh",
			"args": [
				// "flash",
				"debug_cmd",
			],

			// This task is run before some debug tasks.
			// Problem is, it's a watch script, and since it never exits, VSCode
			// complains. All this is needed so VSCode just lets it run.
			"problemMatcher": {
				"owner": "external",
				"pattern": [
					{
						"regexp": ".",
						"file": 1,
						"location": 2,
						"message": 3
					}
				],
				"background": {
					"activeOnStart": true,
					"beginsPattern": ".",
					"endsPattern": "."
				}
			},
			"presentation": {
				"echo": true,
				"reveal": "always",
				"focus": true,
				"panel": "dedicated",
				"showReuseMessage": true,
				"clear": true,
			},
		},

		{
			"label": "killallJLinkGDBServer",
			"type":"shell",
			"isBackground": true,
			"command": "killall",
			"args": ["JLinkGDBServer"],
			"presentation": {
				"echo": false,
				"reveal": "never",
				"focus": false,
				"showReuseMessage": false,
				"clear": true,
			},
		},

	]
}
