#!/bin/bash # version 3.0 # BASE : 0 -> executed directory (default) # BASE : 1 -> home directory BASE=0 YES=0 USER_INCLUDES="" while getopts "uyI:" flag; do case "$flag" in u) BASE=1 ;; y) YES=1 ;; I) USER_INCLUDES="$USER_INCLUDES -I$OPTARG" ;; \?) usage; exit -1 ;; esac done shift $((OPTIND - 1)) if [ $# -eq 1 ]; then echo ${!1} fi if [ $BASE -eq 0 ]; then path="${PWD}/.PS" else path="$HOME/.PS" fi path_warning="$path/warning" path_obj="$path/obj" path_objmd5="$path/objmd5" path_output="$path/output.txt" mkdir -p $path_warning mkdir -p $path_obj mkdir -p $path_objmd5 if [ -f "$1.cpp" ] && [ ! -z "$1.cpp" ]; then md5=`md5sum $1.cpp | cut -f1 -d' '` name=`basename $1` echo "$1.cpp : File Exist!" echo "md5: $md5" if [ -e "$path_objmd5/$md5" ]; then if [ $YES -eq 0 ]; then read -p "There's excutable file with same md5. Will you excute this?(Y/n) " yesno fi if [ -z "$yesno" ] || [[ $yesno =~ [yY] ]] || [[ $yesno =~ [yY][eE][sS] ]]; then echo -e "---------------- \"$1.cpp(?)\" Standard Input ----------------" "$path_objmd5/$md5" > $path_output; ret=$? echo -e "\n-------------------- \"$1.cpp(?)\" output --------------------" cat $path_output echo -e "\n----------------------- \"$1.cpp(?)\" ------------------------" exit 0 fi fi # copt="g++ $1.cpp -Ilib -Iac-library -fsanitize=undefined,address -o $path_obj/$1 -O2 -lm -Wall -std=c++2a -DDEBUG -Wno-unused-result" copt="g++ $1.cpp $USER_INCLUDES -fsanitize=undefined,address -o $path_obj/$1 -O2 -lm -Wall -std=c++2a -DDEBUG -Wno-unused-result" echo "Now Compiling..." echo "## Name of Source File : $1.cpp" > "$path_warning/$1" echo "## MD5 of Source File : $md5" >> "$path_warning/$1" echo "## Compile command : $copt" >> "$path_warning/$1" ctime=`date +%y%m%d%H%M%S`; echo "## Compile start time : $ctime" >> "$path_warning/$1" `$copt 2> $path/latest`; res=$? echo -e "## Compile end time : $(date +%y%m%d%H%M%S)\n" >> "$path_warning/$1" cat "$path/latest" >> "$path_warning/$1" echo "Compile Finished!" cat "$path_warning/$1" if [ $res -eq 0 ]; then cp "$path_obj/$1" "$path_objmd5/$md5" echo -e "---------------- \"$1.cpp\" Standard Input ----------------" "$path_obj/$1" > $path_output; ret=$? echo -e "\n-------------------- \"$1.cpp\" output --------------------" cat $path_output echo -e "\n----------------------- \"$1.cpp\" ------------------------" echo -e "\nProgram returned with $ret" echo -e "Excutable File : $path_obj/$1\n" else echo "Compile Failed!" fi elif [ -z "$1" ]; then echo "No string is given!" else echo "There's no such file!" fi exit 0