kode yard
all about C++ and PHP
Saturday, May 8, 2010
utility script-2
This is a shell script that automates the compilation of single c/c++ source file and executes this.
#!/bin/bash
#Developed by : lipun4u@gmail.com
file_name=$1
c_extension=".c"
cpp_extension=".cpp"
ip_file_name="$file_name$c_extension"
i=0
if [ $# -ne 1 ]
then
echo "Usage: `basename $0`
"
echo "Source file should be without extension"
echo "e.g :-`basename $0` test"
exit 1
fi
if [ -f $ip_file_name ]
then
echo "compiling c-source file $file_name ....."
gcc -o $file_name $ip_file_name -lpthread
if [ $? -eq 0 ]
then
i=1
fi
else
ip_file_name="$file_name$cpp_extension"
if [ -f $ip_file_name ]
then
echo "compiling c++-source file $file_name ....."
g++ -o $file_name $ip_file_name -lpthread
if [ $? -eq 0 ]
then
i=1
fi
else
echo "compilation failed"
exit 1
fi
fi
if [ $i -eq 1 ]
then
echo "Output file name : $file_name"
echo "Executing......"
echo
./$file_name
exit_status=$?
if [ $exit_status -ne 0 ]
then
echo "Program execution failed with exit status $exit_status"
exit 1
fi
echo
echo "Program executed successful"
fi
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment