I. Example
Four files: Main. C; Main. h; t_print.c; t_print.h
Makefile: Statement 1)
main:main.o t_print.ogcc main.o t_print.o -o main main.o:main.c main.hgcc -c main.ct_print.o:t_print.c t_print.hgcc -c t_print.cclean:rm main.o t_print.o
Run make or make main.
Delete intermediate files: Make clean
Statement 2)
main:main.o t_print.ogcc main.o t_print.o -o main main.o:main.c main.hgcc -c main.ct_print.o:t_print.c t_print.hgcc -c t_print.c
Run make or make main.
Statement 3)
main:main.o t_print.ogcc main.o t_print.o -o main
Run make or make main.
The make command automatically derives the files required for Main. O generation.
Statement 4)
object=main.o t_print.omain:$(object)gcc $(object) -o main clean:rm $(object)
Variables are used here, but the dependency is unclear.
[Note] the tab Space key is in front of GCC.
Ii. Make Execution Process
1) make finds the "makefile" or "makefile" file in the current directory.
2) if it is found, it will find the first target file in the file (target ). In the above example, main
3) if the execution of the main command depends on the file generated by the subsequent command execution, the following command is executed first.
4) when the file required by the main command is generated, run the main command.
Iii. Details
1) You can use other file names as makefiles, such as make. Linux.
Make-F make. Linux //-F file specifies the file
2) makefile can also contain other files, such
Makefile:
object=main.o t_print.omain:$(object)gcc $(object) -o main clean:rm $(object)include aa
AA:
cleanmain:rm main
Run: Make cleanmain to execute rm main
Note: When the make command starts, other files pointed out by include will be searched, and the content in the file will be placed in the current location.
3) Add "-" before a command in makefile to indicate that no error is reported and the execution continues regardless of the error.
-Rm main. O t_print.o // you can write it as a wildcard RM *. O.
----- The night is already deep ---- not yet resumed -----