function cpprun(){
        echo "Checking if output directory exists..."
        if [ ! -d "./output" ]; then
                echo "Creating output directory..."
                mkdir "./output"
                echo "Output directory created."
        elif [ -f "./output/cpprun.o" ]; then
                echo "Backing up previous output..."
                mv ./output/cpprun.o ./output/cpprun.bak.o
                echo "Backup finished."
        fi
        echo "Running g++ compile..."
        g++ -o ./output/cpprun.o *.cpp
        if [ -f "./output/cpprun.o" ]; then
                echo "Compile finished."
                echo "Running output..."
                echo "-----------------"
                ./output/cpprun.o
                echo "-----------------"
                echo "Run finished."
        else
                echo "Compile failed."
        fi
}
Add this to your .bashrc script and then you should be able to compile your C++ code by typing cpprun in the base directory.
No comments:
Post a Comment