# 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. Linux系统date时间设定

    修改linux系统的时间EDT和EST为CST EDT:指美国东部夏令时间 EST:英国时间 CST:北京时间 那么现在只要改成北京时间的时区CST就可以了,修改如下: [root@localhost ...

  2. 每天一个linux命令:mkdir命令

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...

  3. 基于Redis实现分布式锁以及任务队列

    一.前言 双十一刚过不久,大家都知道在天猫.京东.苏宁等等电商网站上有很多秒杀活动,例如在某一个时刻抢购一个原价1999现在秒杀价只要999的手机时,会迎来一个用户请求的高峰期,可能会有几十万几百万的 ...

  4. jquery带token访问接口ajax

    1.在公共js里全局设置 //设置全局ajax $.ajaxSetup({ xhrFields: { withCredentials: true } }); 2.登录成功时,设置cookie (注: ...

  5. iOS:DKLiveBlur

    https://github.com/kronik/DKLiveBlur Sources of DKLiveBlur and Demo app to show live blur effect sim ...

  6. thikphp5.0 ip地址库 解决卡顿问题 curl_init

    使用淘宝新浪的地址库非常的使用,但是调用有时候会出现很慢.会导致卡在当前网页. 要想不影响当前速度,因此要使用 curl_init功能. 项目案例:会员登陆日志 user_log 字段:id,user ...

  7. LoadRunner做性能测试 从设计到分析执行

    项目简介:像百度知道系统类似的系统性能测试,是公司的自己产品. 对最近这个系统的性能测试进行总结下: 系统功能介绍: 前台用户可以根据自己的需要对不同的区域提问,提问包括匿名和登陆用户提问 后台不同区 ...

  8. Android开发中常用的库总结(持续更新)

    这篇文章用来收集Android开发中常用的库,都是实际使用过的.持续更新... 1.消息提示的小红点 微信,微博消息提示的小红点. 开源库地址:https://github.com/stefanjau ...

  9. es 5 数组reduce方法记忆

    reduce() 方法接收一个函数作为累加器(accumulator),数组中的每个值(从左到右)开始合并,最终为一个值. 概念:对数组中的所有元素调用指定的回调函数.该回调函数的返回值为累积结果,并 ...

  10. Java学习路线图(如何快速学Java)

    不知不觉从初学Java到现在已经8年了,今天在这里给刚入门和入门不久的小伙伴们一些建议.可能总结的不是很详细,但给出了一个大概的学习路线.希望对大家有帮助哈~ 如何快速学Java 这里我以Java E ...