当前位置:网站首页>makefile 常用函数notdir、wildcard、patsubst
makefile 常用函数notdir、wildcard、patsubst
2022-07-23 14:30:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
notdir,wildcard和patsubst是makefile中几个有用的函数,以前没留意过makefile中函数的用法,今天稍微看看~
1、makefile里的函数
makefile里的函数使用,和取变量的值类似,是以一个‘$’开始,然后是一个括号里面是函数名和需要的参数列表,多个变量用逗号隔开,像这样
return = $(functionname arg1,arg2,arg3…)。
可能这里的’$’更像是从某个地址取值类似的操作。
2、 wildcard
使用:SRC = $(wildcard *.c ./foo/*.c)
搜索当前目录及./foo/下所有以.c结尾的文件,生成一个以空格间隔的文件名列表,并赋值给SRC.当前目录文件只有文件名,子目录下的文件名包含路径信息,比如./foor/bar.c。
3、notdir
使用:SRC = $(notdir wildcard)
去除所有的目录信息,SRC里的文件名列表将只有文件名。
4、patsubst
使用:OBJ = (patsubst %.o %.c (SRC))
patsubst是patten substitude的缩写,匹配替代的意思。这句是在SRC中找到所有.c 结尾的文件,然后把所有的.c换成.o。
传说中的万能makefile
###########################################################
# Generic makefile
#
# by George Foot
# email: [email protected]
#
# Copyright (c)
1997 George Foot
# All rights reserved.
# 保留所有版權
#
# No warranty, no liability;
# you use
this at your own risk.
# 沒保險,不負責
# 你要用這個,你自己擔風險
#
# You are free to modify and
# distribute
this without giving
# credit to the original author.
# 你可以隨便更改和散發這個文件
# 而不需要給原作者什榮譽。
# (你好意思?)
#
######################################
### Customising
#
# Adjust the following
if necessary; EXECUTABLE
is the target
# executable
‘
s filename, and LIBS is a list of libraries to link in
# (e.g. alleg, stdcx, iostr, etc). You can
override these on make
‘
s
# command line of course,
if you prefer to
do it that way.
#
# 如果需要,調整下面的東西。 EXECUTABLE 是目標的可執行文件名, LIBS
# 是一個需要連接的程序包列表(例如 alleg, stdcx, iostr 等等)。當然你
# 可以在 make 的命令行覆蓋它們,你願意就沒問題。
#
EXECUTABLE := mushroom.exe
LIBS := alleg
# Now alter any
implicit rules
‘
variables if you like, e.g.:
#
# 現在來改變任何你想改動的隱含規則中的變量,例如
CFLAGS := -g -Wall -O3 -m486
CXXFLAGS := $(CFLAGS)
# The next bit checks to see whether rm
is
in your djgpp bin
# directory;
if not it uses del instead, but
this can cause (harmless)
# `File not found
‘
error messages. If you are not using DOS at all,
#
set the variable to something which will unquestioningly remove
# files.
#
# 下面先檢查你的 djgpp 命令目錄下有沒有 rm 命令,如果沒有,我們使用
# del 命令來代替,但有可能給我們
‘
File not found
‘ 這個錯誤信息,這沒
# 什大礙。如果你不是用 DOS ,把它設定成一個刪文件而不廢話的命令。
# (其實這一步在 UNIX 類的系統上是多余的,只是方便 DOS 用戶。 UNIX
# 用戶可以刪除這5行命令。)
ifneq ($(wildcard $(DJDIR)/bin/rm.exe),)
RM-F := rm -f
else
RM-F := del
endif
# You shouldn
‘
t need to change anything below this point.
#
# 從這裡開始,你應該不需要改動任何東西。(我是不太相信,太NB了!)
SOURCE := $(wildcard *.c) $(wildcard *.cc)
OBJS := $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(SOURCE)))
DEPS := $(patsubst %.o,%.d,$(OBJS))
MISSING_DEPS := $(filter-
out $(wildcard $(DEPS)),$(DEPS))
MISSING_DEPS_SOURCES := $(wildcard $(patsubst %.d,%.c,$(MISSING_DEPS)) \
$(patsubst %.d,%.cc,$(MISSING_DEPS)))
CPPFLAGS += -MD
.PHONY : everything deps objs clean veryclean rebuild
everything : $(EXECUTABLE)
deps : $(DEPS)
objs : $(OBJS)
clean :
@$(RM-F) *.o
@$(RM-F) *.d
veryclean: clean
@$(RM-F) $(EXECUTABLE)
rebuild: veryclean everything
ifneq ($(MISSING_DEPS),)
$(MISSING_DEPS) :
@$(RM-F) $(patsubst %.d,%.o,[email protected])
endif
-include $(DEPS)
$(EXECUTABLE) : $(OBJS)
gcc -o $(EXECUTABLE) $(OBJS) $(addprefix -l,$(LIBS))
###
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/126487.html原文链接:https://javaforall.cn
边栏推荐
- 使用BoundsChecker「建议收藏」
- 解决data functions should return an object 并(Property “visible“ must be accessed with “$data.visible“)
- 软件测试计划包括哪些内容,测试计划如何编写。分享测试计划模板
- Failure analysis and solution of vscode PIO creation project
- Win11如何添加图片3D效果?Win11添加图片3D效果的方法
- Preliminary understanding of string
- Shell | 查看进程的方法的不完全总结
- 浏览器同源策略
- ROS2自学笔记:RQT可视化工具
- C语言基础篇 —— 2-5 指针与函数知识点
猜你喜欢

When does MySQL use table locks and row locks?

虾皮二面:JVM内存布局你知道的都说一下?

Sorting - introduction, code ideas, usage suggestions, code implementation -1

SQL bool盲注和时间盲注详解

【Web漏洞探索】SQL注入漏洞

Pyinstaller+InstallForge多文件项目软件打包

keras——accuracy_score公式

合宙ESP32C3基于VSCode PIO Arduino开发框架初探教程

程序环境和预处理

【Flutter -- 布局】弹性布局(Flex 和 Expanded)
随机推荐
排序-介绍,代码思路,使用建议,代码实现-1
Leetcode-168.excel table column name
PWN entry (3) heap
IR Drop 、EM、Noise 和Antenna
程序环境和预处理
Tips and tricks for Neural Networks 深度学习训练神经网络的技巧总结(不定期更新)
SQL报错盲注详解
Could not load dynamic library ‘cudnn64_8.dll‘; dlerror: cudnn64_8.dll not found
pwn入门(3)堆
C语言基础篇 —— 2-5 指针与函数知识点
PMP每日一练 | 考试不迷路-7.23
docker 安装redis
unity之制作二维码扫描
Pymoo学习 (4): 多标准决策
【Flutter -- 布局】线性布局(Row 和 Column)
[MySQL]一、MySQL起步
Case analysis of building campus information management system with low code
JS if the decimal is 0, subtract it, not keep it
gom及gee架设黑屏的原因以及个别装备地图不显示怎么办?
How many common SQL misuses are there in MySQL?