0% found this document useful (0 votes)
8 views8 pages

06 BasicMake

Make is a Unix tool designed to streamline the compilation of large software projects through a Makefile that specifies file dependencies and commands for recompilation. It operates by checking if targets are up to date with their prerequisites and executes commands accordingly. Additionally, Makefiles can include commands for cleaning up project files, enhancing project management efficiency.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

06 BasicMake

Make is a Unix tool designed to streamline the compilation of large software projects through a Makefile that specifies file dependencies and commands for recompilation. It operates by checking if targets are up to date with their prerequisites and executes commands accordingly. Additionally, Makefiles can include commands for cleaning up project files, enhancing project management efficiency.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is “make”?

• make is a Unix tool that simplifies the task of


compiling large and complex software projects

– the programmer creates a Makefile that speficies:


• which files depend on which other files
• what commands to run when a file changes and needs to be
(re)compiled
– make reads Makefile and runs commands as necessary
• not such a big deal for small single-source-file programs
• very helpful when a large number of files involved
• can be used for many tasks that involve running some commands
on files that have changed

1
Example

Makefile What it means


mayan : mayan.c 1. The file mayan is built from
gcc –Wall mayan.c –o mayan
the file mayan.c
2. To build mayan from mayan.c,
execute this command

2
Makefile structure: rules

“target”
Makefile
mayan : mayan.c file(s) the target depends on ( ≥ 0 )
gcc –Wall mayan.c –o mayan (“prerequisites”)
if any of these files is changed, the
target must be recompiled.

“rule”
command(s) to execute if target is out
of date w.r.t. the files it depends on

a command line must start with a tab

3
How make works

Makefile Simplified Behavior of make


target : prerequisite1 … prerequisiten 1. if target does not exist:
command – run command
2. else: if target is older than any
of its prerequisites:
– run command
3. else: /* (target is up to date) */
– do nothing

4
Example

5
Multiple Targets

Makefile Which target gets “made”


target1 : prerequisite1 … prerequisiten 1. You can specify the target:
command1 make target2
2. If you don’t specify a target, the
target2 : prerequisite1 … prerequisitem first target is used.
command2

6
What can commands be?

Makefile
target : prerequisite1 … prerequisiten 1. The command doesn't have to be
ls -l gcc, it can be any Unix command.
2. Here there is a rather silly
Makefile that runs ls -l when
target doesn't exist or has date
older than a prerequisite
3. Notice ls doesn't update target.
What happens then if make is run
twice in a row?

7
clean

Makefile
isFib: isFib.c 1. Often a makefile will include a
gcc -Wall -o isFib isFib.c "clean" object to remove files
associated with the project
clean: 2. Here typing make clean will cause
rm -f isFib the executable to be deleted.
3. Notice that if there is no file
named "clean" in the current
directory, the rm command will
run everytime you type
make clean

You might also like