Created
November 29, 2012 05:17
-
-
Save kosugi/4166950 to your computer and use it in GitHub Desktop.
execute objc code fragment
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 | |
| # | |
| # exec-objc.sh <<'EOD' | |
| # NSLog(@"this script compile and execute objective-c code fragment"); | |
| # EOD | |
| # | |
| SRC=$(mktemp exec-objc-src.XXXXXXXX) | |
| OUT=$(mktemp exec-objc-out.XXXXXXXX) | |
| trap 'rm -f ${SRC} ${OUT}' EXIT | |
| cat >>${SRC} <<'EOD' | |
| #import <Foundation/Foundation.h> | |
| void doIt() { | |
| EOD | |
| cat >>${SRC} </dev/stdin | |
| cat >>${SRC} <<'EOD' | |
| } | |
| int main() { | |
| @autoreleasepool { | |
| doIt(); | |
| } | |
| return 0; | |
| } | |
| EOD | |
| clang -Wall -x objective-c -std=c99 -fobjc-arc "$@" -framework Foundation -o ${OUT} ${SRC} && PATH=.:$PATH ${OUT} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment