【makefile】01 经典应用示例

 经典应用示例

1. 文件结构

NetServer
├── docs
│   └── images
│       ├── WebBench_hello.png
│       ├── WebBench_html.png
│       ├── wrk_hello_4_iothread_2_workerthread.png
│       ├── wrk_hello_4_iothread.png
│       ├── wrk_hello.png
│       ├── wrk_html_4_iothread_2_workerthread.png
│       ├── wrk_html_4_iothread.png
│       └── wrk_html.png
├── LICENSE
├── Makefile
├── NetServer
│   ├── Channel.cpp
│   ├── Channel.h
│   ├── coroutine
│   │   ├── coroutine.cpp
│   │   ├── coroutine-C-style
│   │   │   ├── coroutine.cpp
│   │   │   ├── coroutine.h
│   │   │   └── coroutine_test.cpp
│   │   ├── coroutine.h
│   │   ├── coroutine_test.cpp
│   │   ├── LICENSE
│   │   └── README.md
│   ├── EchoServer.cpp
│   ├── EchoServer.h
│   ├── EventLoop.cpp
│   ├── EventLoop.h
│   ├── EventLoopThread.cpp
│   ├── EventLoopThread.h
│   ├── EventLoopThreadPool.cpp
│   ├── EventLoopThreadPool.h
│   ├── HttpServer.cpp
│   ├── HttpServer.h
│   ├── HttpSession.cpp
│   ├── HttpSession.h
│   ├── index.html
│   ├── log
│   │   ├── LICENSE
│   │   ├── logger.cpp
│   │   ├── logger.h
│   │   ├── logtest.cpp
│   │   └── README.md
│   ├── main.cpp
│   ├── Poller.cpp
│   ├── Poller.h
│   ├── Socket.cpp
│   ├── Socket.h
│   ├── TcpConnection.cpp
│   ├── TcpConnection.h
│   ├── TcpServer.cpp
│   ├── TcpServer.h
│   ├── ThreadPool.cpp
│   ├── ThreadPool.h
│   ├── Timer.cpp
│   ├── Timer.h
│   ├── TimerManager.cpp
│   └── TimerManager.h
└── README.md

2. makefile文件书写:

 1 IR_BIN = .
 2 DIR_OBJ = ./obj
 3 DIR_SRC = ./NetServer
 4 
 5 SRC = $(wildcard $(DIR_SRC)/*.cpp)
 6 OBJ = $(patsubst %.cpp,$(DIR_OBJ)/%.o,$(notdir $(SRC)))
 7 
 8 
 9 CXX_FLAG = -g -Wall -std=c++11 -pthread -O3
10 CC = g++
11 
12 TARGET = httpserver
13 
14 $(DIR_BIN)/$(TARGET) : $(OBJ)
15     $(CC) $(CXX_FLAG) -o $@ $^
16 
17 $(DIR_OBJ)/%.o : $(DIR_SRC)/%.cpp
18     if [ ! -d $(DIR_OBJ) ];    then mkdir -p $(DIR_OBJ); fi;
19     $(CC) $(CXX_FLAG) -c $< -o $@
20 
21 .PHONY : clean
22 clean : 
23     -rm -rf $(DIR_OBJ)

参考资料

1. NetServer

2. 跟我一起写Makefile

原文地址:https://www.cnblogs.com/sunbines/p/15422843.html