Makefile Writing
Make-f makefile1 Designation
The following is my point Makefile study notes, and then share a good write makefile summary of the website:
Http://www.cnblogs.com/wang_yb/p/3990952.html
mode one, the same directory has multiple. c. h files Cross_compile=arm-none-linux-gnueabi-GCC#CC=arm-none-linux-gnueabi-gcc test_res:=regdebugobjects=MAIN.O UART.O #下面这行表示依赖关系 that all. o files are dependent on. C # [email protected] is the target%. O%.o:%. C Arm-none-linux-gnueabi-gcc-c $<-o [email protected] $ (test_res): $ (objects) #$ (CC) $^ -o [email protected] $ (cross_compile) $^ -o [email protected]. Phony:clean Clean:rm-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) mode two, the same directory has more than one. C. h file cc=arm-none-linux-gnueabi-gcc test_res:=regdebugobjects=main.o UART.O $ (test_res): $ (objects) $ (CC) $^ -o [email protected]. Phony:clean Clean:rm-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (Test_res) method Three, put the compilation generated intermediate file in obj, compile the generated executable file in the bin directory Test_res:= bin/regdebugobjects=./obj/MAIN.O./obj/UART.O./obj/%.o:%. C $ (CC)-C $<-o [email protected]$ (test_res): $ (objects) $ (CC) $^ -o [email protected]. PHONY:CLEANCLEAN:RM-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (objects) method Four, replace the path with Objdir objdir=Objtest_res:= bin/regdebugobjects= $ (objdir)/MAIN.O $ (objdir)/uart.o$ (objdir)/%.o:%. C $ (CC)-C $<-o [email protected]$ (test_res): $ (objects) $ (CC) $^ -o [email protected]. PHONY:CLEANCLEAN:RM-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (objects) method v. Put UART.C and uart.h in the package directory cc=arm-none-linux-gnueabi-gcc Includdir=-I Packageobjdir=Objtest_res:= bin/regdebugobjects= $ (objdir)/MAIN.O $ (objdir)/uart.o$ (objdir)/%.o:%. C $ (CC) $ (includdir)-C $<-o [email protected] $ (objdir)/%.o:./package/%. C $ (CC) $ (includdir)-C $<-o [email protected] $ (test_res): $ (objects) $ (CC) $^ -o [email protected]. Phony:clean Clean:rm-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (objects) method VI, CC=arm-none-linux-gnueabi-Gccincluddir=-I Packageobjdir=Objtest_res:= bin/regdebugobjects= $ (objdir)/MAIN.O-include./package/obj.mk$ (objdir)/%.o:%. C $ (CC) $ (includdir)-C $<-o [email protected]$ (objdir)/%.o:./package/%. C $ (CC) $ (includdir)-C $<-o [email protected]$ (test_res): $ (OBJECTS) $ (CC) $^ -o [email protected]. PHONY:CLEANCLEAN:RM-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (OBJECTS) obj.mkobjects+ =./obj/UART.O Method VII. Place all header files in the Include directory cc=arm-none-linux-gnueabi-Gccincluddir=-I Includeobjdir=Objtest_res:= bin/regdebugobjects= $ (objdir)/MAIN.O-include./package/obj.mk$ (objdir)/%.o:%. C $ (CC) $ (includdir)-C $<-o [email protected]$ (objdir)/%.o:./package/%. C $ (CC) $ (includdir)-C $<-o [email protected]$ (test_res): $ (OBJECTS) $ (CC) $^ -o [email protected]. PHONY:CLEANCLEAN:RM-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (OBJECTS) method VIII, #CC=arm-none-linux-gnueabi-gcc #INCLUDDIR=-I Include#objdir=obj-include Rules.mktest_res:= bin/regdebugobjects= $ (objdir)/MAIN.O-include./package/obj.mk$ (objdir)/%.o:%. C $ (CC) $ (includdir)-C $<-o [email protected] $ (objdir)/%.o:./package/%. C $ (CC) $ (includdir)-C $<-o [email protected] $ (test_res): $ (OBJECTS) $ (CC) $^ -o [email protected]. PHONY:CLEANCLEAN:RM-RF. *.cmd *.O *. mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res) RM-RF $ (OBJECTS) rules.mk file in cc=arm-none-linux-gnueabi-Gccincluddir=-I Includeobjdir=obj
Method IX,
The directory structure is as follows
Executable file under Bin
Include as header file
Intermediate file under obj for compilation
Various C files under the package
root directory under Makefile
-include rules.mk
Test_res: = Bin/regdebug
OBJECTS = $ (objdir)/MAIN.O
-include./package/obj.mk
$ (objdir)/%.o:%.c
$ (CC) $ (includdir)-C $<-o [email protected]-std=gnu99
$ (objdir)/%.o:./package/%.c
$ (CC) $ (includdir)-C $<-o [email protected]-std=gnu99
$ (Test_res): $ (OBJECTS)
$ (CC) $^-o [email protected]-lpthread-std=gnu99
chmod a+x [email protected]
. Phony:clean
Clean
Rm-rf. *.cmd *.o *.mod.c. Tmp_versions module.symvers. MAKEFILE.SWP $ (test_res)
RM-RF $ (OBJECTS)
root directory under RULES.MK:
cc=arm-none-linux-gnueabi-gcc
Includdir=-i include
Objdir=obj
Package directory under OBJ.MK
OBJECTS + =/obj/uart.o \
./OBJ/CONSOLE.O \
./OBJ/REG_DATA.O \
./OBJ/FUNC.O \
./OBJ/RUN.O \
./obj/revdataone.o
If reproduced please indicate the source
Sina Blog: http://blog.sina.com.cn/u/2049150530
Blog Park: http://www.cnblogs.com/sky-heaven/
Know: Http://www.zhihu.com/people/zhang-bing-hua
Makefile's several ways of writing "original"