本博客(http://blog.csdn.net/livelylittlefish )贴出作者(阿波)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
Content
8.1如何自动编译?
8.2如何自动运行并保存结果?
附录 4 :再改进的方法的代码weight3.1.c/3.2.c/3.3.c
附录 5 :再改进的方法的代码weight3.1.c/3.2.c/3.3.c 的输出结果
附录 7 :一个更简单的方法的代码weight5.1.c/5.2.c/5.3.c
8. 所有代码的自动编译、运行
8.1 如何自动编译?
要自动编译所有的例子代码,很容易想到makefile文件。makefile的编写方法,可参考跟我一起写makefile、驾驭makefile、编写makefile。对于该例子,笔者编写的makefile文件如下。
CC = gcc
CXXFLAGS += -g -Wall -Wextra
TARGET = weight1 weight2 weight3.1 weight3.2 weight3.3 weight4 weight5.1 weight5.2 weight5.3
CLEANUP = rm -f $(TARGET) *.o
all : $(TARGET)
clean :
$(CLEANUP)
weight1.o: weight1.c
$(CC) $(CXXFLAGS) -c $^
weight2.o: weight2.c
$(CC) $(CXXFLAGS) -c $^
weight3.1.o: weight3.1.c
$(CC) $(CXXFLAGS) -c $^
weight3.2.o: weight3.2.c
$(CC) $(CXXFLAGS) -c $^
weight3.3.o: weight3.3.c
$(CC) $(CXXFLAGS) -c $^
weight4.o: weight4.c
$(CC) $(CXXFLAGS) -c $^
weight5.1.o: weight5.1.c
$(CC) $(CXXFLAGS) -c $^
weight5.2.o: weight5.2.c
$(CC) $(CXXFLAGS) -c $^
weight5.3.o: weight5.3.c
$(CC) $(CXXFLAGS) -c $^
all:
weight1: weight1.o
$(CC) $(CXXFLAGS) $^ -o $@
weight2: weight2.o
$(CC) $(CXXFLAGS) $^ -o $@
weight3.1: weight3.1.o
$(CC) $(CXXFLAGS) $^ -o $@
weight3.2: weight3.2.o
$(CC) $(CXXFLAGS) $^ -o $@
weight3.3: weight3.3.o
$(CC) $(CXXFLAGS) $^ -o $@
weight4: weight4.o
$(CC) $(CXXFLAGS) $^ -o $@
weight5.1.o: weight5.1.c
$(CC) $(CXXFLAGS) -c $^
weight5.2.o: weight5.2.c
$(CC) $(CXXFLAGS) -c $^
weight5.3.o: weight5.3.c
$(CC) $(CXXFLAGS) -c $^
rm -f *.o
8.2 如何自动运行并保存结果?
编写自动运行并保存运行结果的脚本autorun.sh,运行后,其结果被自动保存到同名的.txt文件中,如下。
echo -e "start to run all examples\n"
echo "weight1 running ..."
./weight1 > weight1.txt
echo " result is in weight1.txt"
echo "weight2 running ..."
./weight2 > weight2.txt
echo " result is in weight2.txt"
echo "weight3.1 running ..."
./weight3.1 > weight3.1.txt
echo " result is in weight3.1.txt"
echo "weight3.2 running ..."
./weight3.2 > weight3.2.txt
echo " result is in weight3.2.txt"
echo "weight3.3 running ..."
./weight3.3 > weight3.3.txt
echo " result is in weight3.3.txt"
echo "weight4 running ..."
./weight4 > weight4.txt
echo " result is in weight4.txt\n"
echo "weight5.1 running ..."
./weight5.1 > weight5.1.txt
echo " result is in weight5.1.txt"
echo "weight5.2 running ..."
./weight5.2 > weight5.2.txt
echo " result is in weight5.2.txt"
echo "weight5.3 running ..."
./weight5.3 > weight5.3.txt
echo " result is in weight5.3.txt"
echo "done. bye."
![](http://img.zemanta.com/pixy.gif?x-id=a85873ce-4995-84e1-b35d-a0fc37c4c121)