cs:makefile_1
Return to Home page
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/makefile_1?do=diff&rev=1469656923&difftype=sidebyside
Differences
This shows you the differences between two versions of the page.
— | cs:makefile_1 [2024/04/08 22:35] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Makefile 1 ====== | ||
+ | **Concepts: | ||
+ | How to write a simple '' | ||
+ | |||
+ | **Text:**\\ | ||
+ | In the directory '' | ||
+ | <file C src/ | ||
+ | #include " | ||
+ | |||
+ | int mul(int a, int b){ | ||
+ | |||
+ | return a*b; | ||
+ | } | ||
+ | </ | ||
+ | In the directory '' | ||
+ | <file C inc/ | ||
+ | #ifndef _FZ_H | ||
+ | #define _FZ_H | ||
+ | |||
+ | int mul(int a, int b); | ||
+ | |||
+ | #endif | ||
+ | </ | ||
+ | Finally, the '' | ||
+ | <file C main.c> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include " | ||
+ | |||
+ | int main(){ | ||
+ | |||
+ | printf(" | ||
+ | |||
+ | return EXIT_SUCCESS; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Build a '' | ||
+ | * obtain an executable program with name '' | ||
+ | * have a target '' | ||
+ | * have a target '' | ||
+ | * have a target '' | ||
+ | |||
+ | |||
+ | **Example: | ||
+ | All files are compiled and the //linker// generates the executable '' | ||
+ | <code bash> | ||
+ | $ make | ||
+ | gcc -Wall -I inc -g -c main.c | ||
+ | gcc -Wall -I inc -g -c src/fz.c | ||
+ | gcc -o prog main.o fz.o | ||
+ | </ | ||
+ | Modifying one file, for example '' | ||
+ | <code bash> | ||
+ | $ touch src/fz.c | ||
+ | $ make | ||
+ | gcc -Wall -I inc -g -c src/fz.c | ||
+ | gcc -o prog main.o fz.o | ||
+ | </ | ||
+ | With '' | ||
+ | <code bash> | ||
+ | $ make clean | ||
+ | rm -f main.o fz.o | ||
+ | rm -f prog | ||
+ | </ | ||
+ | With '' | ||
+ | <code bash> | ||
+ | $ make install | ||
+ | gcc -Wall -I inc -g -c main.c | ||
+ | gcc -Wall -I inc -g -c src/fz.c | ||
+ | gcc -o prog main.o fz.o | ||
+ | mkdir -p bin | ||
+ | cp prog bin | ||
+ | </ | ||
+ | With '' | ||
+ | <code bash> | ||
+ | $ make distclean | ||
+ | rm -f main.o fz.o | ||
+ | rm -f prog | ||
+ | rm -fr bin | ||
+ | </ | ||
+ | |||
+ | **Solution: | ||
+ | <file make Makefile> | ||
+ | target: main.o fz.o | ||
+ | gcc -o prog main.o fz.o | ||
+ | |||
+ | main.o: main.c inc/fz.h | ||
+ | gcc -Wall -I inc -g -c main.c | ||
+ | |||
+ | fz.o: src/fz.c inc/fz.h | ||
+ | gcc -Wall -I inc -g -c src/fz.c | ||
+ | |||
+ | clean: | ||
+ | rm -f main.o fz.o | ||
+ | rm -f prog | ||
+ | |||
+ | install: target | ||
+ | mkdir -p bin | ||
+ | cp prog bin | ||
+ | |||
+ | distclean: clean | ||
+ | rm -fr bin | ||
+ | </ | ||
+ | |||
+ | DOWNLOAD COMPLETE EXAMPLE: [[http:// | ||
+ | |||
+ | **Comments: | ||
If you found any error, or if you want to partecipate to the editing of this wiki, please contact: admin [at] skenz.it
You can reuse, distribute or modify the content of this page, but you must cite in any document (or webpage) this url: https://www.skenz.it/cs/makefile_1?do=diff&rev=1469656923&difftype=sidebyside