File: fastdep.docbook

package info (click to toggle)
fastdep 0.16-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 596 kB
  • ctags: 323
  • sloc: cpp: 2,144; ansic: 814; sh: 208; makefile: 124
file content (343 lines) | stat: -rw-r--r-- 9,820 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE book PUBLIC	'-//OASIS//DTD DocBook XML V4.1.2//EN'
								'http://docbook.org/docbook/xml/1.4/db3xml.dtd'>
<book id="fastdep-manual" lang="en">

<title>fastdep manual</title>

<bookinfo>
   <authorgroup>
		<author>
			<firstname>Bart</firstname>
			<surname>
				Vanhauwaert
			</surname>
			<affiliation>
				<address>
					<email>bvh-cplusplus@irule.be</email>
					<otheraddr>
						<ulink url="http://www.irule.be/bvh/">
							http://www.irule.be/bvh/
						</ulink>
					</otheraddr>
				</address>
			</affiliation>
		</author>
	</authorgroup>
	<revhistory>
		<revision>
			<revnumber>1</revnumber>
			<date>2002-10-28</date>
			<authorinitials>bvh</authorinitials>
			<revremark>Initial version</revremark>
		</revision>
	</revhistory>

	<legalnotice>
		<para>This document can be freely translated and distributed. 
		It is releasedunder the LDP License.</para>
	</legalnotice>

	<releaseinfo>
		I am not a native English speaker, nor an experienced
		documentation writer.
		Thus it should not come as a surprise to you if this text contains
		typographical,
		grammatical or even simple spelling errors. To overcome this
		problem I am
		actively looking for help, suggestions or improvements to this document
		from my readers. If you are willing to do so, send email to
		<ulink url="mailto:bvh-cplusplus@irule.be">bvh-cplusplus@irule.be</ulink>
		to make this guide a great resource
		for everyone trying to learn fastdep.
	</releaseinfo>
</bookinfo>

<chapter>
<title>About fastdep and this manual</title>

<para>
Fastdep generates dependency information for C of C++ files suitable
for inclusion in makefiles. There are two main advantages in using
it instead of the normal programs.</para>

<itemizedlist>
	<listitem>
		<para>It's fast due to a unique parse-once technology.</para>
	</listitem>
	<listitem>
		<para>It has special provision for robust dependency regeneration.</para>
	</listitem>
</itemizedlist>

<para>This manual assumes basic knowledge of make and the build process
for C or C++ programs.</para>

<para>
	I am not a native English speaker, nor an experienced
documentation writer.
Thus it should not come as a surprise to you if this text contains
typographical,
grammatical or even simple spelling errors. To overcome this
problem I am
actively looking for help, suggestions or improvements to this document
from my readers. If you are willing to do so, send email to
<ulink url="mailto:bvh-cplusplus@irule.be">bvh-cplusplus@irule.be</ulink>
to make this guide a great resource
for everyone trying to learn fastdep.
</para>

</chapter>

<chapter>
<title>Basic usage</title>

<para>The commandline synopsis for basic usage is</para>

<cmdsynopsis>
	<command>fastdep</command>
	<arg>--version</arg>
	<arg rep="repeat" choice="plain"><replaceable>sourcefile</replaceable></arg>
</cmdsynopsis>

<para><command>fastdep --version</command> will show version information
and a short copyright statement and exit immediatly.</para>

<para>To produce dependency information for two files
	named file1.cc and file2.cc, execute 
	<command>fastdep file1.cc file2.cc</command> from the shell.</para>

<para>The result will be written to standard output. For example 
it could be</para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h
</screen>

<para>To save the output, use your shell to redirect standard output 
	to a file which you can include in a makefile.
	</para>

</chapter>


<chapter>
<title>Writing a make-rule to generate dependency information</title>

<para>In general it is much more convenient to let your makefiles
	generate their own dependency information instead of doing it by hand
	as described in the previous chapter.</para>
	
<para>Let's say we have a variable in our makefile that lists all
	source files, <varname>SOURCES</varname>. We also want
	to save dependency information to a file named <filename>.depend</filename>.
	Here is how to write a make rule to accomplish just that.
</para>

<example>
	<title>Makefile fragment to generate dependencies from
		a number of sources</title>
	<programlisting>
.depend:
	fastdep $(SOURCES) > .depend

-include .depend
	</programlisting>
</example>

<para>It adds a new target <filename>.depend</filename>, 
	which is file to hold the dependency information generated by fastdep
	for all files listed in <varname>SOURCES</varname>. The fragment
also includes this file in the Makefile itself when it exist. If not
make will generate it first (using the rule
we specified), restart itself and include it next.</para>

<para>Now each time we want to regenerate dependencies, all we
	have to do is delete the <filename>.depend</filename> file and launch
	make.</para>

</chapter>


<chapter>
	<title>Automatically regenerating dependency information</title>

	<para>
