Malkfile改模版
主程序
[root@localhost 0118]# cp -r/mnt/hgfs/shared/client/ ./
[root@localhost 0118]# ls
add.c client divi.c main.c mul.c sub.c
[root@localhost 0118]# cd client
[root@localhost client]# ls
bin check_putin client include main Makefile pack_message scripts
[root@localhost client]# cd ..
[root@localhost 0118]# ls
add.c client divi.c main.c mul.c sub.c
[root@localhost 0118]# cd ..
[root@localhost n2017]# ls
0118 0119 0120 0121
[root@localhost n2017]# cp *.c ../0120
cp: 无法 stat “*.c”: 没有那个文件或目录
[root@localhost n2017]# cd 0118
[root@localhost 0118]# cp *.c ../0120
[root@localhost 0118]# cp -r ./client/../0120
[root@localhost 0118]# cd ../0120
[root@localhost 0120]# ls
add.c client divi.c hu.c main.c mul.c nine.c sub.c
[root@localhost 0120]# cp hu.c nine.c../0121
[root@localhost 0120]# rm hu.c
rm:是否删除 一般文件 “hu.c”? y
[root@localhost 0120]# rm nine.c
rm:是否删除 一般文件 “nine.c”? y
[root@localhost 0120]# ls
add.c client divi.c main.c mul.c sub.c
[root@localhost 0120]# cd client
[root@localhost client]# ls
bin check_putin client include main Makefile pack_message scripts
[root@localhost client]# rm -r client
rm:是否删除 一般文件 “client”? y
[root@localhost client]# rm -frcheck_putin/
[root@localhost client]# rm -frpack_message/
[root@localhost client]# ls
bin include main Makefile scripts
[root@localhost client]# mkdir -p ./add/src
[root@localhost client]# mkdir -p ./sub/src
[root@localhost client]# mkdir -p ./mul/src
[root@localhost client]# mkdir -p./divi/src
[root@localhost client]# ls
add bin divi include main Makefile mul scripts sub
[root@localhost client]# cd add
[root@localhost add]# ls
src
[root@localhost add]# cd ..
[root@localhost client]# cp ./main/Makefile./add
[root@localhost client]# cp ./main/Makefile./sub
[root@localhost client]# cp ./main/Makefile./mul
[root@localhost client]# cp ./main/Makefile./divi
[root@localhost client]# cd divi
[root@localhost divi]# ls
Makefile src
[root@localhost divi]# cd ..
[root@localhost client]# cp ../add.c./add/src
[root@localhost client]# cp ../sub.c./sub/src
[root@localhost client]# cp ../mul.c./mul/src
[root@localhost client]# cp ../divi.c./divi/src
[root@localhost client]# cd ./divi/src
[root@localhost src]# ls
divi.c
[root@localhost src]# cd ..
[root@localhost divi]# cd ..
[root@localhost client]# cd ..
[root@localhost 0120]# vim main
[root@localhost 0120]# vim main.c
[root@localhost 0120]# cp ../main.c./main/src
cp: 无法 stat “../main.c”: 没有那个文件或目录
[root@localhost 0120]# cd client
[root@localhost client]# cp ../main.c./main/src
cp:是否覆盖“./main/src/main.c”? y
[root@localhost client]# cd main
[root@localhost main]# cd src
[root@localhost src]# vim main.c
[root@localhost src]# cd ../../
[root@localhost client]# cd include
[root@localhost include]# vim myhead.c
[root@localhost include]# vim myhead.h
[root@localhost include]# cd ..
[root@localhost client]# cd scripts
[root@localhost scripts]# vim makefile
[root@localhost scripts]# vim Makefile
[root@localhost scripts]# cd ..
[root@localhost client]# make
make[1]: Entering directory`/home/n2017/0120/client/add'
gcc -Wall -O3 -c -o src/add.o src/add.c
make[1]: Leaving directory`/home/n2017/0120/client/add'
make[1]: Entering directory`/home/n2017/0120/client/sub'
gcc -Wall -O3 -c -o src/sub.o src/sub.c
make[1]: Leaving directory`/home/n2017/0120/client/sub'
make[1]: Entering directory`/home/n2017/0120/client/mul'
gcc -Wall -O3 -c -o src/mul.o src/mul.c
make[1]: Leaving directory`/home/n2017/0120/client/mul'
make[1]: Entering directory`/home/n2017/0120/client/divi'
gcc -Wall -O3 -c -o src/divi.o src/divi.c
make[1]: Leaving directory`/home/n2017/0120/client/divi'
make[1]: Entering directory `/home/n2017/0120/client/main'
gcc -Wall -O3 -c -o src/main.o src/main.c
make[1]: Leaving directory`/home/n2017/0120/client/main'
gcc -Wall -O3 -o cal_main add/src/*.osub/src/*.o mul/src/*.o divi/src/*.o main/src/*.o -lpthread
cal_main make done!
[root@localhost client]# ls
add bin cal_main divi include main Makefile mul scripts sub
[roo
Vim main.c
#include
2#include "../../include/myhead.h"
3
4int main()
5 {
6 int a, b;
7 printf("please inputthe number is:\n");
8 scanf("%d,%d",&a,&b);
9 printf("a + b =%d\n", add(a,b));
10 printf("a - b = %d\n", sub(a,b));
11 printf("a * b = %d\n", mul(a,b));
12 printf("a / b = %d\n", divi(a,b));
13 return 0;
14 }
Vim myhead.h
8#ifndef MYHEAD_H_
9#define MYHEAD_H_
10
11int add(int,int);
12int sub(int,int);
13int mul(int,int);
14int divi(int,int);
15
16#endif /* MYHEAD_H_ */
Vim makefile
CC := gcc
2 CFLAGS := -Wall -O3
3 Libs = -lpthread
4 Target := cal_main
5 Source := $(wildcard src/*.c)
6 Objs := $(patsubst %.c,%.o,$(Source))
7 Modules += add sub mul divi main
8 AllObjs := $(addsuffix /src/*.o,$(Modules))