]> Pileus Git - ~andy/sfvlug/blob - cc/cc.tex
Update C Compiling presentation.
[~andy/sfvlug] / cc / cc.tex
1 \documentclass[13pt,aspectratio=169]{beamer}
2
3 %%%%%%%%%%%%%%%%%%%
4 % Commands/macros %
5 %%%%%%%%%%%%%%%%%%%
6 \newcommand{\link}[1]{
7   \begin{flushright}
8     \scriptsize{#1}
9   \end{flushright}
10 }
11
12 \newcommand{\header}[1]{
13   \hspace{-1em}\textit{#1:}
14 }
15
16 \newcommand{\sheader}[1]{
17   \vspace{1.5em}
18   \header{#1}
19 }
20
21 \newcommand{\screen}[1]{
22   \setlength{\leftmargin}{0pt}
23   \setlength{\rightmargin}{0pt}
24   \begin{center}
25     \includegraphics[height=3.0in,width=4.25in,keepaspectratio]{#1}
26   \end{center}
27 }
28
29 %%%%%%%%%%%%%%%%
30 % Header/theme %
31 %%%%%%%%%%%%%%%%
32 %\usetheme[
33 %  pageofpages=of,
34 %  alternativetitlepage=true,
35 %]{Torino}
36 \setbeamertemplate{navigation symbols}{}
37 \setbeamertemplate{footline}{}
38 \setbeamersize{text margin left=20mm}
39 \setbeamersize{text margin right=10mm}
40 \setbeamerfont{frametitle}{size={\fontsize{15}{16}}}
41
42 % Import packages
43 \usepackage[english]{babel}
44 \usepackage[latin1]{inputenc}
45 \usepackage{times}
46 \usepackage[T1]{fontenc}
47 \usepackage{graphics}
48 \usepackage{hyperref}
49 \usepackage{ulem}
50 \usepackage{listings}
51
52 %%%%%%%%%%%%%%%%%%%%
53 % Title page setup %
54 %%%%%%%%%%%%%%%%%%%%
55 \subject{%
56   c,
57   compile,
58   unix,
59 }
60
61 \keywords{%
62   c,
63   cc
64   make,
65   autotools,
66 }
67
68 \title[C Compiling]{%
69   C Compiling and More!
70 }
71
72 \author[Spencer]{%
73   Andy Spencer
74 }
75
76 \date[2018-12-15]{%
77   December 15, 2018 \\
78   \small{San Fernando Valley Linux Users Group}
79 }
80
81 %%%%%%%%%%%%%%%%%
82 % Content pages %
83 %%%%%%%%%%%%%%%%%
84
85 \begin{document}
86
87 %%%%%%%%%%%%%%%%
88 % Introduction %
89 %%%%%%%%%%%%%%%%
90
91 \begin{frame}[plain]
92   \titlepage
93 \end{frame}
94
95 %%%%%%%%%%
96 % Why C? %
97 %%%%%%%%%%
98
99 \section{Why C?}
100
101 \begin{frame}
102   Why C
103 \end{frame}
104
105 %%%%%%%%%%%%%%%%%%%%%
106 % Compiled software %
107 %%%%%%%%%%%%%%%%%%%%%
108 % - compilers vs interpreters
109 % - C compile steps (cpp, cc, as, ld)
110 % - executable formats (ELF)
111 % - dynamic and static linking
112
113 \section{Compiled software}
114
115 \begin{frame}{Compilers vs Interpreters}
116   \structure{Interpreters}
117   \begin{itemize}
118     \item Bash, Python, Ruby
119     \item Interpreter runs and follows the instructions
120     \item The interpreter is generally compiled
121     \item Advantages: advanced languages, lot of features, easy development
122   \end{itemize}
123
124   \structure{Compilers}
125   \begin{itemize}
126     \item C/C++, Fortran, Haskell, Rust, (GCC / LLVM)
127     \item Translates one language to another
128     \item Often self compiling (needs bootstrapping)
129     \item Advantages: fast, deterministic, more static analysis
130   \end{itemize}
131 \end{frame}
132
133 \begin{frame}{C compiling steps}
134   \begin{itemize}
135     \item[cpp] C Pre-Processor
136       \begin{itemize}
137         \item Text based macros (\#include, \#define)
138       \end{itemize}
139
140     \item[cc] C Compiler
141       \begin{itemize}
142         \item Translates C to Assembly
143         \item Register allocation
144         \item Memory layout (structs/unions)
145         \item Function calling conventions
146       \end{itemize}
147
148     \item[as] Assembler
149       \begin{itemize}
150         \item Translates Assembly to object code
151         \item Handles labels, addresses, and mnemonics
152       \end{itemize}
153
154     \item[ld] Linker
155       \begin{itemize}
156         \item Combines object files
157         \item Resolves symbols and relocations
158       \end{itemize}
159
160   \end{itemize}
161 \end{frame}
162
163 \begin{frame}{Executable formats}
164   \begin{itemize}
165     \item[ELF] Executable and linking formats (Linux)
166     \item[COFF] Common Object File Format (Unix)
167     \item[PE] Portable Executable (Windows, EFI)
168     \item[Mach-O] Mach Object (Mac OSX)
169   \end{itemize}
170
171   \textit{There are also DWARFs... \\
172           "Debugging With Attributed Record Formats"}
173 \end{frame}
174
175 \begin{frame}{Executable formats}
176   \screen{elf.pdf}
177 \end{frame}
178
179 \begin{frame}{Dynamic vs static}
180   \begin{itemize}
181     \item Static linking
182     \item Dynamic linking
183     \item Modules
184     \item System calls
185   \end{itemize}
186 \end{frame}
187
188 %%%%%%%%%%%%%%%%%
189 % Build systems %
190 %%%%%%%%%%%%%%%%%
191
192 \section{Build systems}
193
194 \begin{frame}{C is for CC}
195   \structure{Running CC manually}
196   \begin{itemize}
197     \item Compiling manually...
198     \item Works for very small program.
199     \item cc hello.c
200     \item gcc -Wall -o hello hello.c
201   \end{itemize}
202
203   \structure{Scripting}
204   \begin{itemize}
205     \item Why not just write a script for this?
206     \item Dependency tracking, parallel execution.
207   \end{itemize}
208 \end{frame}
209
210 \begin{frame}{Make}
211   \begin{itemize}
212     \item Generic dependency tracker.
213     \item Except GNU Make, which has tons of dumb rules.
214     \item Configured with -DOPTION or config.mk
215   \end{itemize}
216 \end{frame}
217
218 \begin{frame}{autotools}
219   \structure{Overview}
220   \begin{itemize}
221     \item Designed to be "portable".
222     \item Good support for configuration.
223     \item Handles all the weird corner cases.
224     \item Nobody likes it but everybody uses it.
225   \end{itemize}
226   \structure{Usage}
227   \begin{itemize}
228     \item {[./autogen.sh]}
229     \item ./configure --help
230     \item make
231     \item make install
232   \end{itemize}
233 \end{frame}
234
235 \begin{frame}{kconfig}
236   \begin{itemize}
237     \item Started out in the Linux kernel.
238     \item Even better support for configuration.
239     \item Provides nice menu interfaces.
240   \end{itemize}
241 \end{frame}
242
243 \begin{frame}{others}
244   \begin{itemize}
245     \item cmake
246     \item scons
247     \item bazel
248     \item ant
249     \item maven
250     \item gradle
251   \end{itemize}
252 \end{frame}
253
254 \end{document}