不知如何编写shell程序,makefile也是很糟糕,于是查找资料,自己编写一个最入门的例子。
程序文件为helloword.c
makefile也很简单
test为shell程序
这三个文件放在/home/scs/helloword目录下
代码如下所示:
makefile
- a.out:helloword.c
- cc helloword.c
- clean:
- rm a.out
helloword.c
- #include <stdio.h>
- void main(void){
- printf("\nhello world !\n");
- }
test
- #! /bin/sh
- cd /home/scs/helloword
- /usr/bin/make
- echo "lalalalalala"
- exit
下面讲解具体步骤:
1. 建立helloword.c ,这个不用说了,地球人都知道
2. 建立makefile文件,内容如上所示,
(注释:执行make时,生成a.out,
执行make clean时,删除a.out)
3. 建立test文件,敲入对应代码
( 注释:
#!/bin/sh 指明用默认shell
exit为退出shell
中间的命令和linux shell下敲入的命令完全一样)
4.使test编程可执行文件
命令:chmod 555 test
5 执行test
命令: ./test
哈哈发现shell程序调用make了吧??