Created
July 25, 2012 08:22
-
-
Save bellbind/3175073 to your computer and use it in GitHub Desktop.
[macosx][ios][objective-c]Building iOS 5.1 app with command line (completely Xcode-less programming)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# build for target iPad/iPhone binary | |
XCODE=/Applications/Xcode.app | |
TOOLCHAIN=$XCODE/Contents/Developer/Toolchains/XcodeDefault.xctoolchain | |
CC=$TOOLCHAIN/usr/bin/clang | |
PLATFORMS=$XCODE/Contents/Developer/Platforms | |
PLATFORM=$PLATFORMS/iPhoneOS.platform/Developer | |
SYSROOT=$PLATFORM/SDKs/iPhoneOS5.1.sdk | |
$CC -arch armv7 -mthumb -isysroot $SYSROOT \ | |
-miphoneos-version-min=5.1 \ | |
-framework Foundation -framework CoreGraphics -framework UIKit \ | |
"$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# build for IOS Simulator | |
XCODE=/Applications/Xcode.app | |
TOOLCHAIN=$XCODE/Contents/Developer/Toolchains/XcodeDefault.xctoolchain | |
CC=$TOOLCHAIN/usr/bin/clang | |
PLATFORMS=$XCODE/Contents/Developer/Platforms | |
PLATFORM=$PLATFORMS/iPhoneSimulator.platform/Developer | |
SYSROOT=$PLATFORM/SDKs/iPhoneSimulator5.1.sdk | |
$CC -arch i386 -isysroot $SYSROOT \ | |
-miphoneos-version-min=5.1 -ObjC++ -fobjc-abi-version=3 \ | |
-framework Foundation -framework CoreGraphics -framework UIKit \ | |
"$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./compile-simulator.sh hello.m -o hello | |
// ./simulator.sh hello | |
#import <UIKit/UIKit.h> | |
@interface AppDelegate : UIResponder<UIApplicationDelegate> | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(id)application didFinishLaunchingWithOptions:(id)opts | |
{ | |
CGRect frame = [[UIScreen mainScreen] bounds]; | |
UIWindow* window = [[UIWindow alloc] initWithFrame:frame]; | |
window.backgroundColor = [UIColor whiteColor]; | |
[window makeKeyAndVisible]; | |
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; | |
button.frame = frame; | |
[button setTitle:@"Touch" forState:UIControlStateNormal]; | |
[window addSubview:button]; | |
[button addTarget:self action:@selector(hello:) | |
forControlEvents:UIControlEventTouchDown]; | |
return YES; | |
} | |
- (void)hello:(id)sender | |
{ | |
id alert = [[UIAlertView alloc] | |
initWithTitle:@"Alert" message:@"Hello" delegate:nil | |
cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; | |
[alert show]; | |
[alert release]; | |
} | |
@end | |
int main(int argc, char** argv) | |
{ | |
@autoreleasepool { | |
return UIApplicationMain(argc, argv, nil, | |
NSStringFromClass([AppDelegate class])); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"UIDeviceFamily":[1,2]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
XCODE=/Applications/Xcode.app | |
PLATFORMS=$XCODE/Contents/Developer/Platforms | |
APPS=$PLATFORMS/iPhoneSimulator.platform/Developer/Applications | |
SIM=$APPS/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator | |
"$SIM" -SimulateApplication "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./compile-simulator.sh webkit.m -o webkit | |
// ./simulator.sh webkit | |
#import <UIKit/UIKit.h> | |
@interface AppDelegate : UIResponder<UIApplicationDelegate> | |
@end | |
@implementation AppDelegate | |
- (BOOL)application:(id)application didFinishLaunchingWithOptions:(id)opts | |
{ | |
CGRect frame = [[UIScreen mainScreen] applicationFrame]; | |
UIWindow* window = [[UIWindow alloc] initWithFrame:frame]; | |
window.backgroundColor = [UIColor whiteColor]; | |
[window makeKeyAndVisible]; | |
UIWebView* webview = [[UIWebView alloc] initWithFrame:frame]; | |
webview.scalesPageToFit = YES; | |
[window addSubview:webview]; | |
id url = [NSURL URLWithString:@"http://google.com/"]; | |
id req = [NSURLRequest requestWithURL:url]; | |
[webview loadRequest:req]; | |
return YES; | |
} | |
@end | |
int main(int argc, char** argv) | |
{ | |
@autoreleasepool { | |
return UIApplicationMain(argc, argv, nil, | |
NSStringFromClass([AppDelegate class])); | |
} | |
} |
I'm sorry about such indent!
I made them for Swift3 and Xcode8.1 environment: https://gist.github.com/bellbind/20b59a4ab86d11e5e358a472c7ae5986
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
makefile
prerequisite
SDK := 7.1
XCODE := /Applications/Xcode.app
TOOLCHAIN := $(XCODE)/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
PLATFORMS := $(XCODE)/Contents/Developer/Platforms
APPS := $(PLATFORMS)/iPhoneSimulator.platform/Developer/Applications
SIM := $(APPS)/iPhone\ Simulator.app/Contents/MacOS/iPhone\ Simulator
OBJCC = $(TOOLCHAIN)/usr/bin/clang
OBJCXX = $(TOOLCHAIN)/usr/bin/clang++
runtime env
ifeq ($(arm),1)$(PLATFORM)/SDKs/iPhoneOS$ (SDK).sdk$(PLATFORM)/SDKs/iPhoneSimulator$ (SDK).sdk
PLATFORM := $(PLATFORMS)/iPhoneOS.platform/Developer
SYSROOT :=
OBJCXXFLAGS := -arch armv7 -mthumb
else
PLATFORM := $(PLATFORMS)/iPhoneSimulator.platform/Developer
SYSROOT :=
OBJCXXFLAGS := -arch i386
endif
optimization
ifeq ($(release),)
OBJCXXFLAGS := -g -fno-inline -O0
else
OBJCXXFLAGS := -DNDEBUG -O4
endif
target & sources
TARGET := a.out
SRCS := $(wildcard *.mm)
compiling & linking
INCPATH :=
LIBPATH :=
OBJCXXFLAGS +=
-isysroot $(SYSROOT)
-fobjc-arc
-std=c++11
-ObjC++
-Werror -Wall \
LDFLAGS +=
-miphoneos-version-min=$(SDK)
-isysroot $(SYSROOT)
-framework Foundation
-framework CoreGraphics \
ifeq ($(ui),1)
LDFLAGS += -framework UIKit
endif
rules
all: $(TARGET)
run:
./$(TARGET)
sim-run:
$(SIM) -SimulateApplication $ (TARGET)
clean:
rm -f *.out *.o *~
%.o: %.mm
$(OBJCXX) -o $ @ -c $< $ (OBJCXXFLAGS) $(INCPATH)
.PHONY: all run sim-run clean