Ubuntu 16.04下编译C/C++源码包时autogen.sh的作用是什么?
autogen.sh do when building C/C++ packages from source? Great question! Let’s break down exactly what autogen.sh does, why it’s sometimes necessary, and how it fits into the build workflow you mentioned (./autogen.sh → ./configure → make → make install).
First, when do you even need autogen.sh?
You’ll almost only encounter autogen.sh if you’re pulling source code directly from a version control system (like Git), rather than downloading a pre-packaged release tarball. Release tarballs from project maintainers usually already include the configure script and other pre-generated build files—so you can skip straight to ./configure. But Git repos typically don’t track these generated files (since they’re derived from other source files), which is where autogen.sh comes in.
What does autogen.sh actually do?
It’s essentially a helper script that automates running a set of build preparation tools to generate all the files needed for ./configure to work. Here’s a breakdown of its key tasks:
- Generates the
configurescript: It callsautoconf(or oftenautoreconf, a wrapper that runs multiple tools in sequence) to create theconfigurescript from the human-writtenconfigure.ac(or olderconfigure.in) template. This template defines project dependencies, build options, and system checks thatconfigureuses to generate your system-specificMakefile. - Creates
Makefile.intemplates: Usingautomake, it generatesMakefile.infiles fromMakefile.amtemplates. These.infiles are the blueprints thatconfigureuses to produce the finalMakefiletailored to your Ubuntu 16.04 system. - Sets up libtool (if needed): If the project uses shared libraries,
autogen.shwill runlibtoolize(orglibtoolizeon some systems) to generate the necessary libtool scripts and configuration files, which handle cross-platform shared library compilation. - Checks for required tools: It often includes checks to ensure you have all the prerequisite software installed (like
autoconf,automake,libtool). If you’re missing any on Ubuntu 16.04, it’ll usually throw an error telling you to install them with a command like:sudo apt-get install autoconf automake libtool
Why can’t I just run those tools manually?
You could! But autogen.sh exists to save you the hassle of remembering the exact order and flags for each tool. Different projects might have slightly different requirements (like needing to run aclocal first, or passing specific flags to autoreconf), and autogen.sh encapsulates all those project-specific steps into one simple command.
So in short: autogen.sh is your one-stop shop to turn raw source code from a repo into a buildable project that’s ready for ./configure.
内容的提问来源于stack exchange,提问作者Elad Weiss

