class: center, middle ### COMP26020 Programming Languages and Paradigms Part 1: C Programming *** # Automated Compilation --- # Incremental Build ```bash # Initial build: $ gcc -c network.c -o network.o $ gcc -c parser.c -o parser.o $ gcc -c main.c -o main.o $ gcc main.o network.o parser.o -o prog ``` -- ```bash # Assume we update parser.c: to rebuild, we don't need to recompile everything: $ gcc -c parser.c -o parser.o $ gcc main.o network.o parser.o -o prog ``` -- ```bash # Now we update parser.h, remember it's included in both parser.c and main.c, so: $ gcc -c parser.c -o parser.o $ gcc -c main.c -o main.o $ gcc main.o network.o parser.o -o prog ``` -- - **How to automate dependency management and the build process itself?** --- class: inverse, middle, center # Makefiles: Automated Build and Dependency Management --- # Makefiles - Let's consider the dependencies in our example program
--- # Makefiles - Let's consider the dependencies in our example program
--- class: tightcode # Makefiles - Text file named `Makefile` in the source directory .leftcol[ ```makefile # default rule: all: prog # executable deps and command to build it: prog: main.o network.o parser.o gcc main.o network.o parser.o -o prog # network.o deps and command to build it: network.o: network.c network.h gcc -c network.c -o network.o parser.o: parser.c parser.h network.h gcc -c parser.c -o parser.o main.o: main.c network.h parser.h gcc -c main.c -o main.o # Rule to remove all build files clean: rm -rf *.o prog # ``` .codelink[
`17-automated-compilation/automated-compilation.zip`
] ] .rightcol[
Rule syntax: ```sh
:
[TAB]
``` ] --- class: tightcode # Makefiles ```xml $ make gcc -c main.c -o main.o gcc -c network.c -o network.o gcc -c parser.c -o parser.o gcc main.o network.o parser.o -o prog $ make make: Nothing to be done for 'all'. ``` ```xml $ touch network.c # simulate an edit of network.c $ make gcc -c network.c -o network.o gcc main.o network.o parser.o -o prog ``` ```xml $ touch parser.h # simulate an edit of parser.h $ make gcc -c main.c -o main.o gcc -c parser.c -o parser.o gcc main.o network.o parser.o -o prog ``` ```xml $ make clean rm -rf *.o prog ``` --- # Summary - C/C++ application build automation and dependency management with Makefiles ---- .center[Feedback form: https://bit.ly/37uMy09]