Every time you change a dependency relationship (for example when
you include an extra header in some source file), you have to regenerate
the dependency information manually by executing
<command>make .depend</command>
(as mentioned in the previous chapter deleting <filename>.depend</filename>
also works)</para>

<para>Off course this is very error-prone. Why don't we let make regenerate
	the dependencies everytime one of the source files changes? Easy
	enough :</para>

<example>
	<title>Makefile fragment to generate dependencies each time a source
		file changes (wrong).</title>
<programlisting>
.depend: $(SOURCES)
	fastdep $(SOURCES) > .depend

-include .depend
</programlisting>
</example>

<para>This seems to work fine, but in fact doesn't. Suppose
	one (or more) of our source files in <varname>SOURCES</varname>
	includes a certain header <filename>foo.h</filename>. Now imagine
	that during an edit-compile cycle we don't change
	anything in the source files, but we added a new include
	of <filename>bar.h</filename> in <filename>foo.h</filename>.
	This means that the dependencies for each source file that
	includes <filename>foo.h</filename> must change. However since
	none of the source files themself change, make will find
	that <filename>.depend</filename> is still up to date
	and not regenerate it.
	The end result is incorrect dependency information.</para>

<para>To summarize, the dependency information of a source file
	not only depends on the source file itself, but also on all
	files it includes. Hence the earlier makefile fragment is
	incorrect.</para>

<para>To solve this problem, the info manual of GNU make proposes
	a solution where the output of the dependency generator is
	modified by piping it through sed. While this works for
	normal dependency generators like the GNU C/C++ compiler
	(and still works with fastdep), there is a much more elegant
	solution in <application>fastdep</application>.
	By adding the <command>--remakedeptarget=file</command>
	command line option fastdep will also emit a suitable
	dependency line for its own output.</para>

<example>
	<title>Makefile fragment to generate dependencies each time a source
		or included file changes (right).</title>
<programlisting>
.depend:
	fastdep --remakedeptarget=.depend $(ALLSOURCES) > .depend

-include dependinfo
</programlisting>
</example>
		
<para>The <filename>.depend</filename> file will now look like this : </para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h \
.depend: \
	file1.cc \
	header1.h \
	header2.h \
	header3.h \
	file2.cc \
	header4.h \
</screen>

<para>which is exactly how we want it to be.</para>
</chapter>

<chapter>
	<title>Adding an external dependency</title>

	<para>
Suppose you change your Makefile. For example you add -O2 to the CFLAGS
variable, because finally it's release time. Of course all object files
have to be regenerated. The classical way to do that is</para>

<screen>
make clean
make
</screen>

<para>But isn't it easier to let all .o files depend on the Makefile itself? 
	So that once you touch the makefile, all objects are immediatly out of
	date and thus regenerated.
	That's what the --extraremakedep= option is for.</para>

<example>
	<title>Adding an extra dependency to all targets</title>
<programlisting>
.depend:
	fastdep --extraremakedep=Makefile \
			  --remakedeptarget=.depend $(SOURCES) > .depend

-include .depend
</programlisting>
</example>

<para>Here is a possible result</para>

<screen>
file1.o: file1.cc \
	header1.h \
	header2.h \
	header3.h
file2.o: file2.cc \
	header1.h \
	header3.h \
	header4.h \
.depend: \
	file1.cc \
	header1.h \
	header2.h \
	header3.h \
	file2.cc \
	header4.h \
	Makefile
</screen>

</chapter>

<chapter>
	<title>Links and references</title>

	<variablelist>
		<varlistentry>
			<term>fastdep</term>
			<listitem><para>Homepage (news and download) : 
					<ulink url="http://www.irule.be/bvh/c++/fastdep/">http://www.irule.be/bvh/c++/fastdep/</ulink>
				</para>
			</listitem>
		</varlistentry>
		<varlistentry>
			<term>GNU compiler collection (gcc)</term>
			<listitem>
				<para>Homepage : 
					<ulink url="http://www.gnu.org/software/gcc/gcc.html">http://www.gnu.org/software/gcc/gcc.html</ulink></para>
				<para>Manual : 
					<ulink url="http://www.gnu.org/software/gcc/onlinedocs/">http://www.gnu.org/software/gcc/onlinedocs/</ulink>
				</para>
			</listitem>
		</varlistentry>
		<varlistentry>
			<term>GNU make</term>
			<listitem>
				<para>Homepage : 
					<ulink url="http://www.gnu.org/software/make/make.html">http://www.gnu.org/software/make/make.html</ulink></para>
				<para>Manual : 
					<ulink url="http://www.gnu.org/manual/make/html_chapter/make_toc.html">http://www.gnu.org/manual/make/html_chapter/make_toc.html</ulink>
				</para>
			</listitem>
		</varlistentry>
</variablelist>

</chapter>
</book>