You are on page 1of 8

CSE 1201

Simple Makefile
ANIMESH KUMAR PAUL
ASSISTANT PROFESSOR
DEPT. OF CSE
Makefile General format
MAKE is driven by a make file, which contains a list of target
files, dependent files, and commands.
A target file requires its dependent files to produce it
❑ MAKE works by comparing the dates between a dependent file and its target file. (As used here,
the term ''date" includes both the calendar date and the time.)
❑If the target file has a date that is older than its dependent file (or if the target does not exist),
the specified command sequence is executed.
❑If that command sequence contains target files defined by other dependencies, then those
dependencies are also updated, as needed.
❑When the MAKE process is over, all target files have been updated.
❑Therefore, in a correctly constructed make file, all source files that require compilation are
automatically compiled and linked, forming the new executable file.
❑In this way, source files are kept in synchronization with object files.
•-o: specifies the output executable filename.
•-Wall: prints "all" warning messages.
•-g: generates additional symbolic debuggging information for use with gdb debugger.
• -c: compile into object file
•-I dir : Add the directory dir to the head of the list of directories to be searched for
header files. This can be used to override a system header file, substituting your own
version, since these directories are searched before the system header file directories.
However, you should not use this option to add directories that contain
vendor-supplied system header files (use -isystem for that). If you use more than one -I
option, the directories are scanned in left-to-right order; the standard system
directories come after.
•-I. is included so that gcc will look in the current directory (.) for the include header file.
Build Process
❑Compiler takes the source files and outputs object files
❑Linker takes the object files and creates an executable
To run makefile:
Here, it creates only .exe file mingw32-make all
Using dependencies
1st time to run makefile:
mingw32-make all
Output:

2nd time to run makefile:


mingw32-make all
Output:
Using variables and comments

dereference operator $

You might also like