2016年10月22日 星期六
T.s.road总结笔记
项目源码:https://github.com/Tsroad/Linux-Shell-C/
作者说明:
When running this programme, the author’sPC setting is:
Ubuntu14.04 LTS+CPU 3.6GHz + RAM 8.0GB.
(form Lab 2204; Check by Keung Charteris& T.s.road CZQ)
题目
使用脚本mv_src实现将不需要的代码(以.c,.h结尾)去除。以linux 代码为例,可正常编译后,执行脚本,移动所有不是编译所需的文件和目录到指定的文件目录下。
例如:
./mv_src ./linux-src/ ./test_src/
执行脚本后,删除linux-src任一源文件,均导至编译出错。
需要提供脚本和测试过程的输出log.
对问题进行简化如下:
1. 文件夹内只包含未编译工程文件(*.c *.h Makefile etc.);
2. 子目录只做了一层,当然只要有Makefile子目录都不是问题;
3. 工程文件较少,仅为实验所用。
思路整理如下:
1. 确认哪些文件是编译所需,解决方案如下:
Gcc –M object.c >> temp.txt#会列出文件的依赖关系只有*.h文件
Gcc –H -c object.c >> temp.txt #会列出文件的依赖关系调用关系–c参数不链接,有些c文件不含main函数可用-c解决错误信息
2. 找出依赖关系后,接下来就是串的处理了,一系列的文本操作
详情见mv_src.
运行命令如下 $ tar xzvf linux-src.tar.gz $ cd linux-src/ $ patch -p1 < ../patchfile $ cd ../ $ ./mv_src ./linux-src/ ./test_src/ Done !
处理结果
系统log:
subdir make -C subdir make[1]: Entering directory `/home/tsroad/tsroad/linux-src/subdir' echo /home/tsroad/tsroad/linux-src/subdir"/"iolib.c >> ../../temp.txt cc -c iolib.c -o iolib.o cc -H -c iolib.c 2>> ../../temp.txt make[1]: Leaving directory `/home/tsroad/tsroad/linux-src/subdir' echo /home/tsroad/tsroad/linux-src"/"iolib.c >> ../temp.txt cc -H -c iolib.c 2>> ../temp.txt cc -c iolib.c -o iolib.o echo /home/tsroad/tsroad/linux-src"/"main.c >> ../temp.txt cc -H -c main.c 2>> ../temp.txt cc -c main.c -o main.o echo /home/tsroad/tsroad/linux-src"/"web_server.c >> ../temp.txt cc -H -c web_server.c 2>> ../temp.txt cc -c web_server.c -o web_server.o make -C subdir clean make[1]: Entering directory `/home/tsroad/tsroad/linux-src/subdir' make[1]: Leaving directory `/home/tsroad/tsroad/linux-src/subdir'
参考文献:
Linux and Unix make command——http://www.computerhope.com/unix/umake.htm
How do I make a simple makefile for gcc on Linux?——http://stackoverflow.com/questions/1484817/how-do-i-make-a-simple-makefile-for-gcc-on-linux
Replace a string in shell script ——http://stackoverflow.com/questions/3306007/replace-a-string-in-shell-script-using-a-variable
cat option——https://en.wikipedia.org/wiki/Cat_(Unix)
Gcc compile argument ——https://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_3.html
linux shell String Operation——http://www.cnblogs.com/chengmo/archive/2010/10/02/1841355.html
Linux shell scripts——http://linuxcommand.org/wss0090.php
Gcc详解——http://blog.chinaunix.net/uid-21411227-id-1826747.html
Using 'sed' to find and replace ——http://unix.stackexchange.com/questions/159367/using-sed-to-find-and-replace