Created
June 21, 2016 05:18
-
-
Save hikilaka/92a9fb91e364b33abe5093fac5c465d7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
REDTEXT="\e[91m" | |
GREENTEXT="\e[92m" | |
PLAINTEXT="\e[39m" | |
err_str() { | |
echo -e "$(echo $REDTEXT)$1$(echo $PLAINTEXT)" | |
} | |
ok_str() { | |
echo -e "$(echo $GREENTEXT)$1$(echo $PLAINTEXT)" | |
} | |
compile_file() { | |
ASSEMBLER="arm-linux-gnueabihf-as" | |
LINKER="arm-linux-gnueabihf-ld" | |
BASENAME="${1%.*}" | |
echo "Assembling source file: $1" | |
eval "$ASSEMBLER -o $(echo $BASENAME).o $1" | |
if [ "$?" -ne 0 ]; then | |
echo $(err_str "Error in assembling routine") | |
exit 1 | |
fi | |
echo "Linking object file: $(echo $BASENAME).o" | |
eval "$LINKER -o $BASENAME $(echo $BASENAME).o" | |
if [ "$?" -ne 0 ]; then | |
echo $(err_str "Error in linking routine") | |
exit 1 | |
fi | |
echo "Successfully compiled binary $(ok_str $BASENAME)" | |
} | |
test_exec() { | |
eval "./$1" | |
RESULT=$? | |
if [ "$RESULT" -eq 0 ]; then | |
echo $(ok_str "Program terminated successfully") | |
else | |
echo $(err_str "Program terminated with status $RESULT") | |
fi | |
} | |
clean_files() { | |
rm -rf $1 | |
rm -rf $(echo $1).o | |
} | |
if [ "$#" -lt 1 ]; then | |
echo $(err_str "Error: No argument(s) supplied") | |
exit 1 | |
fi | |
compile_file $1 | |
test_exec $(echo ${1%.*}) | |
clean_files $(echo ${1%.*}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment