Table Of ContentCCRREEAATTIINNGG
PPOORRTTAABBLLEE
SSOOFFTTWWAARREE JJUUSSTT AA UU TT OO TT OO OO LL SS
GGOOTT EEAASSIIEERR
AA
A P R A C T I T I O N E R ’ S G U I D E T O
UU G N U A U T O C O N F , A U T O M A K E , A N D L I B T O O L
The GNU Autotools make it easy for developers to • Produce portable makefiles with Automake
create software that is portable across many Unix-like
• Build cross-platform software libraries with Libtool
operating systems. Although the Autotools are used
by thousands of open source software packages, they • Write your own Autoconf macros TT
have a notoriously steep learning curve. And good luck J O H N C A L C O T E
Autotools focuses on two projects: Jupiter, a simple
to the beginner who wants to find anything beyond a
“Hello, world!” program, and FLAIM, an existing, OO
basic reference work online.
complex open source effort containing four separate but
Autotools is the first book to offer programmers a tutorial- interdependent subprojects. Follow along as the author
based guide to the GNU build system. Author John takes Jupiter’s build system from a basic makefile to a
TT
Calcote begins with an overview of high-level concepts full-fledged Autotools project, and then as he converts
and a quick hands-on tour of the philosophy and design the FLAIM projects from complex hand-coded makefiles
of the Autotools. He then tackles more advanced details, to the powerful and flexible GNU build system. OO
like using the M4 macro processor with Autoconf,
ABOUT THE AUTHOR
extending the framework provided by Automake, and
building Java and C# sources. He concludes the book John Calcote is a senior software engineer and architect OO
with detailed solutions to the most frequent problems at Novell, Inc. He’s been writing and developing portable
encountered by first-time Autotools users. networking and system-level software for nearly 20 years
and is active in developing, debugging, and analyzing
You’ll learn how to: LL
diverse open source software packages. He is currently
• Master the Autotools build system to maximize your a project administrator of the OpenSLP, OpenXDAS, and
software’s portability DNX projects, as well as the Novell-sponsored FLAIM
SS
database project.
• Generate Autoconf configuration scripts to simplify
the compilation process
THE FINEST IN GEEK ENTERTAINMENT™
www.nostarch.com C
A
L
C
“I LIE FLAT.” $44.95 ($56.95 CDN) O
T
This book uses RepKover—a durable binding that won’t snap shut. COMPUTERS/PROGRAMSHELVE IN: E
M
ING
Autotools_02.book Page i Tuesday, June 15, 2010 2:38 PM
AUTOTOOLS
Autotools_02.book Page ii Tuesday, June 15, 2010 2:38 PM
Autotools_02.book Page iii Tuesday, June 15, 2010 2:38 PM
AUTOTOOLS
A Practitioner’s Guide to
GNU Autoconf, Automake,
and Libtool
by John Calcote
San Francisco
Autotools_02.book Page iv Tuesday, June 15, 2010 2:38 PM
AUTOTOOLS. Copyright © 2010 by John Calcote.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior
written permission of the copyright owner and the publisher.
14 13 12 11 10 1 2 3 4 5 6 7 8 9
ISBN-10: 1-59327-206-5
ISBN-13: 978-1-59327-206-7
Publisher: William Pollock
Production Editor: Ansel Staton
Cover and Interior Design: Octopod Studios
Developmental Editor: William Pollock
Technical Reviewer: Ralf Wildenhues
Copyeditor: Megan Dunchak
Compositor: Susan Glinert Stevens
Proofreader: Linda Seifert
Indexer: Nancy Guenther
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
38 Ringold Street, San Francisco, CA 94103
phone: 415.863.9900; fax: 415.863.9950; [email protected]; www.nostarch.com
Library of Congress Cataloging-in-Publication Data
Calcote, John, 1964-
Autotools : a practitioner's guide to GNU Autoconf, Automake, and Libtool / by John Calcote.
p. cm.
ISBN-13: 978-1-59327-206-7 (pbk.)
ISBN-10: 1-59327-206-5 (pbk.)
1. Autotools (Electronic resource) 2. Cross-platform software development. 3. Open source software.
4. UNIX (Computer file) I. Title.
QA76.76.D47C335 2010
005.3--dc22
2009040784
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and
company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark
symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution has been
taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any liability to any
person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the
information contained in it.
Autotools_02.book Page v Tuesday, June 15, 2010 2:38 PM
For Michelle
But to see her was to love her;
Love but her, and love forever.
—Robert Burns
Autotools_02.book Page vi Tuesday, June 15, 2010 2:38 PM
Autotools_02.book Page vii Tuesday, June 15, 2010 2:38 PM
B R I E F C O N T E N T S
Foreword by Ralf Wildenhues..........................................................................................xv
Preface.......................................................................................................................xvii
Introduction..................................................................................................................xxi
Chapter 1: A Brief Introduction to the GNU Autotools..........................................................1
Chapter 2: Understanding the GNU CodingStandards.....................................................19
Chapter 3: Configuring Your Project with Autoconf...........................................................57
Chapter 4: More Fun with Autoconf: Configuring User Options..........................................89
Chapter 5: Automatic Makefiles with Automake..............................................................119
Chapter 6: Building Libraries with Libtool.......................................................................145
Chapter 7: Library Interface Versioning and Runtime Dynamic Linking...............................171
Chapter 8: FLAIM: An Autotools Example.......................................................................195
Chapter 9: FLAIM Part II: Pushing the Envelope...............................................................229
Chapter 10: Using the M4 Macro Processor with Autoconf..............................................251
Chapter 11: A Catalog of Tips and Reusable Solutions for Creating Great Projects.............271
Index.........................................................................................................................313
Autotools_02.book Page viii Tuesday, June 15, 2010 2:38 PM