A simple makefile (Specify obj file location)

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.