SlideShare una empresa de Scribd logo
1 de 36
GUN Make

Reference: O’Reilly – Managing Projects with GNU Make 3th.




                                               Eric Hsieh
Outline
• Rule
• Variable and macro
• Functions
Introduction
• Why do we need GUN Make?
• Source -> Object -> Executable
• Goal: The make program is intended to
  automate the mundane aspects of
  transforming source code into an executable.
• Base on timestamp.
Rule
Target: Prereq1 Prereq2 …
<Tab> commands1
<Tab> commands2

Example:
hello: hello.c
      gcc hello.c –o hello
Rule
$make
gcc hello.c –o hello

#make again
$make
make: `hello.c’ is up to date.

(1)
Rule
Just print
$make - -just-print or –n

Comment character
# gcc hello.c –o hello

(M)
Rule
• Default goal
• Top-down (2)
Command Modifiers
• @   Do not echo the command. If you want to
      apply this modifier to all, you can use the
      --silent (or -s) option.
• -   The dash prefix indicates that errors in the
      command should be ignored by make.
      You can use --ignore-errors (or -i) option.
• +   The plus modifier tells make to execute the
      command even if the --just-print (or -n)
      command-line option is given to make.
Phony target
Goal: phony target is out of date.
Example:
clean:
      rm –rf *.o

$touch clean
$make clean
make: `clean’ is up to date.
Phony target
• Remember! Make cannot distinguish the
  different between target and phony target. So,
  we need define following:

.PHONY: clean
clean:
     rm –rf *.o
(2)
Standard phony target list
Empty target (Cookie)
Example: pl1029 opensource hello
.PHONY: install disclean
$(SOURCE)/.configured:
      cd $(SOURCE) && LDFLAGS='-s' CFLAGS='-Os' ./configure
      .......
      touch $@

install: $(SOURCE)/.configured
         make -C $(SOURCE) install-strip

distclean:
        make -C $(SOURCE) distclean
        rm -f $(SOURCE)/.configured
Variable name
• #define
• A = 1234
• CC := cc

• #use
• $A or $(A) or ${A}
• $(CC) or ${CC}
Variable name
• Run on Bash
hello:
         @echo "Hello, $${USER}" #shell variable USER
         @echo "Hello, ${USER}" #make variable USER
or
hello:
         @echo "Hello, $$USER" #shell variable USER
         @echo "Hello, $(USER)" #make variable USER
Automatic variable
• $@          target
• $%          archive member,
       Example: $@ is foo.a, $% is bar.o
       foo.a(bar.o): bar.o
             commands…
• $<          the first prereq
• $?          The names of all prerequisites that
              are newer than the target
Automatic variable
• $^   The names of all the prerequisites. This list
       has duplicate names removed.
• $+   Similar to $^, but it includes duplicates.
• $*   The stem of the target filename.
       Example: $* is hello
       hello.o: hello.c
              gcc hello.c –o hello.o
(3)
VPATH and vpath
• We can use VPATH or vpath to tell make where to
   find the source code.
.
|-- inc
| `-- saydone.h
|-- log
|-- Makefile
`-- src
   |-- hello.c
   |-- saydone.c
VPATH and vpath
• Without VPATH or vpath, we make it and we
  will get~

$make
make: *** No rule to make target `hello.c', needed by
`hello.o'. Stop.


• So, we need to tell make where to find source
  code by VPATH or vpath.(4)
Pattern rule
For example:
hello: hello.o
hello.o: hello.c

$make
cc -c -o hello.o hello.c
cc hello.o -o hello

We need to key “make - -print-data-base” to
understand pattern rule.(5)
Dependencies
$ echo "#include <stdio.h>" > stdio.c
$ gcc -M stdio.c
stdio.o: stdio.c /usr/include/stdio.h /usr/include/features.h 
/usr/include/bits/predefs.h /usr/include/sys/cdefs.h 
/usr/include/bits/wordsize.h /usr/include/gnu/stubs.h 
/usr/include/gnu/stubs-32.h 
/usr/lib/gcc/i686-linux-gnu/4.4.5/include/stddef.h 
/usr/include/bits/types.h /usr/include/bits/typesizes.h 
 /usr/include/libio.h /usr/include/_G_config.h
