SlideShare uma empresa Scribd logo
1 de 23
Introduction To Makefile
Makefile Tutorial
EL KTAOUI ZAKARIA
Email: : elktaoui@outlook.com
Faecbook: https://www.facebook.com/Elktaoui.zakaria
Linkedin: ma.linkedin.com/in/elktaoui/
Table of Content
 Introduction
 Why Makefile ?
 How does it work ?
 How to Make a simple Makefile ?
 Makefile Rules
Sudo has a Make 
Introduction
The utility simply known as make is one of the
most enduring features of both Unix and other
operating systems.
First invented in the 1970s, make still turns up
to this day as the central engine in
most programming projects; it even builds
the Linux kernel.
In this presentation you will learn why this
utility continues to hold its top position
in project build software, despite many
younger competitors.
Makefile Why ?
 Make checks timestamps to see what has changed and rebuilds just
what you need, without wasting time rebuilding other files.
 Manage Several source files and compile them quickly with a single
Command Line.
 Make layers a rich collection of options that lets you manipulate
multiple directories, build different versions of programs for different
platforms, and customize your builds in other ways.
Make Utility

If you run
make

This will cause the make program to read the makefile and build the first
target it finds there

.

If you have several makefiles, then you can
execute them with the command:
make -f mymakefile
For more options use : $ man make
How does it work ?
Typically the default goal in most makefiles is to build
a program. This usually involves many steps:
1. Generate the source code using some utilities like Flex &
Bison.
2. Compile the source code into binary file (.o files c/c++/java
etc ..
3. bound the Object files together using a linker( gcc/g++) to
form an executable program(.exe)
How does it work ?
Makefile contains a set of rules used to build
an application.
The first rule (default rule) seen by make
consists of three parts:
 The Target.
 The Dependencies.
 The Command to be performed.
Target and Dependencies
Now let’s see the Make Process :
 Make is asked to evaluate a rule, it begins by finding the files
indicated by the dependencies and target.
 If any of the dependencies has an associated rule, make attempts to
update those first. Next, the target file is considered.

 If any dependency is newer than the target, the target is
remade by executing the commands.
 If any dependency is newer than the target, the target is
remade by executing the commands.
How to Make a Simple Makefile
Exec: projet.o test.o
gcc –o exec projet.o test.o
projet.o: projet.c
gcc –o projet.o –c projet.c –Wall
Test.o: test.c
gcc –o main.o –c test.c -Wall
How to Make a Simple Makefile
 The target file Exec appears before the colon.

 The dependencies project.c and test.o appear after the colon.
 The command Line usually appears on the following lines and
is preceded by a tab character.
How to Make a Simple Makefile
When this makefile is executed for the first time, we see:
$ make
gcc –o projet.o –c projet.c –Wall
gcc –o test.o –c test.c-Wall
gcc –o exec projet.o test.o
As you look at the makefile and sample execution, you may notice
the order in which commands are executed by make are nearly the
opposite to the order they occur in the Makefile..

Now we have an executable program 
How to Make a Simple Makefile
But How He did that  :
1. First make notices that the command line contains no targets so it decides to make
the default goal, Exec(Our Executable) .
2. It checks for dependencies and sees three: project.o main.o now considers how to
build projetc.o and main.o and sees a rule for it

3. Again, it checks the dependencies, notices that project.c has no rule but (that file
exists), so make executes the commands to transform project.c into project.o by
executing the command ! gcc –o projet.o –c projet.c –Wall
Makefile Rules
In the last section, we wrote some rules to compile and link our program.
Each of those rules defines a target, that is, a file to be updated. Each
target file depends on a set of dependencies, which are also files.
Since rules are so important in make, there are a number of different kinds
of rules. Explicit rules (This is the most common type of rule you will be
writing), and Implicit rules.
Makefile Rules
A makefile often contains long lists of files. To simplify this process make supports
wildcards (also known as globbing).

Wildcards can be very useful for creating more adaptable makefiles. For instance,
instead of listing all the files in a program explicitly, you can use wildcards define a
rule that applies to all files ending in the %.o and %.c suffix.
Automatic variables are set by make after a rule is matched. They provide access
to elements from the target and dependency (so you don’t have to explicitly
specify any filenames)
Variables (Constants) : some can be set by the user to control make’s behavior
while others are set by make to communicate with the user’s makefile.
Makefile Rules
Use WildCard:
%.o: %.c
gcc –o $@ –c $< –Wall
Explanation :
1.
2.
3.
4.

The .o files depends on the .c files.
To generate the .o file, we needs to compile the .c file.
$@ define the filename of the target.
$< define the filename of the first dependency.
Makefile Rules
Define Variables :
CC=gcc
WFLAGS=-Wall
OBJ=projet.o test.o
Exec: $(OBJ)
$(CC) –o $@ $^ $(WFLAGS)
%.o: %.c
$(CC) –o $@ –c $< $(WFLAGS)

Explanation :
 In this exemple we defined some variables CC,WFLAGS,OBJ.
 Variable name must be surrounded by $() or ${}.
 A single character variable name does not require the parentheses.
Makefile Rules
Automatic Variables:
 They provide access to elements from the target and prerequisite lists so
you don’t have to explicitly specify any filenames.
 They are very useful for avoiding code duplication.
Exec: $(OBJ)
$(CC) –o $@ $^ $(WFLAGS)
%.o: %.c
$(CC) –o $@ –c $< $(WFLAGS)

$@ The filename representing the target.
$< The filename of the first dependency.
$^ The filenames of all the dependencies.
Conclusion
Phony Target :
Simple Target to run Command line, Dont create files,most
phony targets do not have prerequisites.
Standard Phony Target :
 Make clean
 Make all
 Make install
.PHONY: clean
clean:
rm –f *.o
Conclusion
Remarks:
 Don’t forget about the TAB Before the
Command.
 Read Tutorials and practice with simple
Example.
 Send Message on Social Media  feel free to
Ask.
Introduction to Makefile
Introduction to Makefile

Mais conteúdo relacionado

Mais procurados

Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Thomas Petazzoni
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequenceHoucheng Lin
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device driversHoucheng Lin
 
Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Tushar B Kute
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device DriversNEEVEE Technologies
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)shimosawa
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedAnne Nicolas
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchlinuxlab_conf
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedureDhaval Kaneria
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingTushar B Kute
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKBshimosawa
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsQUONTRASOLUTIONS
 

