SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Downloaden Sie, um offline zu lesen
Linux
-makefile
by Kevin Wu 2014/11/21
1
0
Agenda
2
 用途
 基本語法
 Athena應用
 練習
Makefile
3
 自動化編譯
 寫自動化的指令 (安裝、壓縮...)
 適用不同的編譯器make工具
 Delphi的make,Visual C++的nmake,Linux下GNU的make
Makefile
4
 Machine-readable
 Workflow
 any dependent files are regenerated with minimal effort.
 Testable
 Syntax:
 targetfile: sourcefile
command
Example - makefile
5
 # comments
 #一些變數宣告

 target1: dependencies of target1
 <TAB>command;
 target2: dependencies of target2
 <TAB>command;
 ...
 ...
 clean:
 <TAB>rm -rf *.o
Example - make
6
 make
 make [-f makefile|Makefile]
 make clean
 make foo=bar target
 makeARGS="asdf" run
 recall how we install tmux :
wget http://downloads.sourceforge.net/tmux/tmux-1.9a.tar.gz
tar -xvzf tmux-1.9a.tar.gz
cd tmux-1.9a
./configure
make
make install
Scenario
7
 Download a zip archive from the Census Bureau.
 Extract the shapefile from the archive.
 Convert the shapefile toTopoJSON.
Scenario
8
 counties.zip:
curl -o counties.zip‘http:url/file.zip‘
 counties.shp: counties.zip
unzip counties.zip
touch counties.shp
 counties.json: counties.shp
topojson -o counties.json -- counties=counties.shp
makefile vs shell
9
 變數與變數內容以『=』隔開,同時兩邊可以具有空格;
 為了Makefile的可移植性,建議使用具有空格的表示方法
 變數左邊不可以有 <tab>
 變數與變數內容在『=』兩邊不能具有『:』;
 運用變數時,以 ${變數} 或 $(變數) 使用;
 parentheses seems better than curly brackets
 在指令列模式也可以給予變數。
 變數值決定
 1st make 指令列後面加上的環境變數為優先;
 2nd makefile 裡面指定的環境變數;
 3rd shell 原本具有的環境變數。
 makefile only:
 $?:代表需要重建(被修改)的相依性項目。
 $@:目前的目標項目名稱。
 $<:代表目前的相依性項目。
 $* :代表目前的相依性項目,不過不含副檔名。
 - :make 會忽略命令的錯誤
 @ :make 不會在標準輸出上,顯示要執行的命令。
Athena應用
10
 系統安裝
 Install Python2.7.8
 Build Symbolic Link
 Yum Setting
 Install pip
 Install the third-party lib for Python2.7.8
 Install the necessary library for tmux
 Install the tmux
 Copy the SSH key from remote athena and pandora
 Create migo folder under /data
 Luigi Job檢核
 執行前檢查
 檢查requires檔案是否存在
 刪除中繼檔案
 刪除output檔案
 執行後檢查
 中繼檔案是否存在
 output檔案是否存在
 刪除中繼檔案
Case (See Problem?)
11
 test: gen-a gen-p
@echo "$@ done“
rm *.o
rm *.pip
 gen-a:
rm $@.o
touch $@.o
 gen-p: a.pip b.pip
 @echo "$@ done"
 %.pip: gen-a.o
 touch $@
 echo "$@ done“
 [hint] : rm -> -rm, rm -> rm –f, gen-a -> install
Solved
12
 rm *.o
• -rm *.o
• -rm –f *.o
• don’t let it parallel go
*Example - Advanced
13
 #usage:make main OR make
 SHELL = /usr/bin/bash #宣告command所使用的shell環境為bash
 CC = gcc #欲使用的C compiler
 CFLAGS = -O3 -ansi #欲使用的參數
 INC = -I /usr/foo/include
 LIB = -L /usr/foo/lib

 .SUFFIXS: .c .cpp .f77 .f #加入所列副檔名到隱含規則裡
 main: main.o foo1.o foo2.o
 ${CC} main.o foo1.o ${CFLAGS} ${INC} ${LIB} -o $@
 %.o: %.c target.h
 ${CC} $< ${CFLAGS} ${INC} ${LIB} -lpthread -c
 .PHONY: clean
 clean:
 @rm -rf *.o
