140 likes | 277 Vues
Dive into the world of GNU Autotools with Michael Imamura's insightful presentation. Explore how Autoconf simplifies the configuration process, Automake streamlines Makefile creation, and Libtool aids in managing shared and static libraries. Learn how to start from scratch with a blank Autotools project, develop with ease, and ensure portability in your code. Understand key processes like autoscan, autoreconf, and debugging techniques. Discover tips for working with source control and customize your package with user-friendly features.
E N D
The GNU Autotools Your very own ./configure Michael Imamura / LUG@GT
Say Hello to the Autotools • Autoconf, with the power of ./configure! • Automake, making makefiles suck less! • Libtool, friend to shared and static library alike! Michael Imamura / LUG@GT
The Autotools are Hard! • No, they’re not! • Well, maybe a little… • Okay, here’s why you should learn them anyway. • User configurability • Standards are everybody’s friend! • Portability – your code isn’t as portable as you think! Michael Imamura / LUG@GT
Getting Started • From scratch: A blank Autotools project • http://lugatgt.org/articles/autotools/autoblank.tar.gz • Use an IDE (like Anjuta) • Retrofit an existing project Michael Imamura / LUG@GT
The Initial Process • Create a few initial stub sources (if you don’t already have any) • Create Makefile.am files • http://lugatgt.org/articles/autotools/amwiz/ • Run autoscan and create configure.ac • Autoconf Macro Archivehttp://autoconf-archive.cryp.to/ • Run autoreconf --install • Run ./configure! Michael Imamura / LUG@GT
Automake • Makefile.am Makefile.in Makefile • Basically, a Makefile with special variable declarations • Primaries: What is being produced • bin_PROGRAMS, lib_LTLIBRARIES, etc. • Secondaries: How to produce it • _CFLAGS, _SOURCES, _LIBADD, etc. Michael Imamura / LUG@GT
Autoconf • Run “autoscan” to produce configure.scan • Detects source file types • Detects toolchain dependencies • Merge configure.scan into configure.ac • Add AM_INIT_AUTOMAKE to add Automake support • Add AC_PROG_LIBTOOL to add Libtool support Michael Imamura / LUG@GT
Developing, developing, developing… • Whenever configure.ac or Makefile.am changes, re-run autoreconf • autoreconf --make is useful here • Generated Makefile is often smart enough to do it for you • Standard make targets generated by Automake • User: all (default), install, clean • Developer: dist, check, distcheck Michael Imamura / LUG@GT
Debugging • Libtool hides linking issues • Automatically relinks on install • Oops… Libtool gets in the way • Your binary may not be a binary! • Use “libtool gdb” instead of “gdb” Michael Imamura / LUG@GT
Source control: What to check in • General rule: Only check in files that you have created • Only configure.ac and Makefile.am • Set ignores for the generated files • Add to note to HACKING about what versions of Autoconf, Automake, and Libtool you used Michael Imamura / LUG@GT
What about portability? • The other reason to use Autoconf • General strategy: • Study the config.h generated by ./configure • For every #define: • Can we work around the issue? • Is the tested feature an absolute requirement? • Autoconf is not a magic bullet! • It’s up to YOU to decide how to react Michael Imamura / LUG@GT
Beyond ./configure • “make check”: Unit tests with DejaGNU • Custom configure.ac tests • Tests are written in GNU M4 • Use AC_ARG_ENABLE to allow the user to customize your package with --enable-feature • Fine-tuning • Different flavors of “clean” Michael Imamura / LUG@GT
There’s much more to say… • But this presentation is too small to contain it. • http://lugatgt.org/articles/autotools/ • Autoconf Macro Archive:http://autoconf-archive.cryp.to/ • “GNU Autoconf, Automake, and Libtool” by Gary Vaughan, et al.http://sourceware.org/autobook/(free download!) Michael Imamura / LUG@GT