Mais procurados (20)

Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)Device Tree for Dummies (ELC 2014)
Device Tree for Dummies (ELC 2014)
 
GCC, GNU compiler collection
GCC, GNU compiler collectionGCC, GNU compiler collection
GCC, GNU compiler collection
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Arm device tree and linux device drivers
Arm device tree and linux device driversArm device tree and linux device drivers
Arm device tree and linux device drivers
 
Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)Part 01 Linux Kernel Compilation (Ubuntu)
Part 01 Linux Kernel Compilation (Ubuntu)
 
Linux Booting Steps
Linux Booting StepsLinux Booting Steps
Linux Booting Steps
 
Introduction Linux Device Drivers
Introduction Linux Device DriversIntroduction Linux Device Drivers
Introduction Linux Device Drivers
 
Shell programming
Shell programmingShell programming
Shell programming
 
Linux Initialization Process (1)
Linux Initialization Process (1)Linux Initialization Process (1)
Linux Initialization Process (1)
 
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all startedKernel Recipes 2019 - ftrace: Where modifying a running kernel all started
Kernel Recipes 2019 - ftrace: Where modifying a running kernel all started
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
GCC LTO
GCC LTOGCC LTO
GCC LTO
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
Linux booting procedure
Linux booting procedureLinux booting procedure
Linux booting procedure
 
Part 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module ProgrammingPart 02 Linux Kernel Module Programming
Part 02 Linux Kernel Module Programming
 
Linux Kernel Module - For NLKB
Linux Kernel Module - For NLKBLinux Kernel Module - For NLKB
Linux Kernel Module - For NLKB
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
 

Semelhante a Introduction to Makefile

Makefile
MakefileMakefile
MakefileIonela
 
Carmen En
Carmen EnCarmen En
Carmen EnCarmen
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfThninh2
 
