makefile -eg1 : makefile的嵌套使用

开发环境 :

ubuntu : 16.04

IDE : vscode

Lau : C++


工程结构如下 :

Dependencies : 依赖库生成工程.

StartUpProject : 启动工程.



StartUpProject -> makefile

CC = g++

SUB_DIR := ./Dependencies/

all : $(SUB_DIR)
	@echo Success
	
$(SUB_DIR) : ECHO
		cd ../$(SUB_DIR) && make && cd ../StartUpProject

ECHO :
	@echo $(SUB_DIR)
	@echo begin compile 
	@echo 


Dependencies -> makefile

cc = g++

src_path = ./src
src = $(wildcard $(src_path)/*.cpp)#指定路径下的所有cpp

obj_path = ./objs
objs =$(patsubst %.cpp, %.o, $(addprefix ./objs/, $(notdir $(src)))) 
#ndobjs = $(notdir $(src))
include_path = ./include
includes = $(wildcard $(include_path)/*.h)
libs_path = ./libs
target = $(libs_path)/libfun.a

all : $(target)	build

$(target) : $(objs)
	ar cr $@ $(objs) 
	
build:
	@echo $(includes)
	@echo $(src)
	@echo $(objs)
	
$(objs) : $(src)
	$(cc) -c $< -o $@ 

	




运行StartUpProject makefile结果:

./Dependencies/
begin compile

cd .././Dependencies/ && make && cd ../StartUpProject
make[1]: Entering directory '/home/erric/Codes/Linux/Cmake/cmake_tutorial/m4step/Dependencies'
g++ -c src/fun.cpp -o objs/fun.o
g++ -c src/fun.cpp -o objs/test.o
ar cr libs/libfun.a  ./objs/fun.o  ./objs/test.o
./include/test.h ./include/fun.h
./src/fun.cpp ./src/test.cpp
./objs/fun.o ./objs/test.o
make[1]: Leaving directory '/home/erric/Codes/Linux/Cmake/cmake_tutorial/m4step/Dependencies'
Success

码云下载地址 :https://gitee.com/DomTech/Cmake

欢迎各位大大指教。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值