brief note on Makefile
来源:互联网 发布:电视盒子无法安软件 编辑:程序博客网 时间:2024/06/05 22:33
usage scene:
compile source code on Unix
auto compilation of the whole project
content:
instructions (like shell)
command “make”:
compile (+pack) + link
file "makefile":
tell command "make" how to compile & link
brief flow:
1) if the project has not been compiled before, compile all of the source files and link the target program
2) if it is compiled before and there's some files modified, compile the modified ones and link the target program
3) if the head file is modified, recompile the files that refer to it and relink the target program
A Sample(from wiki.ubuntu):
edit : main.o kbd.o command.o display.o \insert.o search.o files.o utils.o /*comments:if the .o files are modified then the following command will launch*/cc -o edit main.o kbd.o command.o display.o \insert.o search.o files.o utils.omain.o : main.c defs.hcc -c main.ckbd.o : kbd.c defs.h command.hcc -c kbd.ccommand.o : command.c defs.h command.hcc -c command.cdisplay.o : display.c defs.h buffer.hcc -c display.cinsert.o : insert.c defs.h buffer.hcc -c insert.csearch.o : search.c defs.h buffer.hcc -c search.cfiles.o : files.c defs.h buffer.h command.hcc -c files.cutils.o : utils.c defs.hcc -c utils.cclean :rm edit main.o kbd.o command.o display.o \insert.o search.o files.o utils.o
how dose make work:
1. find the file with the name "Makefile" or "makefile" in current folder
2. if found, make process will find the first target as the final target (in the sample code above, the target is file "edit")
3. if the file edit dose not exit, or the .o files are modified after they were linked, then make will execute the following shell code to emerge the file edit
4. if the .o files that file edit depends on dose not exit too, find the lines that describe it and run the command
5. so, at the beginning, make will create the .o files and then links them to be the final target
6. ADDITION: if the file, like file clean, does not have connections with other files, we can put it in an explicit command like "make clean" to do some special functions
parameter in makefile(sample comes from wiki.ubuntu):
objects = main.o kbd.o command.o display.o \insert.o search.o files.o utils.oedit : $(objects)cc -o edit $(objects)
let make auto emerge(default feature):
objects = main.o kbd.o command.o display.o \insert.o search.o files.o utils.o cc = gccedit : $(objects)cc -o edit $(objects)main.o : defs.hkbd.o : defs.h command.hcommand.o : defs.h command.hdisplay.o : defs.h buffer.hinsert.o : defs.h buffer.hsearch.o : defs.h buffer.hfiles.o : defs.h buffer.h command.hutils.o : defs.h.PHONY : clean /*to show that the clean is a fake target*/clean :rm edit $(objects)
make can let you collect the .h and .c files together, however, i don't like it, so let it go~O(∩_∩)O~
everthing above comes from wiki.ubuntu
- brief note on Makefile
- A Note on CMake - 5 An example: ESESC Makefile
- A brief on using CreateRemoteThread
- A brief survey on MCUs
- makefile and shell Note
- A Brief Note about Boltzmann/Softmax Exploration Strategy
- Note on Quick Sort
- Note on depth texture
- gentoo on kvm[note]
- note: KillProcess On R0
- note on paper review
- My Note on Algorithmn
- BRIEF
- BRIEF
- c++ note--makefile的编写
- [Note] Install Android on VirtualBox
- note on the threadPool function
- note on rest in practice
- GitHub是如何征服Google、微软和其它公司的
- Coderforces 396A
- 通过U盘安装Fedora21 Workstation
- iOS UICollectionView 入门 04 使用UICollectionView的准备工作
- 使用Openssl的AES加密算法
- brief note on Makefile
- 记一次谈判实践
- 环形链表相关题目解析
- Fragment生命周期
- 用CornerStone配置SVN,HTTP及svn简单使用说明
- 判断一颗二叉树是否为平衡二叉树
- clearcase 常用命令参考
- Win7下使用VS2013编写的ActvieX在XP下注册提示:LoadLibrary("XXX.dll")失败-找不到指定的程序
- CheckBoxGroup