c_cpp:编译脚本regcc:编译当前目录的单文件源程序
一、说明
1、单文件的源程序:源程序是一个独立完整的文件。
2、regcc功能:
2.1、在当前目录,删除编译后的可执行文件;
2.2、在当前目录,编译所有单文件的源程序;
2.3、在当前目录,显示所有文件;
二、源码程序
1 [root@rocky tools]# cat regcc 2 #!/usr/bin/bash 3 4 5 6 # ls *.c | gawk -F. '{print $1}' | xargs 7 8 # ls *.c| gawk -F. '{ print $1, $0}' | xargs -n2 gcc -Wall -o 9 10 11 function lsall() 12 { 13 echo 14 echo " == List All Files: Start ==" 15 for la in $(ls) 16 do 17 echo ' List_Name: ' ${la} 18 done 19 echo " == List All Files: END ==" 20 echo 21 } 22 23 24 function lsexe() 25 { 26 echo 27 echo 28 echo " == List EXE file of C : start ==" 29 30 icount=0 31 32 for dl in $(ls *.c |gawk -F. '{print $1}') 33 do 34 echo ' LIST_EXE_NAME_'${icount}:' '${dl} 35 icount=$(($icount+1)) 36 done 37 echo " == List EXE file of C : over ==" 38 echo 39 echo 40 } 41 42 43 function delexe() 44 { 45 echo 46 echo 47 echo " == Delete EXE file of C : start ==" 48 49 icount=0 50 51 for dl in $(ls *.c |gawk -F. '{print $1}') 52 do 53 echo ' DELETE_EXE_NAME_'${icount}:' '${dl} 54 rm -rf ${dl} 55 icount=$(($icount+1)) 56 done 57 echo " == Delete EXE file of C : over ==" 58 echo 59 echo 60 } 61 62 63 function exegcc 64 { 65 echo 66 echo 67 echo " == Compile *.c Files ==" 68 69 ls *.c| gawk -F. '{ print $1, $0}' | xargs -n2 gcc -Wall -o 70 71 echo " == Compile *.c Files ==" 72 echo 73 echo 74 } 75 76 77 78 79 lsexe 80 81 delexe 82 83 lsall 84 85 exegcc 86 87 lsall 88 [root@rocky tools]# 89 [root@rocky tools]# 90 [root@rocky tools]#
三、应用实例
[root@rocky c]# [root@rocky c]# ./regcc == List EXE file of C : start == LIST_EXE_NAME_0: all_test LIST_EXE_NAME_1: getin LIST_EXE_NAME_2: macro_test LIST_EXE_NAME_3: return_struct == List EXE file of C : over == == Delete EXE file of C : start == DELETE_EXE_NAME_0: all_test DELETE_EXE_NAME_1: getin DELETE_EXE_NAME_2: macro_test DELETE_EXE_NAME_3: return_struct == Delete EXE file of C : over == == List All Files: Start == List_Name: all_test.c List_Name: comb List_Name: getin.c List_Name: macro_test.c List_Name: macro_test.i List_Name: regcc List_Name: regcc-backup List_Name: return_struct.c == List All Files: END == == Compile *.c Files == all_test.c: In function ‘linux_thread’: all_test.c:61:16: warning: unused variable ‘thid1’ [-Wunused-variable] 61 | thrd_t thid1; | ^~~~~ return_struct.c:34:5: warning: second argument of ‘main’ should be ‘char **’ [-Wmain] 34 | int main(int argc, char argv[]) | ^~~~ == Compile *.c Files == == List All Files: Start == List_Name: all_test List_Name: all_test.c List_Name: comb List_Name: getin List_Name: getin.c List_Name: macro_test List_Name: macro_test.c List_Name: macro_test.i List_Name: regcc List_Name: regcc-backup List_Name: return_struct List_Name: return_struct.c == List All Files: END == [root@rocky c]# [root@rocky c]#
标签:Files,EXE,Name,List,regcc,echo,编译,test,cpp From: https://www.cnblogs.com/lnlidawei/p/17003215.html