From 9c5857e9319ce92e84f58b0d059ddeb6f691f3f8 Mon Sep 17 00:00:00 2001 From: Quinn Date: Mon, 2 Dec 2024 10:37:46 +0100 Subject: [PATCH] update template --- .gitignore | 6 +++-- .vscode/launch.json | 31 +++++++++++++++++++++++ .vscode/tasks.json | 62 +++++++++++++++++++++++++++++++++++++++++++++ build.sh | 22 ++++++++-------- 4 files changed, 108 insertions(+), 13 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 6a8bc10..2575ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ -.vscode -build \ No newline at end of file +.vscode/* +!.vscode/tasks.json +!.vscode/launch.json +build diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..0258d4f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,31 @@ +{ + "version": "2.0.0", + "configurations": [ + { + "name": "(gdb) C Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/linux-86_64/${workspaceFolderBasename}", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": false, + "miDebuggerPath": "/usr/bin/gdb", + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ], + "preLaunchTask": "build linux86_64" + } + ] +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..01d44c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,62 @@ +{ + "tasks": [ + { + "type": "shell", + "label": "build linux86_64", + "command": "./build.sh", + "args": [ + "linux86_64" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "builds the program for linux x86_64" + }, + { + "type": "shell", + "label": "build win86_64", + "command": "./build.sh", + "args": [ + "win86_64" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "detail": "builds the program for windows x86_64" + }, + { + "type": "shell", + "label": "build web", + "command": "./build.sh", + "args": [ + "web" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": false + }, + "detail": "builds the program for web using emscripten" + } + ], + "version": "2.0.0" +} diff --git a/build.sh b/build.sh index 9aeb9bb..756d52f 100755 --- a/build.sh +++ b/build.sh @@ -26,7 +26,7 @@ args_win86-64() args_emscripten() { ARCHITECTURE="web" - COMPILER="/home/user/.local/bin/emcc" + COMPILER="emcc" # just make sure it's in $PATH (it's a pain to install) ARGS="-s USE_SDL=2" FILE_EXSTENSION=".html" } @@ -35,37 +35,37 @@ args_emscripten() if [ "$1" = "linux86_64" ]; then args_linux86_64 elif [ "$1" = "win86_64" ]; then args_win86-64 elif [ "$1" = "web" ]; then args_emscripten -else echo -e "\033[91mdidn't include any arguments! D:\033[0m" && exit -1 +else echo -e "\033[91mdidn't include any arguments! D:\033[0m" && exit 1 fi # check whether $BUILD_DIR or $ARCHITECTURE isn't set if [[ -z $BUILD_DIR ]] || [[ -z "$ARCHITECTURE" ]]; then echo -e "\033[91mBUILD_DIR or ARCHITECTURE not set D:\033[0m" - exit -1 + exit 1 fi # make (and clear) the build directory -mkdir $BUILD_DIR $BUILD_DIR/$ARCHITECTURE -rm -rf $BUILD_DIR/$ARCHITECTURE/* +mkdir -p "$BUILD_DIR/$ARCHITECTURE" +rm -rf "${BUILD_DIR:?}/$ARCHITECTURE/*" # copy included files or directories to the build directory -if [[ ! -z $INCLUDE_IN_BUILD ]]; then - cp -r $INCLUDE_IN_BUILD $BUILD_DIR/$ARCHITECTURE +if [[ -n $INCLUDE_IN_BUILD ]]; then + cp -r "$INCLUDE_IN_BUILD" "$BUILD_DIR/$ARCHITECTURE" fi # get the executable path EXE_PATH=$BUILD_DIR/$ARCHITECTURE/$PROJECT_NAME$FILE_EXSTENSION echo "building at: $EXE_PATH" -# check whether the compiler path contains an executable at said path -if [ ! -x $COMPILER ]; then +# check whether the compiler can actually be executed +if [ ! -x "$COMPILER" ] && ! command -v "$COMPILER" > /dev/null; then echo -e "\033[91mCouldn't find an executable at path: \033[0m $COMPILER" - exit -1 + exit 1 fi # compile the code -COMMAND="$COMPILER `find ./src -name *.c` -o $EXE_PATH -Wall -g -lm $ARGS" +COMMAND="$COMPILER $(find ./src -name "*.c") -o $EXE_PATH -Wall -g -lm $ARGS" echo "using command: $COMMAND" $COMMAND exit $?