下面是我写的一个简单的makefile文件,学习了makefile的基本语法。
#makefile Example
OBJ=main.o delete_node.o selection_sort.o create_list.o concatenate.o
test:$(OBJ)
gcc -o test $(OBJ)
main.o:main.c head.h
gcc -c main.c
delete_node.o:delete_node.c head.h
gcc -c delete_node.c
selection_sort.o:selection_sort.c head.h
gcc -c selection_sort.c
create_list.o:create_list.c head.h
gcc -c create_list.c
concatenate.o:concatenate.c head.h
gcc -c concatenate.c
install:
./test
clean:
rm -f *.o
/
如下是执行过程
fei@fei-pc:~/Makefile_test$ ls
concatenate.c create_list.c delete_node.c head.h main.o selection_sort.c test
concatenate.o create_list.o delete_node.o main.c makefile selection_sort.o
fei@fei-pc:~/Makefile_test$ vi makefile
fei@fei-pc:~/Makefile_test$ make
make: “test”是最新的。
fei@fei-pc:~/Makefile_test$ make install
./test
: 3
: 8
: 9
: 11
: 12
make: *** [install] 错误 5
fei@fei-pc:~/Makefile_test$ make clean
rm -f *.o
fei@fei-pc:~/Makefile_test$
/
遗憾的是,make install 执行结果有错,但是运行./test没错。