How Do You Create Makefile in Linux Environment?

Asked By 10 points N/A Posted on -
qa-featured

We can use makefile in Windows and Linux operating system environments. I would like to know how I can start creating makefiles in Linux operating system. Is the process for creating makefile in Windows similar to how to create it in Linux? Please help me with some useful guidelines. Thank you.

 

SHARE
Answered By 0 points N/A #190636

How Do You Create Makefile in Linux Environment?

qa-featured
HELLO
 
Writing of the Make file
 
First, All variable names should in upper-case for Make file.
In Make file the common variable assignment is cc=gcc. Which can be used as ${cc} or $(cc).
# is a comment-start marker is used in Make file.
The simple syntax of Make file generally used like this:
Target: dependency 1 dependency 2  dependency 3…….
[TAB] action 1
[TAB] action 2
[TAB] action 3
    …
This is the example for the make file:
 
All: main.o module.o
    Gcc main.o module.o -o target_bin
Main.o: main.c module.h
    gcc -I . -c main.c
Module.o: module.c module.h
    gcc -I . -c module.c
Clean:
    rm -rf *.o
    rm target_bin
 
Where 'all' is special target which is depend on the main.o and module. o to make the two object files at the final executable.
'main.o' is a target of file name and 'main.o' is depends on 'main.c' and module.h' and that can compiles 'main.c' to develop 'main.o'.
'module.o is a target file name that depends on 'module.h' and 'module.c'. It will going to call GCC compile for 'module.c' file to produce the 'module.o'.
Clean is the  special kind of target. It does not have dependencies. But this command is used for clean the compilation results from the project directories.
This command is used to except the target parameter. So that the simplest command is used make<target>. Make is also work if you do not specify any target at the command line.

Login/Register to Answer

Related Questions