原文链接:
http://codecloud.net/11311.html
http://www.cocoachina.com/ios/20150127/11022.html
http://www.cnblogs.com/xiaodao/archive/2012/03/28/2422091.html
【
# Sets the target folders and the final framework product.
# 如果工程名称和Framework的Target名称不1样的话,要自定义FMKNAME
# 例如: FMK_NAME = "MyFramework"
#FMK_NAME=${PROJECT_NAME}
FMK_NAME="TJJ"
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${BUILD_ROOT}/Release-iphonesimulator/${FMK_NAME}.framework
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${INSTALL_DIR}"】
shell中的1些关键字
1、xcode4中的环境变量
$(BUILT_PRODUCTS_DIR)
build成功后的,终究产品路径--可以在Build Settings参数的Per-configuration Build Products Path项里设置
$(TARGET_NAME)
目标工程名称
$(SRCROOT)
工程文件(比如Nuno.xcodeproj)的路径
$(CURRENT_PROJECT_VERSION)
当前工程版本号
其他:
当编译静态库,装备选摹拟器(iPhone 5.0 Simulator),未设置任何Build Settings参数时,默许的基础路径:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxxWorkspace-caepeadwrerdcrftijaolkkagbjf
下面用$()代替上面1长串东东
$(SYMROOT) = $()/Build/Products
$(BUILD_DIR) = $()/Build/Products
$(BUILD_ROOT) = $()/Build/Products
这3个变量中的$()不会随着Build Settings参数的设置而改变
相反,以下可以通过设置而改变
$(CONFIGURATION_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator
$(BUILT_PRODUCTS_DIR) = $()/Build/Products/Debug-iphonesimulator
$(CONFIGURATION_TEMP_DIR) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator
$(TARGET_BUILD_DIR) = $()/Build/Products/Debug-iphonesimulator
$(SDK_NAME) = iphonesimulator5.0
$(PLATFORM_NAME) = iphonesimulator
$(CONFIGURATION) = Debug
$(TARGET_NAME) = UtilLib
$(EXECUTABLE_NAME) = libUtilLib.a 可履行文件名
${IPHONEOS_DEPLOYMENT_TARGET} 5.0
$(ACTION) = build
$(CURRENTCONFIG_SIMULATOR_DIR) 当前摹拟器路径
$(CURRENTCONFIG_DEVICE_DIR) 当前装备路径
$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME =
$()/Build/Products/Debug-iphonesimulator
$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) = $()/Build/Intermediates/UtilLib.build/Debug-iphonesimulator
自定义变量
${CONFIGURATION}-iphoneos 表示:Debug-iphoneos
${CONFIGURATION}-iphonesimulator 表示:Debug-iphonesimulator
$(CURRENTCONFIG_DEVICE_DIR) = ${SYMROOT}/${CONFIGURATION}-iphoneos
$(CURRENTCONFIG_SIMULATOR_DIR) = ${SYMROOT}/${CONFIGURATION}-iphonesimulator
自定义1个装备无关的路径(用来寄存各种架构arm6/arm7/i386输出的产品)
$(CREATING_UNIVERSAL_DIR) = ${SYMROOT}/${CONFIGURATION}-universal
自定义变量代表的值
$(CURRENTCONFIG_DEVICE_DIR) = $()/Build/Products/Debug-iphoneos
$(CURRENTCONFIG_SIMULATOR_DIR) = $()/Build/Products/Debug-iphonesimulator
$(CREATING_UNIVERSAL_DIR) = $()/Build/Products/Debug-universal
iphoneos5.0下的编译脚本:
xcodebuild -project "UtilLib.xcodeproj" -configuration "Debug" -target "UtilLib" -sdk "iphoneos5.0" -arch "armv6 armv7" build RUN_CLANG_STATIC_ANALYZER=NO $(BUILD_DIR)="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
iphonesimulator5.0下的编译脚本:
xcodebuild -project "UtilLib.xcodeproj" -configuration "Debug" -target "UtilLib" -sdk "iphonesimulator5.0" -arch "i386" build RUN_CLANG_STATIC_ANALYZER=NO $(BUILD_DIR)="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}"
加上下面1句表示输出到文件:
> "${BUILD_ROOT}.build_output"
lipo脚本工具:合并iPhone摹拟器和真机的静态类库,生成通用库
lipo -create -output "${CREATING_UNIVERSAL_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_DEVICE_DIR}/${EXECUTABLE_NAME}" "${CURRENTCONFIG_SIMULATOR_DIR}/${EXECUTABLE_NAME}"
意思是:把"${CURRENTCONFIG_DEVICE_DIR}目录下的.a文件,和${CURRENTCONFIG_SIMULATOR_DIR}目录下的.a文件合并,
在${CREATING_UNIVERSAL_DIR}目录下,生成两个装备都通用的静态库,
例如:lipo -create -output xy.a x.a y.a
2、xcode4中build Settings常见参数解析
1.Installation Directory:安装路径
静态库编译时,在Build Settings中Installation Directory设置“$(BUILT_PRODUCTS_DIR)”
Skip Install设为YES
Installation Directory默许为/usr/local/lib
由于Build Location默许时,.a文件会放在很长(比如:/Users/xxx/Library/Developer/Xcode/DerivedData/xxxProgram
dalrvzehhtesxdfqhxixzafvddwe/Build/Products/Debug-iPhoneos)的路径下,或是我们target指定的路径
Skip Install如果是NO,可能会被安装到默许路径/usr/local/lib
2.Public Headers Folder Path:对外公然头文件路径
设为“include”(具体的头文件路径为:$(BUILT_PRODUCTS_DIR)/include/xx.h)
在终究文件.a同级目录下生成1个include目录
默许:/usr/local/include
Public Headers Folder Path这个路径就是使用这lib的某工程需要依赖的外部头文件.导入这路径后,#include/import "xx.h"才能看到
3.User Header Search Paths:依赖的外部头文件搜索路径
设置为“$(BUILT_PRODUCTS_DIR)/include”
和2中路径对应
4.Per-configuration Build Products Path:终究文件路径
比如设为“../app”,就会在工程文件.xcodeproj上1层目录下的app目录里,创建终究文件
默许为$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
等于$(BUILT_PRODUCTS_DIR)
5.Per-configuration Intermediate Build Files Path:临时中间文件路径
默许为:$(PROJECT_TEMP_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
6.Code Signing Identity:真机调试的证书选择
选1个和Bundle identifier相对应的证书
Library Search Paths:库搜索路径
Architectures:架构,设为 armv6 或 armv7
Valid Architectures:利用框架,可以设为 armv6、 armv7 或i386
Product Name:工程文件名,默许为$(TARGET_NAME)
Info.plist File:info文件路径
Build Variants:默许为normal
Other Linker Flags:其他链接标签
设为“-ObjC”
当导入的静态库使用了种别,需要设为-ObjC
iOS Deployment Target:ios部署对象
比如可以选择设为,ios3到ios5的1种版本
Prefix Header:预编头文件(比如:UtilLib/UtilLib-Prefix.pch)
Precompile Prefix Header:设为“Yes”,表示允许加入预编译头
3、workspace(工作区)
作用:管理多个工程(project),多工程联编
4、workspace多工程联编设置
1、
1.新建1个静态库工程,比如UtilLib,并生成UtilLib.h和UtilLib.m文件
2.选中需要公然的头文件,
把右边栏的Target Membership中设置为public
或则,选中工程目录target的Build Phases标签的copy headers项,在public中添加要公然的头文件
3.Architectures设为:armv6 armv7
4.Valid Architectures设为:armv6 armv7 i386
5.Build Products Path设为:$(SRCROOT)/../build
6.Per-configuration Build Products Path设为:
$(SRCROOT)/../build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
7.Per-configuration Intermediate Build Files Path设为:
$(SRCROOT)/../build/$(TARGET_NAME).build/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
8.设置安装路径:Installation Directory项
9.设置对外公然的头文件路径:Public Headers Folder Path项
10.为静态库添加依赖的shell脚本
选中工程目录target的Build Phases标签,点击由下角的Add Build Phase按钮
在弹出的菜单里选择Add run script项,然后页面中会多出1个Run Script项
在黑框里填写"$SRCROOT/mergeArmSymbols.sh"
建立对此脚本的依赖(编译静态库的后会运行此脚本)
如果编译时装备选的是iphone simulator:
则此脚本会在对应iphone device的产品目录Debug-iphoneos中,生成对device有用的.a静态库,
相反,如果装备选的是iphone device:
则此脚本会在对应iphone simulator的产品目录Debug-iphoneos中,生成对simulator有用的.a静态库
最后,此脚本调用lipo工具,把本工程生成静态库与此脚本生成的静态库合并,生成simulator和device都通用的.a文件
11.具体bash shell脚本以下:
下载右侧的图片,然后把后缀改成.sh(其实就是上面的脚本,由于博客园只能上传图片)
静态库编译后的目录结构以下:
2、
1.新建主工程,比如Nuno,添加对静态库的依赖
点击工程,在Build Phases标签的Link Binary With Libraries项中点击加号添加UtilLib.a库
选中上面的红色项,在右侧栏的Location选Relative to Project,把值设为../libs/libUtilLib.a
2.设置主工程依赖的外部头文件路径:User Header Search Paths项
$(SRCROOT)/../include
3.设置Header Search Paths为:$(SRCROOT)/../include
4.设置Library Search Paths为:$(SRCROOT)/../libs
编译运行便可实现联编
(备注:选择摹拟器iphone 5.0 simulator,编译静态库的时,终究文件会在Debug-iphonesimulator,就算成功.a文件还是红色,
这是多是xcode的bug,不会自动切换路径
由于$(BUILT_PRODUCTS_DIR)所指的位置,是build/Debug-iphonesos,不是包括终究.a文件的Debug-iphonesimulator;
选择ios Device,编译成的终究文件才在build/Debug-iphonesos下,.a文件变成非红色
所有得用mergeArmSymbols.sh脚本来解决)