# 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. CSS3小清新下拉菜单 简易大方

    之前有分享过几款CSS3菜单和jQuery菜单,像这款HTML5/CSS3自定义下拉框 3D卡片折叠动画3D效果非常华丽,这次要分享的这款相对比较简单,很适合用在用户的操作面板上.先来看看效果图: 怎 ...

  2. 【Java集合的详细研究1】Collections类常用方法总结

    1.sort(Collection)方法的使用(含义:对集合进行排序). 例:对已知集合c进行排序? public class Practice { public static void main(S ...

  3. memcached监控工具

    最简单和最直接的方式是在启动memcached的时候加入-vv参数,从而在控制台打印每次客户端的请求和相应,这非常适合开发.另外一种较为直接的方式是通过telnet进行查看,例如:若server为本机 ...

  4. SOA及分布式

    结合领域驱动设计的SOA分布式软件架构 Windows平台分布式架构实践 - 负载均衡(下) 分享一个分布式消息总线,基于.NET Socket Tcp的发布-订阅框架,附代码下载 我终于深入参与了一 ...

  5. js requestAnimationFrame

    requestAnimationFrame,Web中写动画的另一种选择  原文:https://www.cnblogs.com/Wayou/p/requestAnimationFrame.html H ...

  6. 【DL】物体识别与定位

    https://cloud.tencent.com/community/article/414833

  7. 1. BeeGo 介绍与项目的创建,启动

    简介 BeeGo是一个快速开发Go而应用的HTTP框架,他可以用来快速开发API,web以及后端服务等各种应用,是一个restful 的框架,主要涉及灵感来源于tornado,sinatr和flask ...

  8. win8 关闭防火墙

    http://jingyan.baidu.com/article/b87fe19eddb4da5218356894.html

  9. Ubuntu下PHP动态编译出现Cannot find autoconf的解决方法

    执行phpize时出现Cannot find autoconf 错误 Ubuntu下解决方法 sudo apt-get install autoconf

  10. 在jstl表达式中嵌入el表达式

    一.问题 在jsp中,想要这么写: <c:url value='/resources/themes/${easyuiThemeName}/easyui.css'/> 但报错:Accordi ...