SlideShare a Scribd company logo
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),;,: )

More Related Content

What's hot

TRunner
TRunnerTRunner
TRunner
Jeen Lee
 
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
Nikita 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 @Silex
Jeen Lee
 
PHP 5.3 Overview
PHP 5.3 OverviewPHP 5.3 Overview
PHP 5.3 Overview
jsmith92
 
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
brian 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 Tokyo
Masahiro Nagano
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
brian d foy
 
Introducing PHP Latest Updates
Introducing PHP Latest UpdatesIntroducing PHP Latest Updates
Introducing PHP Latest Updates
Iftekhar Eather
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
Lin Yo-An
 
How-to Integração Postfi
How-to Integração PostfiHow-to Integração Postfi
How-to Integração Postfi
Thiago Cavalcante
 
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
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
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
Patrick Allaert
 
實戰 Hhvm extension php conf 2014
實戰 Hhvm extension   php conf 2014實戰 Hhvm extension   php conf 2014
實戰 Hhvm extension php conf 2014
Ricky Su
 
Parsing JSON with a single regex
Parsing JSON with a single regexParsing JSON with a single regex
Parsing JSON with a single regex
brian d foy
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
Lin 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.5
Tom Corrigan
 
Cli the other sapi pbc11
Cli the other sapi pbc11Cli the other sapi pbc11
Cli the other sapi pbc11
Combell 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
 

What's hot (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?"
 

Viewers also liked

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 lab
FS Karimi
 
Lab2
Lab2Lab2
Programs for Operating System
Programs for Operating SystemPrograms for Operating System
Programs for Operating System
LPU
 
Os file
Os fileOs file
Os file
mominabrar
 
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 programs
Kandarp Tiwari
 
OS tutoring #1
OS tutoring #1OS tutoring #1
OS tutoring #1
JaeSang Yoo
 
O.s. lab all_experimets
O.s. lab all_experimetsO.s. lab all_experimets
O.s. lab all_experimets
Guru Janbheshver University, Hisar
 
FFmpeg
FFmpegFFmpeg
Openssl
OpensslOpenssl
Ooad lab manual
Ooad lab manualOoad lab manual
Ooad lab manual
Umamurthi Umamurthi
 
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 buildup
psychesnet Hsieh
 
Operating system lab manual
Operating system lab manualOperating system lab manual
Operating system lab manual
Meerut Institute of Technology
 
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
Luca Berardinelli
 
Os lab manual
Os lab manualOs lab manual
Os lab manual
Mohd Mohiuddin Ansari
 
Intro Uml
Intro UmlIntro Uml
Intro Uml
Kris der Rose
 
Memory reference instruction
Memory reference instructionMemory reference instruction
Memory reference instruction
Sanjeev Patel
 
Bank Database Project
Bank Database ProjectBank Database Project
Bank Database Project
DavidPerley
 

Viewers also liked (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 to Gun make

Introduction to GNU Make Programming Language
Introduction to GNU Make Programming LanguageIntroduction to GNU Make Programming Language
Introduction to GNU Make Programming Language
Shih-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 cowboy
Kenneth Geisshirt
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
Thninh2
 
shellScriptAlt.pptx
shellScriptAlt.pptxshellScriptAlt.pptx
shellScriptAlt.pptx
NiladriDey18
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
Gaurav Shinde
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
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
Ireneusz Skrobiś
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
Sami Said
 
Programming in Linux Environment
Programming in Linux EnvironmentProgramming in Linux Environment
Programming in Linux Environment
Dongho Kang
 
Php
PhpPhp
NYPHP March 2009 Presentation
NYPHP March 2009 PresentationNYPHP March 2009 Presentation
NYPHP March 2009 Presentation
brian_dailey
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
Ashrith Mekala
 
2010 Smith Scripting101
2010 Smith Scripting1012010 Smith Scripting101
2010 Smith Scripting101
bokonen
 
Composer, putting dependencies on the score
Composer, putting dependencies on the scoreComposer, putting dependencies on the score
Composer, putting dependencies on the score
Rafael 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
Php i basic chapter 3Php i basic chapter 3
Php i basic chapter 3
Muhamad Al Imran
 
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 to 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)
 

Recently uploaded

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 

Recently uploaded (20)

BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 

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),;,: )