Apple's package management system is often subject to criticism. The utility
pkgutil can be used to list and query the package receipts.
List all the packages installed with Apple's installer
Regex for a package id
List all the files in a package id
pkgutil --only-files --files com.apple.pkg.update.devtools.3.2.6.XcodeUpdate
Then again you could use
lsbom and read the bom files in /var/db/receipts
Users also install other package management systems such as MacPorts, fink, or Homebrew. Or compile their own in whatever prefix.
pkgutil will not list packages installed by these methods.
If your target operating system is OS X10.9 or OS X 10.10 then
Either the command will output the gcc version or you will be prompted to install the XCode command line tools.
gcc, g++, cpp, make, and git will be installed along with other tools. The Java package is offered from Oracle. You could test with
java --version though you'll need to familiarize yourself with Apple's frameworks, plugins, and bundles to search for header files.
pkgutil would be a good candidate for this process.
The other packages you mentioned could possibly be compiled with in a shell script or compiled and put into an Apple installer package then installed via a shell script. There isn't an easy method.