/usr/include/wchar.h 
/usr/lib/gcc/i686-linux-gnu/4.4.5/include/stdarg.h 
/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h
Dependencies
• So, we need to .d and include it.(6)
Manager archive library
libsay.a: libsay.a(saydone.o) libsay.a(hello.o)

libsay.a(saydone.o): saydone.o
       ar rv $@ $^
libsay.a(hello.o): hello.o
       ar rv $@ $^

Same as
libsay.a: saydone.o hello.o
       commands…
(8)
Assign variable
• Simply expanded variable --- immediately expanded
      MAKE_DEPEND := $(CC) –M

• Recursively expanded variable --- lazily expanded
      CURRENT_TIME = $(shell date)

• Conditional variable assignment operator
      OUTPUT_DIR ?= $(PRERIX)

• Append operator
      CPPFLAG += -lpthread
When Variables Are Expanded
When Variables Are Expanded
• The righthand side of += is expanded
  immediately if the lefthand side was originally
  defined as a simple variable. Otherwise, its
  evaluation is deferred.
• For rules, the targets and prerequisites are
  always immediately expanded while the
  commands are always deferred.
• (7.1)
Macro
• Syntax
define macro-name
     commands1
     commands2
endef
Macro
For example:
define ericEcho
      @echo Eric....
      @echo $(CC)
      @echo $(CPPFLAGS)
endef

#use
$(ericEcho) or $(call ericEcho)
Target- and Pattern-Specific Variables
Example:
gui.o: gui.h
         $(COMPILE.c) -DUSE_NEW_MALLOC=1 $(OUTPUT_OPTION) $<


or you can do it same as following
gui.o: CPPFLAGS += -DUSE_NEW_MALLOC=1
gui.o: gui.h
       #default pattern rule
Another example is libffmpeg.
Where Variables Come From
• Command line: (V)
   – make CFLAGS=-g CPPFLAGS=‘-DBSD –DDEBUG’
• File:
   – by include
• Environment:
   – by export or unexport
Conditional
• ifdef or ifndef
      ifdef RANLIB
             $(RANLIB) $@
      endif

• ifeq or ifneq
      ifeq “$(strip $(OPTIONS))” “-d”
             CPPFLAGS += - -DDEBUG
      endif
(3)
include
• The include directive is used like this:
     include definitions.mk
• Special characteristic.
     (4)
• If any of the include files is updated by a rule,
  make then clears its internal database and
  rereads the entire makefile.
Standard make Variables
• MAKE_VERSION:
      – This is the version number of GNU make.
• CURDIR:
      – This variable contains the current working directory of the
        executing make process.
• MAKECMDGOALS:
      – It contains a list of all the targets specified on the
         command line for the current execution of make.
      ifneq "$(MAKECMDGOALS)" "clean"
          -include $(DEPEND)
      Endif
(v)
Functions
• $(call macro,parm1 ….)
• $(shell command)
   – CURRENT := $(shell date)
• $(filter pattern,text) or $(filter-out pattern,text)
   HEADER := $(filter %.h, $(SOURCES))
Functions
• $(subst search-string,replace-string,text)
  OBJECTS := $(subst .c,.o,$(SOURCES))
• $(patsubst search-pattern,replace-pattern,text)
  and $(variable:search=replace)
  OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
  DEPENDS := $(SOURCES:%.c=%.d)
Functions
• $(wildcard pattern…)
  SRCS := $(wildcard *.c)
• $(suffix name)
  See example
• $(addsuffix suffix,name)
  common := $(addsuffix /common.mk,prefix)
  #common = prefix/common.mk
• $(error text)
Functions
• $(warning text)
• $(strip text)
• $(if condition,true-part,false-part)
     PATH_SEP := $(if $(COMSPEC),;,: )

Más contenido relacionado

