[项目][WebServer][Makefile & Shell]详细讲解

目录


1.Makefile

  • 为了方便构建项目,并将其发布,使用Makefile来管理构建项目
makefile 复制代码
bin = httpserver
cgi = test_cgi
cc = g++
GLD_FLAGS = -std=c++11 -D DEBUG_SHOW
LD_FLAGS = $(GLD_FLAGS) -lpthread
src = main.cc
curr = $(shell pwd)

.PHONY:ALL
ALL:$(bin) $(cgi)

$(bin):$(src)
	$(cc) -o $@ $^ $(LD_FLAGS)

$(cgi):$(curr)/CGI/*.cc
	$(cc) -o $@ $^ $(GLD_FLAGS)

.PHONY:output
output:
	mkdir output
	cp $(bin) output
	cp -rf wwwroot output
	cp $(cgi) output/wwwroot
	cp ./CGI/shell_cgi.sh output/wwwroot
	cp ./CGI/python_cgi.py output/wwwroot

.PHONY:clean
clean:
	rm -f $(bin) $(cgi)
	rm -rf output

2. build.sh

  • 在项目后期,构建项目并发布时,要执行以下指令,略显繁琐,所以将其放进shell脚本内
    • make clean
    • make
    • make output
  • 后面构建项目时,只需要./build.sh,则可一键构建项目,并将其发布
sh 复制代码
#!/bin/bash

make clean
make
make output

3.test.sh

  • 在项目后期,测试项目时,为测试发布版本,要执行以下指令,略显繁琐,所以将其放进shell脚本内
    • ./build.sh
    • cd ./output
    • ./httpserver PORT
  • 后面测试项目时,只需要./test.sh,则可一键发布,并切换至发布目录下,直接运行项目
sh 复制代码
#!/bin/bash

./build.sh
cd ./output
./httpserver PORT
相关推荐
肆忆_20 小时前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星1 天前
虚函数表:C++ 多态背后的那个男人
c++
不可能的是1 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
端平入洛3 天前
delete又未完全delete
c++
端平入洛4 天前
auto有时不auto
c++
郑州光合科技余经理5 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1235 天前
matlab画图工具
开发语言·matlab
dustcell.5 天前
haproxy七层代理
java·开发语言·前端
norlan_jame5 天前
C-PHY与D-PHY差异
c语言·开发语言
哇哈哈20215 天前
信号量和信号
linux·c++