Mecklenburg - Managing Projects with GNU Make 3e (O'Reilly, 2005).pdf

(3396 KB) Pobierz
607650042 UNPDF
607650042.076.png
Managing Projects with GNU Make, Third Edition
by Robert Mecklenburg
Copyright © 2005, 1991, 1986 O’Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles ( safari.oreilly.com ). For more information, contact our corporate/insti-
tutional sales department: (800) 998-9938 or corporate@oreilly.com .
Editor: Andy Oram
Production Editor: Matt Hutchinson
Production Services: Octal Publishing, Inc.
Cover Designer: Edie Freedman
Interior Designer: David Futato
Printing History:
1986: First Edition.
October 1991: Second Edition.
November 2004: Third Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Managing Projects with GNU Make , the image of a potto, and related trade dress
are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
Permission is granted to copy, distribute, and/or modify this document under the terms of the GNU
Free Documentation License, Version 1.1 or any later version published by the Free Software
Foundation. A copy of this license is included in Appendix C.
While every precaution has been taken in the preparation of this book, the publisher and author assume
no responsibility for errors or omissions, or for damages resulting from the use of the information
contained herein.
This book uses RepKover , a durable and flexible lay-flat binding.
ISBN: 0-596-00610-1
[M]
607650042.087.png 607650042.098.png 607650042.109.png 607650042.001.png 607650042.012.png 607650042.023.png 607650042.029.png 607650042.030.png 607650042.031.png 607650042.032.png 607650042.033.png 607650042.034.png 607650042.035.png 607650042.036.png 607650042.037.png 607650042.038.png 607650042.039.png 607650042.040.png 607650042.041.png 607650042.042.png 607650042.043.png 607650042.044.png 607650042.045.png 607650042.046.png 607650042.047.png 607650042.048.png 607650042.049.png 607650042.050.png 607650042.051.png 607650042.052.png
Table of Contents
Foreword
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xi
Preface
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii
Part I.
Basic Concepts
1. How to Write a Simple Makefile
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
Targets and Prerequisites
4
Dependency Checking
6
Minimizing Rebuilds
7
Invoking make
7
Basic Makefile Syntax
8
2. Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
Explicit Rules
10
Variables
16
Finding Files with VPATH and vpath
17
Pattern Rules
21
The Implicit Rules Database
25
Special Targets
30
Automatic Dependency Generation
31
Managing Libraries
34
3. Variables and Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
What Variables Are Used For
42
Variable Types
43
Macros
45
vii
607650042.053.png 607650042.054.png 607650042.055.png 607650042.056.png 607650042.057.png 607650042.058.png 607650042.059.png 607650042.060.png 607650042.061.png 607650042.062.png 607650042.063.png 607650042.064.png 607650042.065.png 607650042.066.png 607650042.067.png 607650042.068.png 607650042.069.png 607650042.070.png 607650042.071.png 607650042.072.png 607650042.073.png 607650042.074.png 607650042.075.png 607650042.077.png 607650042.078.png 607650042.079.png 607650042.080.png 607650042.081.png 607650042.082.png
When Variables Are Expanded
47
Target- and Pattern-Specific Variables
50
Where Variables Come From
51
Conditional and include Processing
54
Standard make Variables
57
4. Functions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
61
User-Defined Functions
61
Built-in Functions
64
Advanced User-Defined Functions
80
5. Commands
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
88
Parsing Commands
88
Which Shell to Use
96
Empty Commands
97
Command Environment
98
Evaluating Commands
99
Command-Line Limits
100
Part II.
Advanced and Specialized Topics
6. Managing Large Projects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
107
Recursive make
108
Nonrecursive make
117
Components of Large Systems
124
Filesystem Layout
126
Automating Builds and Testing
128
7. Portable Makefiles
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
129
Portability Issues
130
Cygwin
131
Managing Programs and Files
134
Working with Nonportable Tools
137
Automake
139
8. C and C++
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
141
Separating Source and Binary
141
Read-Only Source
149
Dependency Generation
149
viii
|
Table of Contents
607650042.083.png 607650042.084.png 607650042.085.png 607650042.086.png 607650042.088.png 607650042.089.png 607650042.090.png 607650042.091.png 607650042.092.png 607650042.093.png 607650042.094.png 607650042.095.png 607650042.096.png 607650042.097.png 607650042.099.png 607650042.100.png 607650042.101.png 607650042.102.png 607650042.103.png 607650042.104.png 607650042.105.png 607650042.106.png 607650042.107.png 607650042.108.png 607650042.110.png 607650042.111.png 607650042.112.png 607650042.113.png 607650042.114.png 607650042.115.png
Supporting Multiple Binary Trees
154
Partial Source Trees
156
Reference Builds, Libraries, and Installers
157
9. Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
159
Alternatives to make
160
A Generic Java Makefile
164
Compiling Java
168
Managing Jars
175
Reference Trees and Third-Party Jars
177
Enterprise JavaBeans
178
10. Improving the Performance of make
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
182
Benchmarking
182
Identifying and Handling Bottlenecks
186
Parallel make
190
Distributed make
194
11. Example Makefiles
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
196
The Book Makefile
196
The Linux Kernel Makefile
218
12. Debugging Makefiles
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
229
Debugging Features of make
229
Writing Code for Debugging
236
Common Error Messages
241
Part III. Appendixes
A. Running make
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
249
B. The Outer Limits
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
252
C. GNU Free Documentation License—GNU Project—Free Software
Foundation (FSF)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
263
Index
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
271
Table of Contents
|
ix
607650042.116.png 607650042.117.png 607650042.118.png 607650042.119.png 607650042.002.png 607650042.003.png 607650042.004.png 607650042.005.png 607650042.006.png 607650042.007.png 607650042.008.png 607650042.009.png 607650042.010.png 607650042.011.png 607650042.013.png 607650042.014.png 607650042.015.png 607650042.016.png 607650042.017.png 607650042.018.png 607650042.019.png 607650042.020.png 607650042.021.png 607650042.022.png 607650042.024.png 607650042.025.png 607650042.026.png 607650042.027.png 607650042.028.png
Zgłoś jeśli naruszono regulamin