1. You can specify where the. o file is generated
2. Can automatically search the original code file
The directory and file structures used for examples are roughly as follows:
App
Src
Obj
Test.o
a.o
A.cpp
Test.cpp
Makefile
Include
Bin
#make File v1.0
#define CharSet
Export Lc_all = Zh_cn. GBK
Export LANG = Zh_cn. GBK
#define GCC global variable
LIBS =-LPTHREAD-LRT
INCLUDE =-I.. /
CC = g++
Cflags + +-wno-deprecated-wall-g
#define TARGET File
BIN =.. /bin/test
#define COMPILE variable
Cur_path =./
Obj_path = $ (cur_path) obj/
#获取到本目录下所有cpp
All_cpp = $ (foreach dir,$ (Cur_path), $ (wildcard $ (dir) *.cpp))
#构造预期的目标. o File
All_obj = $ (Patsubst $ (Cur_path)%.cpp,%.o,$ (all_cpp))
Directory generated by #指定. o File
All_obj_pos = $ (Addprefix $ (Obj_path), $ (all_obj))
#define Target
Default
@echo "Make file Example v1.0"
@echo "Use Make all"
@echo $ (Depe)
All: $ (all_obj)
#. Phony:all
$ (CC) $ (LIBS) $ (cflags)-O $ (BIN) $ (all_obj_pos)
$ (all_obj):%.o:%.cpp
$ (CC) $ (INCLUDE) $ (cflags)-C $<-O $ (obj_path) $@
Clean:
-RM $ (Obj_path) *.O $ (BIN) *.O