Created
June 19, 2014 16:02
-
-
Save unixmonkey/55e3381804aa419c536c to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
* Copyright (c) 2007-2014 by Apple Inc.. All rights reserved. | |
* | |
* @APPLE_LICENSE_HEADER_START@ | |
* | |
* This file contains Original Code and/or Modifications of Original Code | |
* as defined in and that are subject to the Apple Public Source License | |
* Version 2.0 (the 'License'). You may not use this file except in | |
* compliance with the License. Please obtain a copy of the License at | |
* http://www.opensource.apple.com/apsl/ and read it before using this | |
* file. | |
* | |
* The Original Code and all software distributed under the License are | |
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
* Please see the License for the specific language governing rights and | |
* limitations under the License. | |
* | |
* @APPLE_LICENSE_HEADER_END@ | |
*/ | |
#ifndef __AVAILABILITY__ | |
#define __AVAILABILITY__ | |
/* | |
These macros are for use in OS header files. They enable function prototypes | |
and Objective-C methods to be tagged with the OS version in which they | |
were first available; and, if applicable, the OS version in which they | |
became deprecated. | |
The desktop Mac OS X and iOS each have different version numbers. | |
The __OSX_AVAILABLE_STARTING() macro allows you to specify both the desktop | |
and iOS version numbers. For instance: | |
__OSX_AVAILABLE_STARTING(__MAC_10_2,__IPHONE_2_0) | |
means the function/method was first available on Mac OS X 10.2 on the desktop | |
and first available in iOS 2.0 on the iPhone. | |
If a function is available on one platform, but not the other a _NA (not | |
applicable) parameter is used. For instance: | |
__OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_NA) | |
means that the function/method was first available on Mac OS X 10.3, and it | |
currently not implemented on the iPhone. | |
At some point, a function/method may be deprecated. That means Apple | |
recommends applications stop using the function, either because there is a | |
better replacement or the functionality is being phased out. Deprecated | |
functions/methods can be tagged with a __OSX_AVAILABLE_BUT_DEPRECATED() | |
macro which specifies the OS version where the function became available | |
as well as the OS version in which it became deprecated. For instance: | |
__OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_0,__MAC_10_5,__IPHONE_NA,__IPHONE_NA) | |
means that the function/method was introduced in Mac OS X 10.0, then | |
became deprecated beginning in Mac OS X 10.5. On iOS the function | |
has never been available. | |
For these macros to function properly, a program must specify the OS version range | |
it is targeting. The min OS version is specified as an option to the compiler: | |
-mmacosx-version-min=10.x when building for Mac OS X, and -miphoneos-version-min=y.z | |
when building for the iPhone. The upper bound for the OS version is rarely needed, | |
but it can be set on the command line via: -D__MAC_OS_X_VERSION_MAX_ALLOWED=10x0 for | |
Mac OS X and __IPHONE_OS_VERSION_MAX_ALLOWED = y0z00 for iOS. | |
Examples: | |
A function available in Mac OS X 10.5 and later, but not on the phone: | |
extern void mymacfunc() __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_NA); | |
An Objective-C method in Mac OS X 10.5 and later, but not on the phone: | |
@interface MyClass : NSObject | |
-(void) mymacmethod __OSX_AVAILABLE_STARTING(__MAC_10_5,__IPHONE_NA); | |
@end | |
An enum available on the phone, but not available on Mac OS X: | |
#if __IPHONE_OS_VERSION_MIN_REQUIRED | |
enum { myEnum = 1 }; | |
#endif | |
Note: this works when targeting the Mac OS X platform because | |
__IPHONE_OS_VERSION_MIN_REQUIRED is undefined which evaluates to zero. | |
An enum with values added in different iPhoneOS versions: | |
enum { | |
myX = 1, // Usable on iPhoneOS 2.1 and later | |
myY = 2, // Usable on iPhoneOS 3.0 and later | |
myZ = 3, // Usable on iPhoneOS 3.0 and later | |
... | |
Note: you do not want to use #if with enumeration values | |
when a client needs to see all values at compile time | |
and use runtime logic to only use the viable values. | |
It is also possible to use the *_VERSION_MIN_REQUIRED in source code to make one | |
source base that can be compiled to target a range of OS versions. It is best | |
to not use the _MAC_* and __IPHONE_* macros for comparisons, but rather their values. | |
That is because you might get compiled on an old OS that does not define a later | |
OS version macro, and in the C preprocessor undefined values evaluate to zero | |
in expresssions, which could cause the #if expression to evaluate in an unexpected | |
way. | |
#ifdef __MAC_OS_X_VERSION_MIN_REQUIRED | |
// code only compiled when targeting Mac OS X and not iPhone | |
// note use of 1050 instead of __MAC_10_5 | |
#if __MAC_OS_X_VERSION_MIN_REQUIRED < 1050 | |
// code in here might run on pre-Leopard OS | |
#else | |
// code here can assume Leopard or later | |
#endif | |
#endif | |
*/ | |
#define __MAC_10_0 1000 | |
#define __MAC_10_1 1010 | |
#define __MAC_10_2 1020 | |
#define __MAC_10_3 1030 | |
#define __MAC_10_4 1040 | |
#define __MAC_10_5 1050 | |
#define __MAC_10_6 1060 | |
#define __MAC_10_7 1070 | |
#define __MAC_10_8 1080 | |
#define __MAC_10_9 1090 | |
#define __MAC_10_10 101000 | |
/* __MAC_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */ | |
#define __IPHONE_2_0 20000 | |
#define __IPHONE_2_1 20100 | |
#define __IPHONE_2_2 20200 | |
#define __IPHONE_3_0 30000 | |
#define __IPHONE_3_1 30100 | |
#define __IPHONE_3_2 30200 | |
#define __IPHONE_4_0 40000 | |
#define __IPHONE_4_1 40100 | |
#define __IPHONE_4_2 40200 | |
#define __IPHONE_4_3 40300 | |
#define __IPHONE_5_0 50000 | |
#define __IPHONE_5_1 50100 | |
#define __IPHONE_6_0 60000 | |
#define __IPHONE_6_1 60100 | |
#define __IPHONE_7_0 70000 | |
#define __IPHONE_7_1 70100 | |
#define __IPHONE_8_0 80000 | |
/* __IPHONE_NA is not defined to a value but is uses as a token by macros to indicate that the API is unavailable */ | |
#include <AvailabilityInternal.h> | |
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED | |
#define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_ios | |
#define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ | |
__AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep | |
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ | |
__AVAILABILITY_INTERNAL##_iosIntro##_DEP##_iosDep##_MSG(_msg) | |
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) | |
#define __OSX_AVAILABLE_STARTING(_osx, _ios) __AVAILABILITY_INTERNAL##_osx | |
#define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) \ | |
__AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep | |
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) \ | |
__AVAILABILITY_INTERNAL##_osxIntro##_DEP##_osxDep##_MSG(_msg) | |
#else | |
#define __OSX_AVAILABLE_STARTING(_osx, _ios) | |
#define __OSX_AVAILABLE_BUT_DEPRECATED(_osxIntro, _osxDep, _iosIntro, _iosDep) | |
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(_osxIntro, _osxDep, _iosIntro, _iosDep, _msg) | |
#endif | |
#if defined(__has_feature) | |
#if __has_feature(attribute_availability_with_message) | |
#define __OS_AVAILABILITY(_target, _availability) __attribute__((availability(_target,_availability))) | |
#define __OS_AVAILABILITY_MSG(_target, _availability, _msg) __attribute__((availability(_target,_availability,message=_msg))) | |
#else | |
#define __OS_AVAILABILITY(_target, _availability) | |
#define __OS_AVAILABILITY_MSG(_target, _availability, _msg) | |
#endif | |
#else | |
#define __OS_AVAILABILITY(_target, _availability) | |
#define __OS_AVAILABILITY_MSG(_target, _availability, _msg) | |
#endif | |
/* for use to document app extension usage */ | |
#if defined(__has_feature) | |
#if __has_feature(attribute_availability_app_extension) | |
#define __OSX_EXTENSION_UNAVAILABLE(_msg) __OS_AVAILABILITY_MSG(macosx_app_extension,unavailable,_msg) | |
#define __IOS_EXTENSION_UNAVAILABLE(_msg) __OS_AVAILABILITY_MSG(ios_app_extension,unavailable,_msg) | |
#else | |
#define __OSX_EXTENSION_UNAVAILABLE(_msg) | |
#define __IOS_EXTENSION_UNAVAILABLE(_msg) | |
#endif | |
#else | |
#define __OSX_EXTENSION_UNAVAILABLE(_msg) | |
#define __IOS_EXTENSION_UNAVAILABLE(_msg) | |
#endif | |
#define __OS_EXTENSION_UNAVAILABLE(_msg) __OSX_EXTENSION_UNAVAILABLE(_msg) __IOS_EXTENSION_UNAVAILABLE(_msg) | |
#endif /* __AVAILABILITY__ */ |
This file contains 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
gem install amatch -v '0.3.0' | |
Building native extensions. This could take a while... | |
ERROR: Error installing amatch: | |
ERROR: Failed to build gem native extension. | |
/Users/djones/.rubies/ruby-2.1.2/bin/ruby extconf.rb | |
creating Makefile | |
make "DESTDIR=" clean | |
make "DESTDIR=" | |
compiling amatch_ext.c | |
couldn't understand kern.osversion `14.0.0' | |
In file included from /usr/include/stdio.h:65, | |
from /Users/djones/.rubies/ruby-2.1.2/include/ruby-2.1.0/ruby/defines.h:26, | |
from /Users/djones/.rubies/ruby-2.1.2/include/ruby-2.1.0/ruby/ruby.h:29, | |
from /Users/djones/.rubies/ruby-2.1.2/include/ruby-2.1.0/ruby.h:33, | |
from amatch_ext.c:1: | |
/usr/include/Availability.h:174:44: error: missing binary operator before token "(" | |
/usr/include/Availability.h:184:44: error: missing binary operator before token "(" | |
make: *** [amatch_ext.o] Error 1 | |
make failed, exit code 2 | |
Gem files will remain installed in /Users/djones/.gem/ruby/2.1.2/gems/amatch-0.3.0 for inspection. | |
Results logged to /Users/djones/.gem/ruby/2.1.2/extensions/x86_64-darwin-13/2.1.0-static/amatch-0.3.0/gem_make.out |
This file contains 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
I ran into this issue building a gem with c-bindings on OSX 10.10 Yosemite | |
Turns out the Apple Availability.h header file uses bad syntax (the &&). | |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61407 | |
I changed it to a nested if and was able to complile the amatch gem successfully |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment