最近要针对项目文件进行整体修改,所以特地了解了makefile的相关内容。首先,makefile是一种在linux下进行项目管理的工具,关于项目的编译,清楚,重编译都可以在makefile中制作,我的小理解就是作为一个自动化部署的工具,你可以把你要写的命令行命令统一写在Makefile中。
关于编译:
这里说几个基本概念,对于makefile中你的写的第一个
target(目标):…
这个编译命令,就是你执行make的命令,即make执行的命令与你的target顺序有关,看下面我写的一段target:
TEAM = NOBODY
VERSION = 1
HANDINDIR = /afs/cs/academic/class/15213-f02/L5/handin
DRIVER = ./sdriver.pl
TSH = ./tsh
TSHREF = ./tshref
TSHARGS = "-p"
CC = gcc
CFLAGS = -Wall -O2 -g
FILES = ./myspin ./mysplit ./mystop ./myint
all: tsh $(FILES)
tsh: tsh.c funwitherr.c funwitherr.h jobs.c jobs.h mystring.c mystring.h
$(CC) $(CFLAGS) -o tsh tsh.c funwitherr.c jobs.c mystring.c
addition: myspin.c mysplit.c mystop.c myint.c
$(CC) $(CFLAGS) -o myspin myspin.c
$(CC) $(CFLAGS) -o mysplit mysplit.c
$(CC) $(CFLAGS) -o mystop mystop.c
$(CC) $(CFLAGS) -o myint myint.c
##################
# Handin your work
##################
handin:
cp tsh.c $(HANDINDIR)/$(TEAM)-$(VERSION)-tsh.c
##################
# Regression tests
##################
# Run tests using the student's shell program
test01:
$(DRIVER) -t ./test/trace01.txt -s $(TSH) -a $(TSHARGS)
test02:
$(DRIVER) -t ./test/trace02.txt -s $(TSH) -a $(TSHARGS)
test03:
$(DRIVER) -t ./test/trace03.txt -s $(TSH) -a $(TSHARGS)
test04:
$(DRIVER) -t ./test/trace04.txt -s $(TSH) -a $(TSHARGS)
test05:
$(DRIVER) -t ./test/trace05.txt -s $(TSH) -a $(TSHARGS)
test06:
$(DRIVER) -t ./test/trace06.txt -s $(TSH) -a $(TSHARGS)
test07:
$(DRIVER) -t ./test/trace07.txt -s $(TSH) -a $(TSHARGS)
test08:
$(DRIVER) -t ./test/trace08.txt -s $(TSH) -a $(TSHARGS)
test09:
$(DRIVER) -t ./test/trace09.txt -s $(TSH) -a $(TSHARGS)
test10:
$(DRIVER) -t ./test/trace10.txt -s $(TSH) -a $(TSHARGS)
test11:
$(DRIVER) -t ./test/trace11.txt -s $(TSH) -a $(TSHARGS)
test12:
$(DRIVER) -t ./test/trace12.txt -s $(TSH) -a $(TSHARGS)
test13:
$(DRIVER) -t ./test/trace13.txt -s $(TSH) -a $(TSHARGS)
test14:
$(DRIVER) -t ./test/trace14.txt -s $(TSH) -a $(TSHARGS)
test15:
$(DRIVER) -t ./test/trace15.txt -s $(TSH) -a $(TSHARGS)
test16:
$(DRIVER) -t ./test/trace16.txt -s $(TSH) -a $(TSHARGS)
testall:
$(DRIVER) -t ./test/trace01.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace02.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace03.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace04.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace05.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace06.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace07.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace08.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace09.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace10.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace11.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace12.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace13.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace14.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace15.txt -s $(TSH) -a $(TSHARGS)
$(DRIVER) -t ./test/trace16.txt -s $(TSH) -a $(TSHARGS)
# Run the tests using the reference shell program
rtest01:
$(DRIVER) -t trace01.txt -s $(TSHREF) -a $(TSHARGS)
rtest02:
$(DRIVER) -t trace02.txt -s $(TSHREF) -a $(TSHARGS)
rtest03:
$(DRIVER) -t trace03.txt -s $(TSHREF) -a $(TSHARGS)
rtest04:
$(DRIVER) -t trace04.txt -s $(TSHREF) -a $(TSHARGS)
rtest05:
$(DRIVER) -t trace05.txt -s $(TSHREF) -a $(TSHARGS)
rtest06:
$(DRIVER) -t trace06.txt -s $(TSHREF) -a $(TSHARGS)
rtest07:
$(DRIVER) -t trace07.txt -s $(TSHREF) -a $(TSHARGS)
rtest08:
$(DRIVER) -t trace08.txt -s $(TSHREF) -a $(TSHARGS)
rtest09:
$(DRIVER) -t trace09.txt -s $(TSHREF) -a $(TSHARGS)
rtest10:
$(DRIVER) -t trace10.txt -s $(TSHREF) -a $(TSHARGS)
rtest11:
$(DRIVER) -t trace11.txt -s $(TSHREF) -a $(TSHARGS)
rtest12:
$(DRIVER) -t trace12.txt -s $(TSHREF) -a $(TSHARGS)
rtest13:
$(DRIVER) -t trace13.txt -s $(TSHREF) -a $(TSHARGS)
rtest14:
$(DRIVER) -t trace14.txt -s $(TSHREF) -a $(TSHARGS)
rtest15:
$(DRIVER) -t trace15.txt -s $(TSHREF) -a $(TSHARGS)
rtest16:
$(DRIVER) -t trace16.txt -s $(TSHREF) -a $(TSHARGS)
# clean up
clean:
rm -f $(FILES) $(TSH) *.o *~
最开始的CC=…,开始的都是变量的设定。
后面的all:..
tsh:…. additional:…都是一些相关的编译命令。
要执行这些命令,只需要在命令行输入make all ,make tsh , make additional
当然,你如果在shell里输入make 执行的就是all里面的命令,这和你的target的顺序有关
在makelife使用变量的时候,需要用$(变量) 这样的符号来包围变量。
暂时只学了这么多,后面在补充,关于makefile,这里有一个很好资料,在这放出:
http://blog.csdn.net/ruglcc/article/details/7814546/