shell自动编译简单入门
2020-07-19 04:59
1456 查看
动机
用于测试的一组程序比较多,每次编译命令麻烦,写个shell自动执行。
示例
简单示例
# clean echo "************" echo "clean project" rm ./bin/* echo "clean complete" echo "************" # compile link echo "************************" echo "gcc start" gcc fork_parent_first.c -o ./bin/fork_parent_first gcc fork_child_first.c -o ./bin/fork_child_first echo "gcc complete" echo "************************"
简单项目示例1
test.c
/*test.c*/ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> int main() { init_menu(); start_menu(); return 0; }
menu.c
/*menu.c*/ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #define MENU_COUNT 5 #define MENU_PROMPT 9 char* menu[MENU_PROMPT]; char* separator; char* prompt; int init_menu() { menu[0] = "************************************\n"; menu[1] = "* This is my shel demol. Please try it. *\n"; menu[2] = "* 1 : File *\n"; menu[3] = "* 2 : Edit *\n"; menu[4] = "* 3 : View *\n"; menu[5] = "* 4 : Tool *\n"; menu[6] = "* 0 : Quit *\n"; menu[7] = "************************************\n"; menu[8] = "* You can use \"0: Quit\" to exit.\n"; separator = "************************************\n"; prompt = "my shell >>> "; return 0; } int start_menu() { int user_choice = 0; int quit = 0; while(1) { user_choice = display_menu(); quit = dispatch_task(user_choice); if (quit) break; } return 0; } int display_menu() { int i; for ( i=0; i<MENU_PROMPT; i++ ) { printf(menu[i]); } printf(prompt); int choice = 0; scanf("%d", &choice); return choice; }
util.c
/*util.c*/ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> int dispatch_task(int choice) { int result_quit = 0; switch (choice) { case 1: func1(); break; case 2: func2(); break; case 3: func3(); break; case 4: func4(); break; case 0: quit(); result_quit = 1; break; } return result_quit; } int func1() { printf("********** Task is processing. **********\n"); printf("This is function1 File. \n"); printf("This is function1 File. \n"); printf("This is function1 File. \n"); printf("*********** Task is completed. **********\n"); } int func2() { printf("********** Task is processing. **********\n"); printf("This is function2 Edit. \n"); printf("This is function2 Edit. \n"); printf("This is function2 Edit. \n"); printf("*********** Task is completed. **********\n"); } int func3() { printf("********** Task is processing. **********\n"); printf("This is function3 View. \n"); printf("This is function3 View. \n"); printf("This is function3 View. \n"); printf("*********** Task is completed. **********\n"); } int func4() { printf("********** Task is processing. **********\n"); printf("This is function4 Tool. \n"); printf("This is function4 Tool. \n"); printf("This is function4 Tool. \n"); printf("*********** Task is completed. **********\n"); } int quit() { printf("************************************\n"); printf("The Program demo is over. \n"); printf("************************************\n"); }
mymake.sh
# clean echo "************" echo "clean project" rm ./bin/* echo "clean complete" echo "************" # compile link echo "************************" echo "gcc start" gcc test.c menu.c util.c -g -o ./bin/test echo "gcc complete" echo "************************"
简单项目示例2
# clean echo "************" echo "clean project" rm ./obj/* rm ./bin/* echo "clean complete" echo "************" # compile link echo "************************" echo "gcc start" gcc -c util.c -o ./obj/util.o gcc -c menu.c -o ./obj/menu.o gcc -c test.c -o ./obj/test.o gcc ./obj/test.o ./obj/menu.o ./obj/util.o -o ./bin/test echo "gcc complete" echo "************************"
示例中的命令及参数说明
echo命令
rm命令
gcc命令
-c参数
-o参数
-g参数
相关文章推荐
- make自动编译简单入门
- jenkins自动部署应用到tomcat中,编译后shell脚本的简单示例
- Shell脚本自动部署(编译)LAMP平台
- 用于快速编译简单的C语言程序的shell脚本
- Linux脚本(shell)编程(一) 简单入门HelloWorld
- Maven 自动打包编译的shell脚本
- shell基础和简单入门
- shell脚本编程入门基础(附:自动备份与解包文件脚本)
- android学习——NDK入门 windows下安装cygwin 与 Eclipse使用CDT 自动编译
- Ubuntu自动编译和安装Python的shell脚本
- MongoDB Shell简单入门(增删改查)
- shell script自动搭建简单的dhcp服务器
- Linux脚本(shell)编程(一) 简单入门HelloWorld
- linux下shell脚本自动生成编译信息
- linux下使用git和gradle编译项目,编写简单的自动发布脚本
- 一个简单的自动创建Shell脚本的脚本
- React+Flux 新手入门开发套件、模组、实例 ( gulp 自动检查,编译 )
- sublime text3 自动编译php 适合用于简单的php文件执行
- shell脚本和ansible实践MariaDB源码编译自动安装
- 最简单 的入门且最直观的Makefile和.so文件编译链接使用方法