When installing something from source (say, Ruby 1.9.2), what command can I run to get a complete list of all the dependencies needed to install that application? Is this possible?
Short answer: not possible. The difficulty of getting the exact dependencies from a source distribution is the reason why package management is so popular on Linux (okay, one of several reasons). In fact, if you just need to get it done and don't care so much how, the most reliable way to get the dependencies will probably be to grab a distro package (gentoo ebuilds are easy to work with) and pull the list of dependencies from that.
Otherwise, if you're lucky, the maintainers will have created a listing of the dependencies in the README file or similar - that'd be the first place to check. Failing that, if it's a C project and you don't mind getting your hands dirty, you can look inside the configure script (or better yet the configure.ac or whatever it's generated from) and figure out the dependencies from that based on what it checks.
Building from source
There isn't any programmatic way that I'm aware of, I generally look through the release notes and/or software README files to get a general idea. This works out to be an iterative process where I might find a library or two that I don't have or missed and need to go get them.
Building using a package manager
If on the other hand you're using a package manager such as
yum then you can enlist the help of these systems to help install all the dependencies ahead of time, prior to installing/building the package in question.
apt based distros
$ sudo apt-get build-dep <package>
yum based distros
$ sudo yum-builddep --nogpgcheck <source package>
$ sudo yum-builddep --nogpgcheck <package>
On the whole, I also can't give you a 100% solution, but for most sources using autotools, you can grep
The first argument of
AC_CHECK_HEADERS is a filename or even a path with a filename.
PKG_CHECK_MODULES is introduced with pkg-config and, IIRC the second argument to
PKG_CHECK_MODULES includes a package name for which a file
<pkg-name>.pc must exist.
The second argument to
AC_SEARCH_LIBS is a library name and using Linux you are looking for a file which begins with
Neither of those are perfect and this needn't give you a complete list of requirements, but ...
the source maintainers have an increased interest to see that these three things will lead you to a complete list of requirements.
with a little scripting you can use these three things to search through the packages of your distribution and find packages providing you with missing files. For instance using
apt-file searchfor all Debian based Linuxes, as mentioned by Faheem Mitha.
In Ubuntu (Debian):
sudo apt-get build-dep <package>