La actualidad más candente

Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Nikita Popov
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model Perforce
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @SilexJeen Lee
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overviewjsmith92
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongersbrian d foy
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoMasahiro Nagano
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tiebrian d foy
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest UpdatesIftekhar Eather
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)James Titcumb
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 
實戰 Hhvm extension php conf 2014
實戰 Hhvm extension   php conf 2014實戰 Hhvm extension   php conf 2014
實戰 Hhvm extension php conf 2014Ricky Su
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regexbrian d foy
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5Tom Corrigan
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11Combell NV
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 

La actualidad más candente (20)

TRunner
TRunnerTRunner
TRunner
 
Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8Just-In-Time Compiler in PHP 8
Just-In-Time Compiler in PHP 8
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
Smolder @Silex
Smolder @SilexSmolder @Silex
Smolder @Silex
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 TokyoIntroduction to CloudForecast / YAPC::Asia 2010 Tokyo
Introduction to CloudForecast / YAPC::Asia 2010 Tokyo
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
How-to Integração Postfi
How-to Integração PostfiHow-to Integração Postfi
How-to Integração Postfi
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
實戰 Hhvm extension php conf 2014
實戰 Hhvm extension   php conf 2014實戰 Hhvm extension   php conf 2014
實戰 Hhvm extension php conf 2014
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
What's new in PHP 5.5
What's new in PHP 5.5What's new in PHP 5.5
What's new in PHP 5.5
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 

Destacado

work order of logic laboratory
work order of logic laboratory work order of logic laboratory
work order of logic laboratory FS Karimi
 
Bozorgmeh os lab
Bozorgmeh os labBozorgmeh os lab
Bozorgmeh os labFS Karimi
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating SystemLPU
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)Make Mannan
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programsKandarp Tiwari
 
Ooad lab manual(original)
Ooad lab manual(original)Ooad lab manual(original)
Ooad lab manual(original)dipenpatelpatel
 
ipv6 introduction & environment buildup
ipv6 introduction & environment buildupipv6 introduction & environment buildup
ipv6 introduction & environment builduppsychesnet Hsieh
 
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015Luca Berardinelli
 
Memory reference instruction
Memory reference instructionMemory reference instruction
Memory reference instructionSanjeev Patel
 
Bank Database Project
Bank Database ProjectBank Database Project
Bank Database ProjectDavidPerley
 

Destacado (20)

work order of logic laboratory
work order of logic laboratory work order of logic laboratory
work order of logic laboratory
 
Bozorgmeh os lab
Bozorgmeh os labBozorgmeh os lab
Bozorgmeh os lab
 
Lab2
Lab2Lab2
Lab2
 
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
 
Os file
Os fileOs file
Os file
 
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)Lab manual operating system [cs 502 rgpv] (usefulsearch.org)  (useful search)
Lab manual operating system [cs 502 rgpv] (usefulsearch.org) (useful search)
 
Os lab file c programs
Os lab file c programsOs lab file c programs
Os lab file c programs
 
OS tutoring #1
OS tutoring #1OS tutoring #1
OS tutoring #1
 
O.s. lab all_experimets
O.s. lab all_experimetsO.s. lab all_experimets
O.s. lab all_experimets
 
FFmpeg
FFmpegFFmpeg
FFmpeg
 
Openssl
OpensslOpenssl
Openssl
 
Ooad lab manual
Ooad lab manualOoad lab manual
Ooad lab manual
 
Ooad lab manual(original)
Ooad lab manual(original)Ooad lab manual(original)
Ooad lab manual(original)
 
ipv6 introduction & environment buildup
ipv6 introduction & environment buildupipv6 introduction & environment buildup
ipv6 introduction & environment buildup
 
Operating system lab manual
Operating system lab manualOperating system lab manual
Operating system lab manual
 
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
 
Os lab manual
Os lab manualOs lab manual
Os lab manual
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
 
Memory reference instruction
Memory reference instructionMemory reference instruction
Memory reference instruction
 
Bank Database Project
Bank Database ProjectBank Database Project
Bank Database Project
 

Similar a Gun make

Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageShih-Hsiang Lin
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Ahmed El-Arabawy
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptxNiladriDey18
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux EnvironmentDongho Kang
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentationbrian_dailey
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101bokonen
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the scoreRafael Dohms
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Benny Siegert
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Muhamad Al Imran
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Muhamad Al Imran
 

Similar a Gun make (20)

Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
 
Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands Course 102: Lecture 8: Composite Commands
Course 102: Lecture 8: Composite Commands
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
 
New features in Ruby 2.5
New features in Ruby 2.5New features in Ruby 2.5
New features in Ruby 2.5
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
 
Php
PhpPhp
Php
 
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the score
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]
 
Php i basic chapter 3
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
 
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
Php i basic chapter 3 (syahir chaer's conflicted copy 2013-04-22)
 
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
Php i basic chapter 3 (afifah rosli's conflicted copy 2013-04-23)
 

Último

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxcallscotland1987
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 

Último (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Gun make

  • 1. GUN Make Reference: O’Reilly – Managing Projects with GNU Make 3th. Eric Hsieh
  • 2. Outline • Rule • Variable and macro • Functions
  • 3. Introduction • Why do we need GUN Make? • Source -> Object -> Executable • Goal: The make program is intended to automate the mundane aspects of transforming source code into an executable. • Base on timestamp.
  • 4. Rule Target: Prereq1 Prereq2 … <Tab> commands1 <Tab> commands2 Example: hello: hello.c gcc hello.c –o hello
  • 5. Rule $make gcc hello.c –o hello #make again $make make: `hello.c’ is up to date. (1)
  • 6. Rule Just print $make - -just-print or –n Comment character # gcc hello.c –o hello (M)
  • 8. Command Modifiers • @ Do not echo the command. If you want to apply this modifier to all, you can use the --silent (or -s) option. • - The dash prefix indicates that errors in the command should be ignored by make. You can use --ignore-errors (or -i) option. • + The plus modifier tells make to execute the command even if the --just-print (or -n) command-line option is given to make.
  • 9. Phony target Goal: phony target is out of date. Example: clean: rm –rf *.o $touch clean $make clean make: `clean’ is up to date.
  • 10. Phony target • Remember! Make cannot distinguish the different between target and phony target. So, we need define following: .PHONY: clean clean: rm –rf *.o (2)
  • 12. Empty target (Cookie) Example: pl1029 opensource hello .PHONY: install disclean $(SOURCE)/.configured: cd $(SOURCE) && LDFLAGS='-s' CFLAGS='-Os' ./configure ....... touch $@ install: $(SOURCE)/.configured make -C $(SOURCE) install-strip distclean: make -C $(SOURCE) distclean rm -f $(SOURCE)/.configured
  • 13. Variable name • #define • A = 1234 • CC := cc • #use • $A or $(A) or ${A} • $(CC) or ${CC}
  • 14. Variable name • Run on Bash hello: @echo "Hello, $${USER}" #shell variable USER @echo "Hello, ${USER}" #make variable USER or hello: @echo "Hello, $$USER" #shell variable USER @echo "Hello, $(USER)" #make variable USER
  • 15. Automatic variable • $@ target • $% archive member, Example: $@ is foo.a, $% is bar.o foo.a(bar.o): bar.o commands… • $< the first prereq • $? The names of all prerequisites that are newer than the target
  • 16. Automatic variable • $^ The names of all the prerequisites. This list has duplicate names removed. • $+ Similar to $^, but it includes duplicates. • $* The stem of the target filename. Example: $* is hello hello.o: hello.c gcc hello.c –o hello.o (3)
  • 17. VPATH and vpath • We can use VPATH or vpath to tell make where to find the source code. . |-- inc | `-- saydone.h |-- log |-- Makefile `-- src |-- hello.c |-- saydone.c
  • 18. VPATH and vpath • Without VPATH or vpath, we make it and we will get~ $make make: *** No rule to make target `hello.c', needed by `hello.o'. Stop. • So, we need to tell make where to find source code by VPATH or vpath.(4)
  • 19. Pattern rule For example: hello: hello.o hello.o: hello.c $make cc -c -o hello.o hello.c cc hello.o -o hello We need to key “make - -print-data-base” to understand pattern rule.(5)
  • 20. Dependencies $ echo "#include <stdio.h>" > stdio.c $ gcc -M stdio.c stdio.o: stdio.c /usr/include/stdio.h /usr/include/features.h /usr/include/bits/predefs.h /usr/include/sys/cdefs.h /usr/include/bits/wordsize.h /usr/include/gnu/stubs.h /usr/include/gnu/stubs-32.h /usr/lib/gcc/i686-linux-gnu/4.4.5/include/stddef.h /usr/include/bits/types.h /usr/include/bits/typesizes.h /usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h /usr/lib/gcc/i686-linux-gnu/4.4.5/include/stdarg.h /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h
  • 21. Dependencies • So, we need to .d and include it.(6)
  • 22. Manager archive library libsay.a: libsay.a(saydone.o) libsay.a(hello.o) libsay.a(saydone.o): saydone.o ar rv $@ $^ libsay.a(hello.o): hello.o ar rv $@ $^ Same as libsay.a: saydone.o hello.o commands… (8)
  • 23. Assign variable • Simply expanded variable --- immediately expanded MAKE_DEPEND := $(CC) –M • Recursively expanded variable --- lazily expanded CURRENT_TIME = $(shell date) • Conditional variable assignment operator OUTPUT_DIR ?= $(PRERIX) • Append operator CPPFLAG += -lpthread
  • 24. When Variables Are Expanded
  • 25. When Variables Are Expanded • The righthand side of += is expanded immediately if the lefthand side was originally defined as a simple variable. Otherwise, its evaluation is deferred. • For rules, the targets and prerequisites are always immediately expanded while the commands are always deferred. • (7.1)
  • 26. Macro • Syntax define macro-name commands1 commands2 endef
  • 27. Macro For example: define ericEcho @echo Eric.... @echo $(CC) @echo $(CPPFLAGS) endef #use $(ericEcho) or $(call ericEcho)
  • 28. Target- and Pattern-Specific Variables Example: gui.o: gui.h $(COMPILE.c) -DUSE_NEW_MALLOC=1 $(OUTPUT_OPTION) $< or you can do it same as following gui.o: CPPFLAGS += -DUSE_NEW_MALLOC=1 gui.o: gui.h #default pattern rule Another example is libffmpeg.
  • 29. Where Variables Come From • Command line: (V) – make CFLAGS=-g CPPFLAGS=‘-DBSD –DDEBUG’ • File: – by include • Environment: – by export or unexport
  • 30. Conditional • ifdef or ifndef ifdef RANLIB $(RANLIB) $@ endif • ifeq or ifneq ifeq “$(strip $(OPTIONS))” “-d” CPPFLAGS += - -DDEBUG endif (3)
  • 31. include • The include directive is used like this: include definitions.mk • Special characteristic. (4) • If any of the include files is updated by a rule, make then clears its internal database and rereads the entire makefile.
  • 32. Standard make Variables • MAKE_VERSION: – This is the version number of GNU make. • CURDIR: – This variable contains the current working directory of the executing make process. • MAKECMDGOALS: – It contains a list of all the targets specified on the command line for the current execution of make. ifneq "$(MAKECMDGOALS)" "clean" -include $(DEPEND) Endif (v)
  • 33. Functions • $(call macro,parm1 ….) • $(shell command) – CURRENT := $(shell date) • $(filter pattern,text) or $(filter-out pattern,text) HEADER := $(filter %.h, $(SOURCES))
  • 34. Functions • $(subst search-string,replace-string,text) OBJECTS := $(subst .c,.o,$(SOURCES)) • $(patsubst search-pattern,replace-pattern,text) and $(variable:search=replace) OBJECTS := $(patsubst %.c,%.o,$(SOURCES)) DEPENDS := $(SOURCES:%.c=%.d)
  • 35. Functions • $(wildcard pattern…) SRCS := $(wildcard *.c) • $(suffix name) See example • $(addsuffix suffix,name) common := $(addsuffix /common.mk,prefix) #common = prefix/common.mk • $(error text)
  • 36. Functions • $(warning text) • $(strip text) • $(if condition,true-part,false-part) PATH_SEP := $(if $(COMSPEC),;,: )