Practice
14
 建立一個makefile, 至少包含
 build : 可touch 出a.out b.out c.out, 若檔案都存在則echo出”build done”
 clean : 刪除所有.out檔
 rebuild : 會clean再build, 若檔案都存在則echo出”rebuild done”
 相依性條件:
 a.out為主要任務(檔案),需要 b.out存在才能產出
 b.out 需要 c.out存在才能產出
 c.out不須任何相依檔案,
 測試結果是否正常
 make rebuild
 rm any .out file (you choose)
 make build, 自動讓缺少的檔案產生出來
 提示
 將a/b/c分開寫各自的dependency與command
 使用$@變數
Answer
15
 clean:
 -rm -f *.out
 a.out: | b.out
 touch a.out
 b.out: | c.out
 touch b.out
 c.out:
 touch c.out
 build: a.out
 @echo $@ done
 rebuild: clean build
 @echo $@ done
Thank you
16

Weitere ähnliche Inhalte

Was ist angesagt?

Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Yiwei Ma
 
Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)fisher zheng
 
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具Will Huang
 
Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档xuebao_zx
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)heima911
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversionYiwei Ma
 
Mysql mmm安装指南(翻译)
Mysql mmm安装指南(翻译)Mysql mmm安装指南(翻译)
Mysql mmm安装指南(翻译)Yiwei Ma
 
Cent os 安装 subversion
Cent os 安装 subversionCent os 安装 subversion
Cent os 安装 subversionYUCHENG HU
 
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務我的 Windows 平台自動化經驗:基礎批次檔撰寫實務
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務Will Huang
 
持续集成在Flex_as3应用程序中的应用v4
持续集成在Flex_as3应用程序中的应用v4持续集成在Flex_as3应用程序中的应用v4
持续集成在Flex_as3应用程序中的应用v4jexchan
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & WindowsChu-Siang Lai
 
5, system admin
5, system admin5, system admin
5, system adminted-xu
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchangChang Mt
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理haiyuan ning
 

Was ist angesagt? (18)

Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)Nagios的安装部署和与cacti的整合(linuxtone)
Nagios的安装部署和与cacti的整合(linuxtone)
 
Intro to svn
Intro to svnIntro to svn
Intro to svn
 
Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)Nae client(using Node.js to create shell cmd)
Nae client(using Node.js to create shell cmd)
 
Gnu
GnuGnu
Gnu
 
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具
《保哥線上講堂》打造一個具有 Linux 溫度的 Windows 命令提示字元工具
 
Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档Oraliux+mysql5单机多实例安装文档
Oraliux+mysql5单机多实例安装文档
 
使用dd命令快速复制LV
使用dd命令快速复制LV使用dd命令快速复制LV
使用dd命令快速复制LV
 
九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)九州通 Tsm重新配置文档(2008 11 10)
九州通 Tsm重新配置文档(2008 11 10)
 
Centos下安装apache + subversion
Centos下安装apache + subversionCentos下安装apache + subversion
Centos下安装apache + subversion
 
Mysql mmm安装指南(翻译)
Mysql mmm安装指南(翻译)Mysql mmm安装指南(翻译)
Mysql mmm安装指南(翻译)
 
Cent os 安装 subversion
Cent os 安装 subversionCent os 安装 subversion
Cent os 安装 subversion
 
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務我的 Windows 平台自動化經驗:基礎批次檔撰寫實務
我的 Windows 平台自動化經驗:基礎批次檔撰寫實務
 
OSGi Small Lab
OSGi Small LabOSGi Small Lab
OSGi Small Lab
 
持续集成在Flex_as3应用程序中的应用v4
持续集成在Flex_as3应用程序中的应用v4持续集成在Flex_as3应用程序中的应用v4
持续集成在Flex_as3应用程序中的应用v4
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows
現代 IT 人一定要知道的 Ansible 自動化組態技巧 Ⅱ - Roles & Windows
 
