O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Managing Projects with GNU Make, 3rd Edition

Book Description

The utility simply known as make is one of the most enduring features of both Unix and other operating systems. First invented in the 1970s, make still turns up to this day as the central engine in most programming projects; it even builds the Linux kernel. In the third edition of the classic Managing Projects with GNU make, readers will learn why this utility continues to hold its top position in project build software, despite many younger competitors. The premise behind make is simple: after you change source files and want to rebuild your program or other output files, make checks timestamps to see what has changed and rebuilds just what you need, without wasting time rebuilding other files. But on top of this simple principle, make layers a rich collection of options that lets you manipulate multiple directories, build different versions of programs for different platforms, and customize your builds in other ways. This edition focuses on the GNU version of make, which has deservedly become the industry standard. GNU make contains powerful extensions that are explored in this book. It is also popular because it is free software and provides a version for almost every platform, including a version for Microsoft Windows as part of the free Cygwin project. Managing Projects with GNU make, 3rd Edition provides guidelines on meeting the needs of large, modern projects. Also added are a number of interesting advanced topics such as portability, parallelism, and use with Java. Robert Mecklenburg, author of the third edition, has used make for decades with a variety of platforms and languages. In this book he zealously lays forth how to get your builds to be as efficient as possible, reduce maintenance, avoid errors, and thoroughly understand what make is doing. Chapters on C++ and Java provide makefile entries optimized for projects in those languages. The author even includes a discussion of the makefile used to build the book.

Table of Contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Other resources from O’Reilly
  4. Foreword
  5. Preface
    1. The Road to the Third Edition
    2. What’s New in This Edition
    3. Conventions Used in This Book
    4. Using Code Examples
    5. Comments and Questions
    6. Acknowledgments
  6. I. Basic Concepts
    1. 1. How to Write a Simple Makefile
      1. Targets and Prerequisites
      2. Dependency Checking
      3. Minimizing Rebuilds
      4. Invoking make
      5. Basic Makefile Syntax
    2. 2. Rules
      1. Explicit Rules
        1. Wildcards
        2. Phony Targets
        3. Empty Targets
      2. Variables
        1. Automatic Variables
      3. Finding Files with VPATH and vpath
      4. Pattern Rules
        1. The Patterns
        2. Static Pattern Rules
        3. Suffix Rules
      5. The Implicit Rules Database
        1. Working with Implicit Rules
        2. Rule Structure
        3. Implicit Rules for Source Control
        4. A Simple Help Command
      6. Special Targets
      7. Automatic Dependency Generation
      8. Managing Libraries
        1. Creating and Updating Libraries
        2. Using Libraries as Prerequisites
        3. Double-Colon Rules
    3. 3. Variables and Macros
      1. What Variables Are Used For
      2. Variable Types
        1. Other Types of Assignment
      3. Macros
      4. When Variables Are Expanded
      5. Target- and Pattern-Specific Variables
      6. Where Variables Come From
      7. Conditional and include Processing
        1. The include Directive
        2. include and Dependencies
      8. Standard make Variables
    4. 4. Functions
      1. User-Defined Functions
      2. Built-in Functions
        1. String Functions
        2. Important Miscellaneous Functions
        3. Filename Functions
        4. Flow Control
          1. Style note concerning variables and parentheses
        5. Less Important Miscellaneous Functions
      3. Advanced User-Defined Functions
        1. eval and value
        2. Hooking Functions
        3. Passing Parameters
    5. 5. Commands
      1. Parsing Commands
        1. Continuing Long Commands
        2. Command Modifiers
        3. Errors and Interrupts
          1. Deleting and preserving target files
      2. Which Shell to Use
      3. Empty Commands
      4. Command Environment
      5. Evaluating Commands
      6. Command-Line Limits
  7. II. Advanced and Specialized Topics
    1. 6. Managing Large Projects
      1. Recursive make
        1. Command-Line Options
        2. Passing Variables
        3. Error Handling
        4. Building Other Targets
        5. Cross-Makefile Dependencies
        6. Avoiding Duplicate Code
      2. Nonrecursive make
      3. Components of Large Systems
        1. Requirements
      4. Filesystem Layout
      5. Automating Builds and Testing
    2. 7. Portable Makefiles
      1. Portability Issues
      2. Cygwin
        1. Line Termination
        2. Filesystem
        3. Program Conflicts
      3. Managing Programs and Files
        1. Source Tree Layout
      4. Working with Nonportable Tools
        1. A Standard Shell
      5. Automake
    3. 8. C and C++
      1. Separating Source and Binary
        1. The Easy Way
        2. The Hard Way
      2. Read-Only Source
      3. Dependency Generation
        1. Tromey’s Way
        2. makedepend Programs
      4. Supporting Multiple Binary Trees
      5. Partial Source Trees
      6. Reference Builds, Libraries, and Installers
    4. 9. Java
      1. Alternatives to make
        1. Ant
        2. IDEs
      2. A Generic Java Makefile
      3. Compiling Java
        1. The Fast Approach: All-in-One Compile
        2. Compiling with Dependencies
        3. Setting CLASSPATH
      4. Managing Jars
      5. Reference Trees and Third-Party Jars
      6. Enterprise JavaBeans
    5. 10. Improving the Performance of make
      1. Benchmarking
      2. Identifying and Handling Bottlenecks
        1. Simple Variables Versus Recursive
        2. Disabling @
        3. Lazy Initialization
      3. Parallel make
      4. Distributed make
    6. 11. Example Makefiles
      1. The Book Makefile
        1. Managing Examples
        2. XML Preprocessing
        3. Generating Output
        4. Validating the Source
      2. The Linux Kernel Makefile
        1. Command-Line Options
        2. Configuration Versus Building
        3. Managing Command Echo
        4. User-Defined Functions
    7. 12. Debugging Makefiles
      1. Debugging Features of make
        1. Command-Line Options
          1. --just-print
          2. --print-data-base
          3. --warn-undefined-variables
        2. The --debug Option
      2. Writing Code for Debugging
        1. Good Coding Practices
        2. Defensive Coding
        3. Debugging Techniques
      3. Common Error Messages
        1. Syntax Errors
          1. missing separator
          2. commands commence before first target
          3. unterminated variable reference
        2. Errors in Command Scripts
        3. No Rule to Make Target
        4. Overriding Commands for Target
  8. III. Appendixes
    1. A. Running make
    2. B. The Outer Limits
      1. Data Structures
      2. Arithmetic
    3. C. GNU Free Documentation License—GNU Project—Free Software Foundation (FSF)
      1. 0. Preamble
      2. 1. Applicability and Definitions
      3. 2. Verbatim Copying
      4. 3. Copying in Quantity
      5. 4. Modifications
      6. 5. Combining Documents
      7. 6. Collections of Documents
      8. 7. Aggregation with Independent Works
      9. 8. Translation
      10. 9. Termination
      11. 10. Future Revisions of this License
  9. D. About the Author
  10. E. O’Reilly®: Managing Projects with GNU Make
  11. Index
  12. About the Author
  13. Colophon
  14. Copyright