-
-
Save bellbind/3175073 to your computer and use it in GitHub Desktop.
#!/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 \ | |
"$@" |
#!/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 \ | |
"$@" |
// ./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])); | |
} | |
} |
{"UIDeviceFamily":[1,2]} |
#!/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 "$@" |
// ./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])); | |
} | |
} |
Thanks!!!!
❤️
Nice!
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 := $(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:
clean:
rm -f *.out *.o *~
%.o: %.mm
.PHONY: all run sim-run clean
I'm sorry about such indent!
I made them for Swift3 and Xcode8.1 environment: https://gist.github.com/bellbind/20b59a4ab86d11e5e358a472c7ae5986
Running on iPhone Simulator 6.1 requires "AppName.app" directory. e.g.:
The compile options are also switched "-miphoneos-verson-min=6.1" and "SYSROOT=$PLATFORM/SDKs/iPhoneSimulator6.1.sdk"