playground/build.bash

28 lines
550 B
Bash
Raw Normal View History

2024-08-27 15:37:16 -04:00
#!/bin/bash
# Check if the argument is provided
if [ -z "$1" ]; then
echo "No C++ file provided."
exit 1
fi
# Extract the filename without extension
filename=$(basename -- "$1")
filename="${filename%.*}"
mkdir -p "build/$filename"
# Compile the C++ file
2024-09-08 02:12:30 -04:00
g++ -o "build/$filename/$filename" "$1"
2024-08-27 15:37:16 -04:00
# Check if the compilation was successful
if [ $? -eq 0 ]; then
echo "Compilation successful. Executable is located at build/$filename/$filename"
else
echo "Compilation failed."
exit 1
fi
echo "Running: $filename"
build/$filename/$filename