首页 / 操作系统 / Linux / 自动化编译C/C++程序脚本
该脚本文件主要根据程序的扩展名来确定该程序属于C程序还是C++程序,然后根据不同情况,使用gcc或者g++编译器编译该程序。#!/bin/bash
# =====================================
# Author : Anna
# exit_code :
# 2 -> Invalid Usage;
# 3 -> not a source code file
# =====================================
fileName=$1
option="$* -g -lpthread"
outFileName=`echo $fileName | cut -d. -f1`
AnalyseFile(){
if ! file $fileName | grep "ASCII" &> /dev/null;then
echo -e " 33[31m<$fileName> is not a ASCII file. 33[0m"
exit 3
fi
}
function ComplieFile {
if echo $fileName | egrep ".*.cc|cpp>" &> /dev/null;then
CC=g++
echo -e " 33[34m======================== C++_program Compling =====================