Makefile Demo案例
# Comments can be written like this. # File should be named Makefile and then can be run as `make <target>`.
# Otherwise we use `make -f "filename" <target>`. # Warning - only use TABS to indent in Makefiles, never spaces! #-----------------------------------------------------------------------
# Basics
#----------------------------------------------------------------------- # Rules are of the format
# target: <prerequisite>
# where prerequisites are optional. # A rule - this rule will only run if file0.txt doesn't exist.
file0.txt:
echo "foo" > file0.txt
# Even comments in these 'recipe' sections get passed to the shell.
# Try `make file0.txt` or simply `make` - first rule is the default. # This rule will only run if file0.txt is newer than file1.txt.
file1.txt: file0.txt
cat file0.txt > file1.txt
# use the same quoting rules as in the shell.
@cat file0.txt >> file1.txt
# @ stops the command from being echoed to stdout.
-@echo 'hello'
# - means that make will keep going in the case of an error.
# Try `make file1.txt` on the commandline. # A rule can have multiple targets and multiple prerequisites
file2.txt file3.txt: file0.txt file1.txt
touch file2.txt
touch file3.txt # Make will complain about multiple recipes for the same rule. Empty
# recipes don't count though and can be used to add new dependencies. #-----------------------------------------------------------------------
# Phony Targets
#----------------------------------------------------------------------- # A phony target. Any target that isn't a file.
# It will never be up to date so make will always try to run it.
all: maker process # We can declare things out of order.
maker:
touch ex0.txt ex1.txt # Can avoid phony rules breaking when a real file has the same name by
.PHONY: all maker process
# This is a special target. There are several others. # A rule with a dependency on a phony target will always run
ex0.txt ex1.txt: maker # Common phony targets are: all make clean install ... #-----------------------------------------------------------------------
# Automatic Variables & Wildcards
#----------------------------------------------------------------------- process: file*.txt #using a wildcard to match filenames
@echo $^ # $^ is a variable containing the list of prerequisites
@echo $@ # prints the target name
#(for multiple target rules, $@ is whichever caused the rule to run)
@echo $< # the first prerequisite listed
@echo $? # only the dependencies that are out of date
@echo $+ # all dependencies including duplicates (unlike normal)
#@echo $| # all of the 'order only' prerequisites # Even if we split up the rule dependency definitions, $^ will find them
process: ex1.txt file0.txt
# ex1.txt will be found but file0.txt will be deduplicated. #-----------------------------------------------------------------------
# Patterns
#----------------------------------------------------------------------- # Can teach make how to convert certain files into other files. %.png: %.svg
inkscape --export-png $^ # Pattern rules will only do anything if make decides to create the
# target. # Directory paths are normally ignored when matching pattern rules. But
# make will try to use the most appropriate rule available.
small/%.png: %.svg
inkscape --export-png --export-dpi 30 $^ # make will use the last version for a pattern rule that it finds.
%.png: %.svg
@echo this rule is chosen # However make will use the first pattern rule that can make the target
%.png: %.ps
@echo this rule is not chosen if *.svg and *.ps are both present # make already has some pattern rules built-in. For instance, it knows
# how to turn *.c files into *.o files. # Older makefiles might use suffix rules instead of pattern rules
.png.ps:
@echo this rule is similar to a pattern rule. # Tell make about the suffix rule
.SUFFIXES: .png #-----------------------------------------------------------------------
# Variables
#-----------------------------------------------------------------------
# aka. macros # Variables are basically all string types name = Ted
name2="Sarah" echo:
@echo $(name)
@echo ${name2}
@echo $name # This won't work, treated as $(n)ame.
@echo $(name3) # Unknown variables are treated as empty strings. # There are 4 places to set variables.
# In order of priority from highest to lowest:
# 1: commandline arguments
# 2: Makefile
# 3: shell environment variables - make imports these automatically.
# 4: make has some predefined variables name4 ?= Jean
# Only set the variable if environment variable is not already defined. override name5 = David
# Stops commandline arguments from changing this variable. name4 +=grey
# Append values to variable (includes a space). # Pattern-specific variable values (GNU extension).
echo: name2 = Sara # True within the matching rule
# and also within its remade recursive dependencies
# (except it can break when your graph gets too complicated!) # Some variables defined automatically by make.
echo_inbuilt:
echo $(CC)
echo ${CXX)}
echo $(FC)
echo ${CFLAGS)}
echo $(CPPFLAGS)
echo ${CXXFLAGS}
echo $(LDFLAGS)
echo ${LDLIBS} #-----------------------------------------------------------------------
# Variables 2
#----------------------------------------------------------------------- # The first type of variables are evaluated each time they are used.
# This can be expensive, so a second type of variable exists which is
# only evaluated once. (This is a GNU make extension) var := hello
var2 ::= $(var) hello
#:= and ::= are equivalent. # These variables are evaluated procedurally (in the order that they
# appear), thus breaking with the rest of the language ! # This doesn't work
var3 ::= $(var4) and good luck
var4 ::= good night #-----------------------------------------------------------------------
# Functions
#----------------------------------------------------------------------- # make has lots of functions available. sourcefiles = $(wildcard *.c */*.c)
objectfiles = $(patsubst %.c,%.o,$(sourcefiles)) # Format is $(func arg0,arg1,arg2...) # Some examples
ls: * src/*
@echo $(filter %.txt, $^)
@echo $(notdir $^)
@echo $(join $(dir $^),$(notdir $^)) #-----------------------------------------------------------------------
# Directives
#----------------------------------------------------------------------- # Include other makefiles, useful for platform specific code
include foo.mk sport = tennis
# Conditional compilation
report:
ifeq ($(sport),tennis)
@echo 'game, set, match'
else
@echo "They think it's all over; it is now"
endif # There are also ifneq, ifdef, ifndef foo = true ifdef $(foo)
bar = 'hello'
endif
Makefile Demo案例的更多相关文章
- Linux学习笔记——例说makefile 综合案例
0.前言 从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...
- 五个demo案例带你学习PHP反序列化漏洞
一直想研究下php反序列化漏洞,花了几天时间做了个简单的了解..写篇文章记录下. 直白点就是围绕着serialize和unserialize两个函数. 一个用于序列化,一个用于反序列化. 我们通常把字 ...
- Unity5.1 新的网络引擎UNET(二) UNET 官方推荐Demo案例
http://blog.csdn.net/u010019717/article/details/46873153 视频 http://www.iqiyi.com/playlist391685502.h ...
- ThinkPHP 3.2 DEMO案例系列【phpmailer批量发送邮件】
但是邮件和短信相比在一些场景依然有着重要的意义和优势: 1:零成本:发邮件没有费用: 2:内容丰富且量大:邮件可以长篇大论:图文并茂: 3:增加访问量:用户很容易通过邮件中的链接访问网站: 好了:下面 ...
- Android O 获取APK文件权限 Demo案例
1. 通过 aapt 工具查看 APK权限 C:\Users\zh>adb pull /system/priv-app/Settings . /system/priv-app/Settings/ ...
- Css Secret 案例Demo全套
Css Secret 案例全套 github地址 案例地址 去年买了一本CSS揭秘的css专题书,该书揭示了 47 个鲜为人知的 CSS 技巧,主要内容包括背景与边框.形状. 视觉效果.字体排印.用户 ...
- vue2.0 transition -- demo实践填坑
前言 vue1.0版本和2.0版本的过渡系统改变还是蛮彻底的,具体请自行详看文档介绍:https://vuefe.cn/v2/guide/migration.html#过渡.在使用2.0版本做过渡效果 ...
- C编译: makefile基础
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在编译一个大型项目的时候,往往有很多目标文件.库文件.头文件以及最终的可执行文件. ...
- TP5学习基础一:增删改查小demo
①TP5--增删改查简单的demo 我先吐槽一下:因为工作需要研究tp5,去官网看了一下哎呦,资源挺多挺全啊!然后下载唯一免费的官方教程,我曹pdf打开533页.讲的很细但是开发能等看完才做吗?看到精 ...
随机推荐
- 如何在Web.config中注册用户控件和自定义控件
问题: 在ASP.NET 的早先版本里,开发人员通过在页面的顶部添加 指令来引入和使用自定义服务器控件和用户控件时,象这样: <%@ Register TagPrefix="scott ...
- 机器学习——利用PCA来简化数据
降维技术的好处: 1.使得数据集更易使用 2.降低很多算法的计算开销 3.取出噪声 4.使得结果易懂 在已标注和未标注的数据上都有降维技术,降维的方法: 1.主成分分析(Principal Compo ...
- Scripting.FileSystemObject对象的详细技巧指南
Scripting.FileSystemObject对象的详细技巧指南 FileSystemObject对象提供对计算机文件系统的访问: powered by 25175.net 在代码内操作文本文件 ...
- MongoDB 之 幽灵操作避免
进行静态加载数据到集合的过程中可能会出现. 假设建立一个任务(Job):在MongoDB中进行千条更新操作,开始后迅速终止任务,终止所有更新操作,但依然发现新的更新任务在不断出现,即使任务已经停止. ...
- level 6 - unit3 -- 非限制性定语从句
非限制性定语从句 例子1 he has a son who is a fireman who 引导一个定语从句. who 是修饰前面的son. 翻译的意思:他有一个消防员的儿子 he has a so ...
- mysql数据库2
命令行客户端软件MySQL Command Line Client, 打开该程序,输入数据库密码,登陆到MySQL软件, 如果想通过该命令行工具来操作MySQL软件,只需要在"mysql&g ...
- 一些JavaScript基本函数
1.document.write(”");为 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html->(head,body) 4.一个浏览 ...
- Servlet入门总结及第一个Servlet程序
目录 一了解Servlet的概念 二Servlet技术功能 三 Servlet技术特点 四 Servlet生命周期 五servlet工作过程 六 Servlet与JSP区别 七Servlet代码结构 ...
- [AX]AX2012 R2 EP员工自助服务中的产品不能显示图片的问题
在员工自助服务EP站点中员工可以通过Order products自助提交采购申请,在正确设置员工采购目录后会罗列出允许员工购买的产品,每个产品都可带有图片,我们可以通过Product image来为产 ...
- error C4996: Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct
使用VS13 跟 google protocbuf时出现了这个问题:真蛋疼,用别人的东西你就说不安全,用你自己的东西时你怎么不说不安全来着! 解决方案 在protoc 生成的头文件中加上 #pr ...