Software Build processes and Git
Software Build processes and GitSoftware Build processes and Git
Software Build processes and GitAlec Clews
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdfvino108206
 
ASP.NET Core and Docker
ASP.NET Core and DockerASP.NET Core and Docker
ASP.NET Core and DockerChuck Megivern
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
Leiningen2 - humane build management for clojure
Leiningen2 - humane build management for clojureLeiningen2 - humane build management for clojure
Leiningen2 - humane build management for clojureJohn Stevenson
 
.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQAvijit Shaw
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database DeploymentsMike Willbanks
 
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamMoving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamPVS-Studio
 
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamMoving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamSofia Fateeva
 
Lightning web components
Lightning web components Lightning web components
Lightning web components Cloud Analogy
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automakeniurui
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_netNico Ludwig
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsSu Zin Kyaw
 

Semelhante a Introduction to Makefile (20)

Makefile
MakefileMakefile
Makefile
 
Carmen En
Carmen EnCarmen En
Carmen En
 
Basic Make
Basic MakeBasic Make
Basic Make
 
LOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdfLOSS_C11- Programming Linux 20221006.pdf
LOSS_C11- Programming Linux 20221006.pdf
 
Linux intro 5 extra: makefiles
Linux intro 5 extra: makefilesLinux intro 5 extra: makefiles
Linux intro 5 extra: makefiles
 
Software Build processes and Git
Software Build processes and GitSoftware Build processes and Git
Software Build processes and Git
 
A05
A05A05
A05
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
ASP.NET Core and Docker
ASP.NET Core and DockerASP.NET Core and Docker
ASP.NET Core and Docker
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Leiningen2 - humane build management for clojure
Leiningen2 - humane build management for clojureLeiningen2 - humane build management for clojure
Leiningen2 - humane build management for clojure
 
.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ.NET,ASP .NET, Angular Js,LinQ
.NET,ASP .NET, Angular Js,LinQ
 
Linkers
LinkersLinkers
Linkers
 
Handling Database Deployments
Handling Database DeploymentsHandling Database Deployments
Handling Database Deployments
 
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamMoving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
 
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development teamMoving from CruiseControl.NET to Jenkins in the PVS-Studio development team
Moving from CruiseControl.NET to Jenkins in the PVS-Studio development team
 
Lightning web components
Lightning web components Lightning web components
Lightning web components
 
Autoconf&Automake
Autoconf&AutomakeAutoconf&Automake
Autoconf&Automake
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 

Último

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 

Último (20)

EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Introduction to Makefile

  • 1. Introduction To Makefile Makefile Tutorial EL KTAOUI ZAKARIA Email: : elktaoui@outlook.com Faecbook: https://www.facebook.com/Elktaoui.zakaria Linkedin: ma.linkedin.com/in/elktaoui/
  • 2. Table of Content  Introduction  Why Makefile ?  How does it work ?  How to Make a simple Makefile ?  Makefile Rules
  • 3. Sudo has a Make 
  • 4. Introduction The utility simply known as make is one of the most enduring features of both Unix and other operating systems. First invented in the 1970s, make still turns up to this day as the central engine in most programming projects; it even builds the Linux kernel.
  • 5. In this presentation you will learn why this utility continues to hold its top position in project build software, despite many younger competitors.
  • 6. Makefile Why ?  Make checks timestamps to see what has changed and rebuilds just what you need, without wasting time rebuilding other files.  Manage Several source files and compile them quickly with a single Command Line.  Make layers a rich collection of options that lets you manipulate multiple directories, build different versions of programs for different platforms, and customize your builds in other ways.
  • 7. Make Utility If you run make This will cause the make program to read the makefile and build the first target it finds there . If you have several makefiles, then you can execute them with the command: make -f mymakefile For more options use : $ man make
  • 8. How does it work ? Typically the default goal in most makefiles is to build a program. This usually involves many steps: 1. Generate the source code using some utilities like Flex & Bison. 2. Compile the source code into binary file (.o files c/c++/java etc .. 3. bound the Object files together using a linker( gcc/g++) to form an executable program(.exe)
  • 9. How does it work ? Makefile contains a set of rules used to build an application. The first rule (default rule) seen by make consists of three parts:  The Target.  The Dependencies.  The Command to be performed.
  • 10. Target and Dependencies Now let’s see the Make Process :  Make is asked to evaluate a rule, it begins by finding the files indicated by the dependencies and target.  If any of the dependencies has an associated rule, make attempts to update those first. Next, the target file is considered.  If any dependency is newer than the target, the target is remade by executing the commands.  If any dependency is newer than the target, the target is remade by executing the commands.
  • 11. How to Make a Simple Makefile Exec: projet.o test.o gcc –o exec projet.o test.o projet.o: projet.c gcc –o projet.o –c projet.c –Wall Test.o: test.c gcc –o main.o –c test.c -Wall
  • 12. How to Make a Simple Makefile  The target file Exec appears before the colon.  The dependencies project.c and test.o appear after the colon.  The command Line usually appears on the following lines and is preceded by a tab character.
  • 13. How to Make a Simple Makefile When this makefile is executed for the first time, we see: $ make gcc –o projet.o –c projet.c –Wall gcc –o test.o –c test.c-Wall gcc –o exec projet.o test.o As you look at the makefile and sample execution, you may notice the order in which commands are executed by make are nearly the opposite to the order they occur in the Makefile.. Now we have an executable program 
  • 14. How to Make a Simple Makefile But How He did that  : 1. First make notices that the command line contains no targets so it decides to make the default goal, Exec(Our Executable) . 2. It checks for dependencies and sees three: project.o main.o now considers how to build projetc.o and main.o and sees a rule for it 3. Again, it checks the dependencies, notices that project.c has no rule but (that file exists), so make executes the commands to transform project.c into project.o by executing the command ! gcc –o projet.o –c projet.c –Wall
  • 15. Makefile Rules In the last section, we wrote some rules to compile and link our program. Each of those rules defines a target, that is, a file to be updated. Each target file depends on a set of dependencies, which are also files. Since rules are so important in make, there are a number of different kinds of rules. Explicit rules (This is the most common type of rule you will be writing), and Implicit rules.
  • 16. Makefile Rules A makefile often contains long lists of files. To simplify this process make supports wildcards (also known as globbing). Wildcards can be very useful for creating more adaptable makefiles. For instance, instead of listing all the files in a program explicitly, you can use wildcards define a rule that applies to all files ending in the %.o and %.c suffix. Automatic variables are set by make after a rule is matched. They provide access to elements from the target and dependency (so you don’t have to explicitly specify any filenames) Variables (Constants) : some can be set by the user to control make’s behavior while others are set by make to communicate with the user’s makefile.
  • 17. Makefile Rules Use WildCard: %.o: %.c gcc –o $@ –c $< –Wall Explanation : 1. 2. 3. 4. The .o files depends on the .c files. To generate the .o file, we needs to compile the .c file. $@ define the filename of the target. $< define the filename of the first dependency.
  • 18. Makefile Rules Define Variables : CC=gcc WFLAGS=-Wall OBJ=projet.o test.o Exec: $(OBJ) $(CC) –o $@ $^ $(WFLAGS) %.o: %.c $(CC) –o $@ –c $< $(WFLAGS) Explanation :  In this exemple we defined some variables CC,WFLAGS,OBJ.  Variable name must be surrounded by $() or ${}.  A single character variable name does not require the parentheses.
  • 19. Makefile Rules Automatic Variables:  They provide access to elements from the target and prerequisite lists so you don’t have to explicitly specify any filenames.  They are very useful for avoiding code duplication. Exec: $(OBJ) $(CC) –o $@ $^ $(WFLAGS) %.o: %.c $(CC) –o $@ –c $< $(WFLAGS) $@ The filename representing the target. $< The filename of the first dependency. $^ The filenames of all the dependencies.
  • 20. Conclusion Phony Target : Simple Target to run Command line, Dont create files,most phony targets do not have prerequisites. Standard Phony Target :  Make clean  Make all  Make install .PHONY: clean clean: rm –f *.o
  • 21. Conclusion Remarks:  Don’t forget about the TAB Before the Command.  Read Tutorials and practice with simple Example.  Send Message on Social Media  feel free to Ask.