5, system admin
5, system admin5, system admin
5, system admin
 
Openshift by mtchang
Openshift by mtchangOpenshift by mtchang
Openshift by mtchang
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理
 

Ähnlich wie makefile20141121

Docker tutorial
Docker tutorialDocker tutorial
Docker tutorialazole Lai
 
X64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newX64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newYiwei Ma
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结Yiwei Ma
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)acqua young
 
康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)Yiwei Ma
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定Shengyou Fan
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command lineWen Liao
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理Jason Zheng
 
Android系统移植技术详解
Android系统移植技术详解Android系统移植技术详解
Android系统移植技术详解zzc89522
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practicelitaocheng
 
Linux基础
Linux基础Linux基础
Linux基础zhuqling
 
利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版xingsu1021
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Chu-Siang Lai
 
Learning python in the motion picture industry by will zhou
Learning python in the motion picture industry   by will zhouLearning python in the motion picture industry   by will zhou
Learning python in the motion picture industry by will zhouWill Zhou
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版redhat9
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linuxYiwei Ma
 

Ähnlich wie makefile20141121 (20)

gnutool
gnutoolgnutool
gnutool
 
Docker tutorial
Docker tutorialDocker tutorial
Docker tutorial
 
X64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 newX64服务器 lamp服务器部署标准 new
X64服务器 lamp服务器部署标准 new
 
Make talk-cn
Make talk-cnMake talk-cn
Make talk-cn
 
Puppet安装总结
Puppet安装总结Puppet安装总结
Puppet安装总结
 
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
Install oracle ebs r12.1.1 on OEL5.6 x86(include demo)
 
康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)康盛创想项目部Linux 服务器部署标准(最新版)
康盛创想项目部Linux 服务器部署标准(最新版)
 
啟動 Laravel 與環境設定
啟動 Laravel 與環境設定啟動 Laravel 與環境設定
啟動 Laravel 與環境設定
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command line
 
使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理使用Rpm&yum进行基础软件管理
使用Rpm&yum进行基础软件管理
 
Android系统移植技术详解
Android系统移植技术详解Android系统移植技术详解
Android系统移植技术详解
 
Erlang Practice
Erlang PracticeErlang Practice
Erlang Practice
 
Linux基础
Linux基础Linux基础
Linux基础
 
利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版利用Cent Os快速构建自己的发行版
利用Cent Os快速构建自己的发行版
 
Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)Automate with Ansible basic (3/e)
Automate with Ansible basic (3/e)
 
Learning python in the motion picture industry by will zhou
Learning python in the motion picture industry   by will zhouLearning python in the motion picture industry   by will zhou
Learning python in the motion picture industry by will zhou
 
Linuxguide4f2e
Linuxguide4f2eLinuxguide4f2e
Linuxguide4f2e
 
LinuxGuide4F2E
LinuxGuide4F2ELinuxGuide4F2E
LinuxGuide4F2E
 
Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版Bypat博客出品-利用cent os快速构建自己的发行版
Bypat博客出品-利用cent os快速构建自己的发行版
 
Kick start无人值守批量安装linux
Kick start无人值守批量安装linuxKick start无人值守批量安装linux
Kick start无人值守批量安装linux
 

