Xcode also supports compiling iPhone programs in the form of command lines. In addition, you can manually compile the Makefile file to compile and install the automatic batch processing process. If you are used to the command line operation (linux, unix), this operation is very convenient.
First, look at the command line format of Xcode:
Xcodebuild-target Project_Name
Xcodebuild install-target Project_Name
Next we will compile the program, use ldid to convert the encoding format, and then use ssh to install the compiled program to the/Applications/directory on the iPhone.
First, install the ssh public key on the iPhone.
1). Generate a key on the Mac Terminal
Ssh-keygen-t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xxxx/. ssh/id_rsa ):
Created directory '/home/xxxx/. ssh '.
Enter passphrase (empty for no passphrase): xxx
Enter same passphrase again: xxx
Your identification has been saved in/home/xxxx/. ssh/id_rsa.
Your public key has been saved in/home/xxxx/. ssh/id_rsa.pub.
The key fingerprint is:
E4: e8: b7: 05: 06: b3: f0: ff: af: 13: fc: 50: 6a: 5b: d1: b5 xxxx@localhost.localdomain
In the process, you will be asked about your pass (passphrase) and enter your frequently used secret.
2). Create the. ssh directory on the iPhone (the IP address of the iPhone is 10.0.2.2)
1 ssh root@10.0.2.2 'mkdir-p. ssh'
If you ask your iPhone root password, enter alpine.
3) copy the public key just generated to the iPhone
1 cat ~ /. Ssh/id_rsa.pub | ssh root@10.0.2.2 'cat>. ssh/authorized_keys'
If you ask your iPhone root password, enter alpine.
4) edit the/etc/ssh/sshd_config file on the iPhone.
# Set
# StrictModes yes
# PubkeyAuthentication yes
# AuthorizedKeysFile. ssh/authorized_keys
# Replace
StrictModes no
PubkeyAuthentication yes
AuthorizedKeysFile. ssh/authorized_keys
5). Restart the iPhone
Next, compile and generate the ldid Tool
Wget http://svn.telesphoreo.org/trunk/data/ldid/ldid-1.0.610.tgz
Tar-zxf ldid-1.0.610.tgz
# Download the following patch for PowerPC
# Wget-qO-pilot? Revision = 1.1 | patch-p0
Cd ldid-1.0.610
G ++-I.-o util/ldid {,. cpp}-x c util/{lookup2, sha1}. c
Sudo cp-a util/ldid/usr/bin
Finally, let's see what is in Makefile.
The project file is as follows:
Classes: source code (. m. c. cpp etc)
Resources: png file and other support files
Project folder: *. xib Info. plist
Makefile: Select all
PREFIX = arm-apple-darwin9-
###///////////////////////////////////// ////////////////////////
### Executable files
###///////////////////////////////////// ////////////////////////
CC = $ (PREFIX) gcc
CXX = $ (PREFIX) g ++
LD = $ (CC)
AR = $ (PREFIX) ar
STRIP = $ (PREFIX) strip
OBJCOPY = $ (PREFIX) objcopy
######################################## ######################################## ####
# Debug/release
DEBUG? = N
DEVEL? = N
# SDK version
SDKVER = 3.1.2
# IPhone IP Address
IPHONE_IP = 10.0.2.2
# IPhone SDK path
IPhone sdk =/Developer/Platforms/iPhone OS. platform/Developer/SDKs/iPhone OS $ (SDKVER). sdk
# Include path
INCPATH + =-I "$ (IPHONESDK)/usr/include"
INCPATH + =-I "/Developer/Platforms/iPhoneOS. platform/Developer/usr/lib/gcc/arm-apple-darwin9/4.2/include /"
INCPATH + =-I "/Developer/Platforms/iPhoneOS. platform/Developer/usr/include /"
INCPATH + =-I "/Developer/Platforms/iPhoneSimulator. platform/Developer/SDKs/iPhoneSimulator $ (SDKVER). sdk/usr/include"
# Settings of the standard library or framework
LDFLAGS =-lobjc \
-Bind_at_load \
-Multiply_defined suppress \
-W
LDFLAGS + =-framework CoreFoundation
LDFLAGS + =-framework Foundation
LDFLAGS + =-framework UIKit
LDFLAGS + =-framework CoreGraphics
# LDFLAGS + =-framework AddressBookUI
# LDFLAGS + =-framework AddressBook
# LDFLAGS + =-framework QuartzCore
# LDFLAGS + =-framework GraphicsServices
# LDFLAGS + =-framework CoreSurface
# LDFLAGS + =-framework CoreAudio
# LDFLAGS + =-framework Celestial
# LDFLAGS + =-framework AudioToolbox
# LDFLAGS + =-framework WebCore
# LDFLAGS + =-framework WebKit
# LDFLAGS + =-framework SystemConfiguration
# LDFLAGS + =-framework CFNetwork
# LDFLAGS + =-framework MediaPlayer
# LDFLAGS + =-framework OpenGLES
# LDFLAGS + =-framework OpenAL
LDFLAGS + =-F "$ (IPHONESDK)/System/Library/Frameworks"
LDFLAGS + =-F "$ (IPHONESDK)/System/Library/PrivateFrameworks"
# Compile Switch
CFLAGS + = $ (INCPATH )\
-Std = c99 \
-W-Wall \
-Funroll-loops \
-Diphoneos_version_min = 2.0 \
-Wno-unused-parameter \
-Wno-sign-compare
Ifeq ($ (DEBUG), y)
CFLAGS + =-O0-g-DDEBUG_MUTEX
Else
CFLAGS + =-O3-DNDEBUG
Ifeq ($ (DEVEL), y)
CFLAGS + =-g
Endif
Endif
CFLAGS + =-F "$ (IPHONESDK)/System/Library/Frameworks"
CFLAGS + =-F "$ (IPHONESDK)/System/Library/PrivateFrameworks"
######################################## ######################################## ####
BUILDDIR =./build/3.0
SRCDIR =./Classes
RESDIR =./Resources
###///////////////////////////////////// ////////////////////////
### Source files
###///////////////////////////////////// ////////////////////////
OBJS = $ (patsubst %. m, %. o, $ (wildcard $ (SRCDIR)/*. m ))
OBJS + = $ (patsubst %. m, %. o, $ (wildcard./*. m ))
OBJS + =$ (patsubst %. c, %. o, $ (wildcard $ (SRCDIR)/*. c ))
OBJS + =$ (patsubst %. cpp, %. o, $ (wildcard $ (SRCDIR)/*. cpp ))
NIBS = $ (patsubst %. xib, %. nib, $ (wildcard *. xib ))
RESOURCES = $ (wildcard $ (RESDIR )/*)
APPFOLDER = $ (TARGET). app
. PHONY: all
All: $ (TARGET) bundle
$ (TARGET): $ (OBJS)
$ (LD) $ (LDFLAGS)-o $ @ $ ^
%. O: %. m
$ (CC)-c $ (CFLAGS) $ <-o $ @
%. O: %. c
$ (CC)-c $ (CFLAGS) $ <-o $ @
%. O: %. cpp
$ (CXX)-x objective-c ++ $ (CFLAGS) $ <-o $ @
%. Nib: %. xib
Ibtool $ <-- compile $ @
Bundle: $ (TARGET)
@ Rm-rf $ (BUILDDIR)
@ Mkdir-p $ (BUILDDIR)/$ (APPFOLDER)
@ Cp-r $ (RESDIR)/* $ (BUILDDIR)/$ (APPFOLDER)
@ Cp Info. plist $ (BUILDDIR)/$ (APPFOLDER)/Info. plist
@ Echo "APPL"> $ (BUILDDIR)/$ (APPFOLDER)/PkgInfo
Mv $ (NIBS) $ (BUILDDIR)/$ (APPFOLDER)
# Export CODESIGN_ALLOCATE =/Developer/Platforms/iPhoneOS. platform/Developer/usr/bin/codesign_allocate
@ Ldid-S $ (TARGET)
@ Mv $ (TARGET) $ (BUILDDIR)/$ (APPFOLDER)/$ (TARGET )_
Install: bundle
@ Ssh root @ $ (IP) "cd/Applications/$ (APPFOLDER) & rm-R * | echo 'not found '"
@ Scp-rp $ (BUILDDIR)/$ (APPFOLDER) root @ $ (IP):/Applications
@ Ssh root @ $ (IP) "cd/Applications/$ (APPFOLDER); ldid-S $ (TARGET) _; killall SpringBoard"
@ Echo "Application $ (APPFOLDER) installed"
Uninstall:
Ssh root @ $ (IPHONE_IP) 'rm-fr/Applications/$ (APPFOLDER); respring'
@ Echo "Application $ (APPFOLDER) uninstalled, please respring iPhone"
Install_respring:
Scp respring_arm root @ $ (IPHONE_IP):/usr/bin/respring
. PHONY: clean
Clean:
@ Rm-f $ (OBJS) $ (TARGET)
@ Rm-rf $ (BUILDDIR)
Then run the following make command to test our program on the iPhone.
Make install_respring
Make
Make install
Author: Yi Feiyang