Building an iPhone application from the command line, without xcodebuild - iphone

It is possible to build an iPhone application manually, without using xcodebuild nor an Xcode project?
The idea is to build the application using SCons without creating an Xcode project. I know there is the codesign command line tool, that I could use, but before I start reverse engineering the Xcode build process, I was wondering if anybody has experience with this or has done it before.

Yes, It's possible to write a makefile using gcc. You're going to want to set your GCC to use frameworks from /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.2.sdk/ (frameworks being in system/library/frameworks, and usr/lib).
As far as specifics, I think you're going to have to work that out yourself - but pay careful consideration to the architecture options in GCC and you should have something working quickly.

Xcode just wraps gcc/g++ and ld (and yes, codesign). Take a look at any Xcode project build output and you'll see what commands it uses. I believe the key to building an iphone app is the -arch parameter.

Related

Cross-compiling open-source c library for iOS and XCode 4.3

I'd like to use the excellent stringencoders library in an iOS application. It's a fairly typical c library, with a configure script generated by autoconf and a makefile.
What I'd like to do is compile arm7 and i386 versions on Mac OSX and then use lipo to make a fat binary.
I'm having trouble figuring out how to persuade the build tools to create my platform-specific binaries. There's a few articles out there and even a few scripts but most of them are targeted at XCode 4.2 and don't work with 4.3.
It looks like it should be possible to create a fairly generic build script that can play nicely with configure and make but I'm at a loss as to where to even start.
Have you successfully done anything like this? I'd love some pointers!
BTW: 'import all the sourcecode into your project' is NOT a viable solution. That way lies madness.
Thanks.
I've ported a handful of open source C libraries to iOS (see iOS Ports). I've found the most reliable way to port a library is to build a new Xcode project with a build target for a static iOS Library. It is important to note that Apple will not allow your iOS Application to contain dynamic libraries if you plan to distribute your app on the iTunes App store, so you will be unable to use FAT libraries.
These are the steps I usually follow when porting libraries to iOS which usually built with the GNU Autotools:
Run ./configure with appropriate flags on OS X.
Verify that the library builds correctly on OS X using make.
Create a new Xcode project using the iOS Static Library template.
Add the config.h from the previous configure run to the Xcode project.
Read the automake file (Makefile.am), and add the referenced sources in the automaker targets to the Xcode target for the static library.
Copy the CPP flags (i.e. -DHAVE_CONFIG_H) from the automake file to the build settings in Xcode.
Compile in Xcode and start running down errors (usually by adding missing header include paths or missing source files).
The directory structure I usually use is the following:
project/
project/ported-project.xcodeproj
project/project-x.x.x.tar.gz
project/project-x.x.x
project/project -> project-x.x.x
I know this is not exactly what you asked for in your question, however it is rough outline of the steps I've used for years for porting libraries. The benefit of creating an actual Xcode to compile the ported library is that it makes it easier to integrate the library into multiple Xcode iOS applications.
If you need clarification or more detailed instructions, let me know and I"ll try to write up more extensive instructions and update my answer.
Is it plausible to add the source files (i.e. .c files) to your project directly?
Objective C is a superset of C so i am surprised that the code did not work directly out of the box in XCode 4. Are you missing out something there ? just suggesting
Generate your project files using gyp: http://code.google.com/p/gyp/
I use it to share libraries between win/osx/ios and linux (pi).

Developing in Xcode with MonoTouch?

I am new to Xcode and MonoTouch, so please bear with me.
Is it possible to develop MonoTouch applications with Xcode instead of with MonoDevelop? I have read the MonoTouch Xcode tutorial but unfortunately the process described does not seem to work with the latest MonoTouch version (I get a "No SDK in directory" error, there is also no resource rules file in the root SDK directory). Finally, where am I supposed to put the directives to the MonoTouch compiler?
I have downloaded the trial version of MonoTouch.
Thanks in advance.
Its technically possible, but not in the supported MonoTouch workflow, so you'd be somewhat on your own. What you'd need to do is look at the output of a MonoTouch build with "-v -v -v" in the Extra Arguments field to see how we invoke the AOT compiler. You'll also need to look at the main.m generated by -keeptemp and adapt that in to your Xcode workflow. Lastly you would not be able to use the linker unless you maintained a parallel monotouch project which compiled and linked, and then you did a secondary build step to update your Xcode project.
Xcode does not support third-party plug-ins or environments.

