Beruflich Dokumente
Kultur Dokumente
Prepared by: Shah Het. Prajapati Arjun. Rathod Jatin. Poshiya Ujas. 1 Shah Dipen.
Origin of Makefile
It was originally created by Stuart Feldman in 1977 at Bell Labs. In 2003 Dr. Feldman received the ACM Software System Award for the authoring of this widespread tool. Before Make's introduction, the Unix build system most commonly consisted of operating system dependent "make" and "install" shell scripts accompanying their program's source. Being able to combine the commands for the different targets into a single file and being able to abstract out dependency tracking and archive handling was an important step in the direction of modern build environments.
What is Makefile
A Makefile can be the collective memory of commands necessary to build or manage a software project. There are several flavours and variants of make.
A Makefile contains targets, dependencies,and commands. make is a simple and useful tool that compares the dependencies in the Makefile, with respect to the source file time stamps, executing the given commands to create an up-todate dependent.
Project structure
Project
:
contains 3 files sum.c, sum.h should be the file sum
Program main.c.,
sum.h
Executable
sum (exe)
main.o
sum.o
main.c
sum.h
sum.c
Make operation
Project Target We
recreated. This is required when the target file is older than one of its dependencies
In
specified, on our way up the tree. Consequently, more files may need to be recreated
If
Makefile Syntax
Rules: It refers to the collection of a target , possible dependencies and command to execute.
10
Targets
a filename
a variable There can be several targets on the same line if they depend on
Targets - continued
Another common target is clean
Developers supply it to clean up their source tree from temporary files, object modules, etc.
Dependencies
The list of dependencies can be:
Filenames
Other target names Variables
Separated by a space.
May be empty; means build always.
13
Dependencies - continue
Before the target is built: its checked whether it is up-to-date (in case of files) by
makefile
sum: main.o sum.o gcc o sum main.o sum.o main.o: main.c sum.h gcc c main.c
Rule
Rule
Rule
15
Target
Rule syntax
Dependencies
Rule
Tab!!!
Action(s)
16
Make operation
File sum main.o sum.o main.c sum.c sum.h Last Modified 10:03 09:56 09:35 10:45 09:14 08:39
17
Main.c
19
a.c
20
b.c
21
Makefile
22
execution
23
24
Must copy header files to the current directory. There must be only one main function in all files. Enter ./target_name to run. Do not use make -t after you make a change. Your c files can be in any folder.You only need to mention the paths.
25
Extensions to make.
make -C /home/proj2
-n to dry run the program.(changes will not come to effect) -d print debugging information. -f use file1 as a makefile.
Make -f file1
-i ignore errors while remaking a file. -k keep going till possible. -t consider file as up to date.
26
Shortcuts
We
can compress identical dependencies and use built-in macros to get another (shorter) equivalent makefile :
27
$@ name of target $? name of depended changed $< name of the first dependent $^ names of all dependents $+ replace all dependencies with
duplicates.
28
$(@D) The directory part of the file name of the target, with the trailing slash removed. If the value of $@ is dir/foo.o then $(@D) is dir. This value is . if $@ does not contain a slash. $(@F) The file-within-directory part of the file name of the target. If the value of $@ is dir/foo.o then $(@F) is foo.o. $(@F) is equivalent to $(notdir $@) $(<D) $(<F) The directory part and the file-within-directory part of the first prerequisite.
29
$(^D) $(^F) Lists of the directory parts and the file-within-directory parts of all prerequisites. $(+D) $(+F) Lists of the directory parts and the file-within-directory parts of all prerequisites, including multiple instances of duplicated prerequisites. $(?D) $(?F) Lists of the directory parts and the file-within-directory parts of all prerequisites that are newer than the target.
30
31
Any questions???
32