makefile20141121

  • 3. Makefile 3  自動化編譯  寫自動化的指令 (安裝、壓縮...)  適用不同的編譯器make工具  Delphi的make,Visual C++的nmake,Linux下GNU的make
  • 4. Makefile 4  Machine-readable  Workflow  any dependent files are regenerated with minimal effort.  Testable  Syntax:  targetfile: sourcefile command
  • 5. Example - makefile 5  # comments  #一些變數宣告   target1: dependencies of target1  <TAB>command;  target2: dependencies of target2  <TAB>command;  ...  ...  clean:  <TAB>rm -rf *.o
  • 6. Example - make 6  make  make [-f makefile|Makefile]  make clean  make foo=bar target  makeARGS="asdf" run  recall how we install tmux : wget http://downloads.sourceforge.net/tmux/tmux-1.9a.tar.gz tar -xvzf tmux-1.9a.tar.gz cd tmux-1.9a ./configure make make install
  • 7. Scenario 7  Download a zip archive from the Census Bureau.  Extract the shapefile from the archive.  Convert the shapefile toTopoJSON.
  • 8. Scenario 8  counties.zip: curl -o counties.zip‘http:url/file.zip‘  counties.shp: counties.zip unzip counties.zip touch counties.shp  counties.json: counties.shp topojson -o counties.json -- counties=counties.shp
  • 9. makefile vs shell 9  變數與變數內容以『=』隔開,同時兩邊可以具有空格;  為了Makefile的可移植性,建議使用具有空格的表示方法  變數左邊不可以有 <tab>  變數與變數內容在『=』兩邊不能具有『:』;  運用變數時,以 ${變數} 或 $(變數) 使用;  parentheses seems better than curly brackets  在指令列模式也可以給予變數。  變數值決定  1st make 指令列後面加上的環境變數為優先;  2nd makefile 裡面指定的環境變數;  3rd shell 原本具有的環境變數。  makefile only:  $?:代表需要重建(被修改)的相依性項目。  $@:目前的目標項目名稱。  $<:代表目前的相依性項目。  $* :代表目前的相依性項目,不過不含副檔名。  - :make 會忽略命令的錯誤  @ :make 不會在標準輸出上,顯示要執行的命令。
  • 10. Athena應用 10  系統安裝  Install Python2.7.8  Build Symbolic Link  Yum Setting  Install pip  Install the third-party lib for Python2.7.8  Install the necessary library for tmux  Install the tmux  Copy the SSH key from remote athena and pandora  Create migo folder under /data  Luigi Job檢核  執行前檢查  檢查requires檔案是否存在  刪除中繼檔案  刪除output檔案  執行後檢查  中繼檔案是否存在  output檔案是否存在  刪除中繼檔案
  • 11. Case (See Problem?) 11  test: gen-a gen-p @echo "$@ done“ rm *.o rm *.pip  gen-a: rm $@.o touch $@.o  gen-p: a.pip b.pip  @echo "$@ done"  %.pip: gen-a.o  touch $@  echo "$@ done“  [hint] : rm -> -rm, rm -> rm –f, gen-a -> install
  • 12. Solved 12  rm *.o • -rm *.o • -rm –f *.o • don’t let it parallel go
  • 13. *Example - Advanced 13  #usage:make main OR make  SHELL = /usr/bin/bash #宣告command所使用的shell環境為bash  CC = gcc #欲使用的C compiler  CFLAGS = -O3 -ansi #欲使用的參數  INC = -I /usr/foo/include  LIB = -L /usr/foo/lib   .SUFFIXS: .c .cpp .f77 .f #加入所列副檔名到隱含規則裡  main: main.o foo1.o foo2.o  ${CC} main.o foo1.o ${CFLAGS} ${INC} ${LIB} -o $@  %.o: %.c target.h  ${CC} $< ${CFLAGS} ${INC} ${LIB} -lpthread -c  .PHONY: clean  clean:  @rm -rf *.o
  • 14. Practice 14  建立一個makefile, 至少包含  build : 可touch 出a.out b.out c.out, 若檔案都存在則echo出”build done”  clean : 刪除所有.out檔  rebuild : 會clean再build, 若檔案都存在則echo出”rebuild done”  相依性條件:  a.out為主要任務(檔案),需要 b.out存在才能產出  b.out 需要 c.out存在才能產出  c.out不須任何相依檔案,  測試結果是否正常  make rebuild  rm any .out file (you choose)  make build, 自動讓缺少的檔案產生出來  提示  將a/b/c分開寫各自的dependency與command  使用$@變數
  • 15. Answer 15  clean:  -rm -f *.out  a.out: | b.out  touch a.out  b.out: | c.out  touch b.out  c.out:  touch c.out  build: a.out  @echo $@ done  rebuild: clean build  @echo $@ done