|
Lines 1146-1151
Link Here
|
| 1146 |
</sect2> |
1146 |
</sect2> |
| 1147 |
|
1147 |
|
| 1148 |
<sect2> |
1148 |
<sect2> |
|
|
1149 |
<title>Make and include-files</title> |
| 1150 |
|
| 1151 |
<para>C code often starts with a list of files to include, for |
| 1152 |
example stdio.h. Some of these files are system-include |
| 1153 |
files, some of them are from the project you're now working |
| 1154 |
on: |
| 1155 |
</para> |
| 1156 |
|
| 1157 |
<programlisting>#include <stdio.h> |
| 1158 |
#include "foo.h" |
| 1159 |
|
| 1160 |
int main(....</programlisting> |
| 1161 |
|
| 1162 |
<para>To make sure that this file is recompiled the moment |
| 1163 |
<filename>foo.h</filename> is changed, you have to add it in |
| 1164 |
your <filename>Makefile</filename>:</para> |
| 1165 |
|
| 1166 |
<programlisting>foo: foo.c foo.h</programlisting> |
| 1167 |
|
| 1168 |
<para>The moment your project is getting bigger and you have |
| 1169 |
more and more own include-files to maintain, it will be a |
| 1170 |
pain to keep track of all include files and the files which |
| 1171 |
are depending on it. If you change an include-file but |
| 1172 |
forget to recompile all the files which are depending on |
| 1173 |
it, the results will be devastating. <command>gcc</command> |
| 1174 |
has an option to analyze your files and to produce a list |
| 1175 |
of include-files and their dependencies: <option>-MM</option>. |
| 1176 |
</para> |
| 1177 |
|
| 1178 |
<para>If you add this to your Makefile:</para> |
| 1179 |
|
| 1180 |
<programlisting>depend: |
| 1181 |
gcc -E -MM *.c > .depend</programlisting> |
| 1182 |
|
| 1183 |
<para>and run <userinput>make depend</userinput>, the file |
| 1184 |
<filename>.depend</filename> will appear with a list of |
| 1185 |
object-files, C-files and the include-files:</para> |
| 1186 |
|
| 1187 |
<programlisting>foo.o: foo.c foo.h</programlisting> |
| 1188 |
|
| 1189 |
<para>If you change <filename>foo.h</filename>, next time |
| 1190 |
you run <command>make</command> all files depending on |
| 1191 |
<filename>foo.h</filename> will be recompiled.</para> |
| 1192 |
|
| 1193 |
<para>Don't forget to run <command>make depend</command> each |
| 1194 |
time you add an include-file to one of your files.</para> |
| 1195 |
</sect2> |
| 1196 |
|
| 1197 |
<sect2> |
| 1149 |
<title>FreeBSD Makefiles</title> |
1198 |
<title>FreeBSD Makefiles</title> |
| 1150 |
|
1199 |
|
| 1151 |
<para>Makefiles can be rather complicated to write. Fortunately, |
1200 |
<para>Makefiles can be rather complicated to write. Fortunately, |