A simple example on using make

  • Write a Makefile to automate the compilation of the Hello.c program:

     #include <stdio.h>
    
     int main( int argc, char* argv[] )
     {
         printf( "Hello World !\n" );
     } 

  • The final executable program is named hello

A simple example on using make

  • The chain of file dependencies, starting from the target hello:

      hello    depends on:             hello.o
               constructed using:      gcc -o hello hello.o
                
      hello.o  depends on:             hello.c
               constructed using:      gcc -c hello.c 

  • How to specify these dependencies in a Makefile:

    hello: hello.o 
    	gcc -o hello hello.o
    
    hello.o: hello.c           
    	gcc -c hello.c    

A simple example on using make

  • The chain of file dependencies, starting from the target hello:

      hello    depends on:             hello.o
               constructed using:      gcc -o hello hello.o
                
      hello.o  depends on:             hello.c
               constructed using:      gcc -c hello.c 

  • How to specify these dependencies in a Makefile:

    hello: hello.o 
    	gcc -o hello hello.o
    
    hello.o: hello.c           
    	gcc -c hello.c    

A simple example on using make

  • The chain of file dependencies, starting from the target hello:

      hello    depends on:             hello.o
               constructed using:      gcc -o hello hello.o
                
      hello.o  depends on:             hello.c
               constructed using:      gcc -c hello.c 

  • How to specify these dependencies in a Makefile:

    hello: hello.o 
    	gcc -o hello hello.o  # This line starts with a <TAB>
    
    hello.o: hello.c           
    	gcc -c hello.c    

A simple example on using make

  • The chain of file dependencies, starting from the target hello:

      hello    depends on:             hello.o
               constructed using:      gcc -o hello hello.o
                
      hello.o  depends on:             hello.c
               constructed using:      gcc -c hello.c 

  • How to specify these dependencies in a Makefile:

    hello: hello.o 
    	gcc -o hello hello.o
    
    hello.o: hello.c           
    	gcc -c hello.c    

A simple example on using make

  • The chain of file dependencies, starting from the target hello:

      hello    depends on:             hello.o
               constructed using:      gcc -o hello hello.o
                
      hello.o  depends on:             hello.c
               constructed using:      gcc -c hello.c 

  • How to specify these dependencies in a Makefile:

    hello: hello.o 
    	gcc -o hello hello.o
    
    hello.o: hello.c           
    	gcc -c hello.c    # This line starts with a <TAB> 

DEMO: demo/C/Make/1
(1) Type make again after completion. (2) Edit hello.c and re-compile !!!