Created
November 20, 2019 12:10
-
-
Save nicklasfrahm/8463b709dc3729492f2f9c379eded0e0 to your computer and use it in GitHub Desktop.
A convenient script for automatic compiling and execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./run.sh source_filename_without_extension