最简单的makefile和最简单的shell程序

不知如何编写shell程序,makefile也是很糟糕,于是查找资料,自己编写一个最入门的例子。

程序文件为helloword.c

makefile也很简单

test为shell程序

这三个文件放在/home/scs/helloword目录下

代码如下所示:

makefile

[plain] view plaincopy
  1. a.out:helloword.c  
  2.     cc helloword.c  
  3. clean:  
  4.     rm a.out  

 

 

helloword.c

 

  1. #include <stdio.h>  
  2. void main(void){  
  3. printf("\nhello world !\n");  
  4. }  

 

test 

 

[plain] view plaincopy
  1. #! /bin/sh   
  2. cd /home/scs/helloword  
  3. /usr/bin/make  
  4. echo "lalalalalala"  
  5. 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了吧??

posted @ 2012-04-12 13:46  yazhouren  阅读(243)  评论(0编辑  收藏  举报