Skip to content

Instantly share code, notes, and snippets.

@nicklasfrahm
Created November 20, 2019 12:10
Show Gist options
  • Save nicklasfrahm/8463b709dc3729492f2f9c379eded0e0 to your computer and use it in GitHub Desktop.
Save nicklasfrahm/8463b709dc3729492f2f9c379eded0e0 to your computer and use it in GitHub Desktop.
A convenient script for automatic compiling and execution
#!/usr/bin/env bash
RED='\033[1;31m'
BLUE='\033[1;34m'
RESET='\033[0m'
# Select compiler.
# COMPILER=x86_64-w64-mingw32-g++
COMPILER=g++
if [ -z "$*" ]
then
echo -e "${RED}Supply at least one argument like so:${RESET} ./exe.sh counter"
exit 1
fi
# find source file
echo -e "${BLUE}Searching source file ...${RESET}"
SOURCEFILE=$(find -iname ${1}.cpp)
if [ -z "$SOURCEFILE" ]
then
echo -e "${RED}Source file not found:${RESET} ${1}.cpp"
exit 1
else
echo -e "${BLUE}Found source file:${RESET} ${SOURCEFILE}"
fi
# compile source file
echo -e "${BLUE}Compiling source file ...${RESET}"
$COMPILER "$SOURCEFILE" -o ${1}.exe --static
# execute .exe file
echo -e "${BLUE}Executing source file:${RESET}"
./${1}.exe
rm ./${1}.exe
@nicklasfrahm
Copy link
Author

Usage: ./run.sh source_filename_without_extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment