# 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案例的更多相关文章

  1. Linux学习笔记——例说makefile 综合案例

    0.前言     从学习C语言開始就慢慢開始接触makefile,查阅了非常多的makefile的资料但总感觉没有真正掌握makefile,假设自己动手写一个makefile总认为非常吃力.所以特意借 ...

  2. 五个demo案例带你学习PHP反序列化漏洞

    一直想研究下php反序列化漏洞,花了几天时间做了个简单的了解..写篇文章记录下. 直白点就是围绕着serialize和unserialize两个函数. 一个用于序列化,一个用于反序列化. 我们通常把字 ...

  3. Unity5.1 新的网络引擎UNET(二) UNET 官方推荐Demo案例

    http://blog.csdn.net/u010019717/article/details/46873153 视频 http://www.iqiyi.com/playlist391685502.h ...

  4. ThinkPHP 3.2 DEMO案例系列【phpmailer批量发送邮件】

    但是邮件和短信相比在一些场景依然有着重要的意义和优势: 1:零成本:发邮件没有费用: 2:内容丰富且量大:邮件可以长篇大论:图文并茂: 3:增加访问量:用户很容易通过邮件中的链接访问网站: 好了:下面 ...

  5. Android O 获取APK文件权限 Demo案例

    1. 通过 aapt 工具查看 APK权限 C:\Users\zh>adb pull /system/priv-app/Settings . /system/priv-app/Settings/ ...

  6. Css Secret 案例Demo全套

    Css Secret 案例全套 github地址 案例地址 去年买了一本CSS揭秘的css专题书,该书揭示了 47 个鲜为人知的 CSS 技巧,主要内容包括背景与边框.形状. 视觉效果.字体排印.用户 ...

  7. vue2.0 transition -- demo实践填坑

    前言 vue1.0版本和2.0版本的过渡系统改变还是蛮彻底的,具体请自行详看文档介绍:https://vuefe.cn/v2/guide/migration.html#过渡.在使用2.0版本做过渡效果 ...

  8. C编译: makefile基础

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在编译一个大型项目的时候,往往有很多目标文件.库文件.头文件以及最终的可执行文件. ...

  9. TP5学习基础一:增删改查小demo

    ①TP5--增删改查简单的demo 我先吐槽一下:因为工作需要研究tp5,去官网看了一下哎呦,资源挺多挺全啊!然后下载唯一免费的官方教程,我曹pdf打开533页.讲的很细但是开发能等看完才做吗?看到精 ...

随机推荐

  1. RNA_seq GATK 最佳实践

    GATK处理DNA 水平的snp 经验比较成熟,而RNA 水平较少,所以可能会存在错误 目前的流程兼顾了假阳性(不是真的snp位点)和假阴性(该位点是snp,却没有检测到):后续会不断改善     G ...

  2. FrameBot 软件安装测试

    背景:           FrameBot 用于纠正DNA序列中的插入和缺失,然后正确的翻译成蛋白质序列,frameBot 工具集成在RDPTools 中   源代码:           http ...

  3. C# 校验给定的ip地址是否合法

    函数用于检测ip地址格式是否合法,包括ip的组成格式,每隔段是否不超过255等,但这个函数不能验证这个ip地址是否可以ping通. /// <summary> /// 验证IP地址是否合法 ...

  4. js(数组篇02)

    原文:http://www.cnblogs.com/zaking/p/8686676.html 上一篇文章简单的介绍了一下js的类型,以及数组的增删方法.这一篇文章,我们一起来看看数组还有哪些用法,以 ...

  5. 浏览器兼容css

    原文:https://www.cnblogs.com/shizk/p/8459362.html 1.为什么会出现浏览器兼容问题? 由于各大主流浏览器由不同的厂家开发,所用的核心架构和代码也很难重和,这 ...

  6. spark1.4配置安装

    https://segmentfault.com/a/1190000004508993

  7. datepicker clone 控件错误

    删除id,并删除hasDatepicker //+ -  function changeRows(sender,desc){ var tr = $(sender).closest("tr&q ...

  8. express项目创建步骤

    安装nodejs 安装npm 安装express npm install -g express 安装express生成器 npm install -g express-generator 查看expr ...

  9. UGUI表情系统解决方案

    参考链接: https://blog.uwa4d.com/archives/Sparkle_UGUI.html http://tech.seasungame.com/blog/index.php/20 ...

  10. oracle数据库中sql%notfound的用法

    SQL%NOTFOUND 是一个布尔值.与最近的sql语句(update,insert,delete,select)发生交互,当最近的一条sql语句没有涉及任何行的时候,则返回true.否则返回fal ...