This question led to a new feature in a package:
As of version 0.6currfilesupports the requested feature via a new package option and the-recordercompiler switch. For details, see Martin's answer below.
From the documentation I assumed that Martin Scharrer's currfile package would do this. However, while it deals well with tracking the actual file name over \inputs and \includes, the name of the main .tex file is still set to \jobname:
\documentclass{article}
\usepackage{currfile}
\begin{document}
I was compiled as job \texttt{\jobname} from the file \texttt{\currfilename}.
\end{document}
If saved as test.tex and compiled with pdflatex -jobname bla test.tex the output is:
Even compiling with pdflatex -jobname bla "\input{test.tex}" does not change the output.
currfileuses\jobnamefor the main file. I'm not aware of any other way to find out the real file name (or even its extension), but I'm happy to learn about one if it exists. This is actually a recent feature request for the package. – Martin Scharrer Oct 16 '11 at 18:19