Building and code signing an iPhone Application from the command line

I want to make my iPhone Apps in Emacs now, so without using Xcode at all.
How can I build and codesign my app from the command line (even through SSH)? I can't use xcodebuild as there is no Xcode project. Are there any tutorials which cover this? I want to compile them with GCC, and as soon as Developer Tools 4.0 come out, I want to compile them with LLVM.
Can anyone help me? Thanks.
Is it also possible to debug it on the device without Xcode?
You could start with running a build through Xcode and then having a look at the build log. It contains all the commands and respective parameters used to build your project.
Then is should "just" be a matter of creating a make file using the same commands.

How can I install and ideally run an iPhone app entirely from the command-line?

I'm porting an existing game engine to the iPhone. As a result of a large and complicated build process that isn't really conducive to Xcode I'm developing my own build system that calls the same programs and does the same build steps as Xcode does.
This is generally working pretty well, referring heavily to xcodebuild's output for reference.
The one big thing I can't do is install stuff programatically. I can use Xcode's Organizer window to install manually, but I know of no way to duplicate that behavior via the commandline, nor to run the installed program directly on the iPhone afterwards. I can script it with a GUI macroing system if I have to, but I'd rather not.
I've found the program "iphonesim" to run iPhone apps in the simulator from the commandline, but nothing equivalent for actual hardware development. Any suggestions?
(To stave off the inevitable suggestions: nothing involved is jailbroken in any way, and I don't really plan to jailbreak it.)
The Xcode build system is just a lightweight face on top of standard Unix build tools. Therefore, anything you can do from the command line you can do from Xcode. Most large and/or complex projects use customized build scripts.
The easiest solution for you is to take your existing build scripts and plug them into a custom build script in Xcode. That way you get the control of the command line with the integration of Xcode.
If you're a command line build wizard you shouldn't have any problems customizing Xcode to suit the needs of your project. See the Xcode build documentation for details.
Personally I think Jailbreaking is the way to go.
I bootstrapped a SIP client that way; compile stuff on the command line on Mac with regular Makefiles, then transfer to the iPhone and run there from the command line.
This made my initial development/experiments so much easier.
I wish Apple would ship iPhones with a root shell to developers.

How do I automatically run my iphone app after building it?

I'm using google unit testing code.
I'm building it quite nicely with xcodebuild on the command line. Now I want to run it (preferably on attached Device but simulator would also work) and catch all the feedback from the tests.
But I can't find out how to run it. Any ideas?
Jeff Haynie's iphonesim project on Github looks like it could work. I had trouble building 27812bb4b (make failed on a warning in nsprintf.m), but that may just be me using a pre-release OS and SDK. See also this related question.
If you followed the instructions from the Google page (creating the target, adding the test files to the target) and you have an iPhone SDK certificate (you need it to upload apps to the device) you can just change the Active SDK to your device (upper left corner combo in XCode)
If you don't have a certificate, you need to apply to the SDK program.
The only iPhone simulator and debugger I'm aware of comes with the iPhone SDK. In order to use the iPhone SDK you need to have an Intel-based mac with OS 10.5 Leopard installed, in which case you might as well be programming/compiling in XCode instead of using the command line.
There has to be some misunderstanding here. What exactly do you want to run from the command line? The test suite? If so, the test suite should be a separate target, so that all you have to do is build it, for example like this:
xcodebuild -target UnitTests -sdk iphonesimulator2.2.1 -configuration Debug
If you have the testing target configured correctly, it will run the RunIPhoneUnitTest.sh shipped with the Google Toolbox and the script will run all your tests.