Here are some links that might help:
Joshua Davies walks through building a simple Hello World app outside of Xcode: http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art024
A .ipa file is just a zip archive with a predefined structure. The iPhone wiki describes it well: http://theiphonewiki.com/wiki/IPA_File_Format