1 /*
   2  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 ext.MAC = [:]
  27 
  28 MAC.canBuild = IS_MAC && IS_64
  29 if (!MAC.canBuild) return;
  30 
  31 // All desktop related packages should be built
  32 MAC.compileSwing = true;
  33 MAC.compileSWT = true;
  34 MAC.compileFXPackager = true;
  35 
  36 MAC.includeNull3d = true
  37 
  38 // Lambda for naming the generated libs
  39 MAC.library = { name -> return "lib${name}.dylib" as String }
  40 
  41 MAC.libDest = "lib"
  42 
  43 /*
  44  * Define settings for Mac compilation. If we don't find the preferred SDK
  45  * in the default location then we will use "xcodebuild" to locate a suitable SDK.
  46  * In extreme cases you can provide your own properties in your home dir to
  47  * override these settings or pass them on the command line.
  48  */
  49 def prefSdkVersion = "10.7"
  50 def defaultSdkPath = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${prefSdkVersion}.sdk";
  51 
  52 // Set the minimum API version that we require (developers do not need to override this)
  53 // Note that this is not necessarily the same as the preferred SDK version
  54 defineProperty("MACOSX_MIN_VERSION", "10.7");
  55 
  56 // Create $buildDir/mac_tools.properties file and load props from it
  57 setupTools("mac_tools",
  58     { propFile ->
  59         propFile << ""
  60         if (!file(defaultSdkPath).isDirectory()) {
  61             // Get list of all macosx sdks
  62             ByteArrayOutputStream results = new ByteArrayOutputStream();
  63             exec {
  64                 commandLine("xcodebuild", "-version", "-showsdks");
  65                 setStandardOutput(results);
  66             }
  67 
  68             BufferedReader reader = new BufferedReader(new StringReader(results.toString().trim()));
  69             // If our preferred SDK is in the list use it, else use the default
  70             String sdk = "macosx"
  71             String prefSdk = sdk + prefSdkVersion
  72             while (true) {
  73                 def line = reader.readLine();
  74                 if (line == null) break;
  75                 if (line.contains("-sdk ${prefSdk}")) {
  76                     sdk = prefSdk
  77                     break;
  78                 }
  79             }
  80 
  81             results = new ByteArrayOutputStream();
  82             exec {
  83                 commandLine("xcodebuild", "-version", "-sdk", sdk, "Path");
  84                 setStandardOutput(results);
  85             }
  86             String sdkPath = results.toString().trim();
  87             propFile << "MACOSX_SDK_PATH=" << sdkPath << "\n";
  88         }
  89     },
  90     { properties ->
  91         defineProperty("MACOSX_SDK_PATH", properties, defaultSdkPath)
  92     }
  93 )
  94 
  95 println "MACOSX_MIN_VERSION = $MACOSX_MIN_VERSION"
  96 println "MACOSX_SDK_PATH = $MACOSX_SDK_PATH"
  97 
  98 if (!file(MACOSX_SDK_PATH).isDirectory()) {
  99     throw new GradleException("FAIL: Cannot find $MACOSX_SDK_PATH")
 100 }
 101 
 102 def commonParams = [
 103         "-mmacosx-version-min=$MACOSX_MIN_VERSION",
 104         "-isysroot", "$MACOSX_SDK_PATH",
 105         "-arch", "x86_64"]
 106 
 107 def ccBaseFlags = [
 108         commonParams,
 109         "-I$JDK_HOME/include",
 110         "-I$JDK_HOME/include/darwin"].flatten()
 111 
 112 
 113 def ccFlags = [
 114         ccBaseFlags,
 115         "-std=c99",
 116         "-c",
 117         IS_DEBUG_NATIVE ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()
 118 
 119 def linkFlags = [
 120         commonParams,
 121         "-framework", "AppKit",
 122         "-framework", "ApplicationServices",
 123         "-framework", "OpenGL",
 124         "-framework", "QuartzCore",
 125         "-framework", "Security",
 126         "-dynamiclib", "-lobjc"].flatten();
 127 
 128 
 129 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
 130 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";
 131 
 132 MAC.glass = [:]
 133 MAC.glass.javahInclude = [
 134     "com/sun/glass/events/**",
 135     "com/sun/glass/ui/*",
 136     "com/sun/glass/ui/mac/*"]
 137 MAC.glass.nativeSource = file("modules/graphics/src/main/native-glass/mac")
 138 MAC.glass.compiler = compiler
 139 MAC.glass.ccFlags = [ccFlags].flatten()
 140 MAC.glass.linker = linker
 141 MAC.glass.linkFlags = [linkFlags].flatten()
 142 MAC.glass.lib = "glass"
 143 
 144 MAC.decora = [:]
 145 MAC.decora.compiler = compiler
 146 MAC.decora.ccFlags = ["-O1", "-ffast-math", "-c", ccBaseFlags].flatten()
 147 MAC.decora.linker = linker
 148 MAC.decora.linkFlags = ["-dynamiclib", commonParams].flatten()
 149 MAC.decora.lib = "decora_sse"
 150 
 151 MAC.prism = [:]
 152 MAC.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"]
 153 MAC.prism.nativeSource = file("modules/graphics/src/main/native-prism")
 154 MAC.prism.compiler = compiler
 155 MAC.prism.ccFlags = ["-O3", "-DINLINE=inline", "-c", ccBaseFlags].flatten()
 156 MAC.prism.linker = linker
 157 MAC.prism.linkFlags = ["-dynamiclib", commonParams].flatten()
 158 MAC.prism.lib = "prism_common"
 159 
 160 MAC.prismSW = [:]
 161 MAC.prismSW.javahInclude = ["com/sun/pisces/**/*"]
 162 MAC.prismSW.nativeSource = file("modules/graphics/src/main/native-prism-sw")
 163 MAC.prismSW.compiler = compiler
 164 MAC.prismSW.ccFlags = [MAC.prism.ccFlags].flatten()
 165 MAC.prismSW.linker = linker
 166 MAC.prismSW.linkFlags = [MAC.prism.linkFlags].flatten()
 167 MAC.prismSW.lib = "prism_sw"
 168 
 169 MAC.launcher = [:]
 170 MAC.launcher.compiler = compiler
 171 MAC.launcher.ccFlags = [
 172         "-std=c99",
 173         ccBaseFlags,
 174         "-framework", "Cocoa",
 175         IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten()
 176 MAC.launcher.linker = linker
 177 MAC.launcher.linkFlags = ["-ldl"]
 178 
 179 MAC.launcherlibrary = [:]
 180 MAC.launcherlibrary.compiler = compiler
 181 MAC.launcherlibrary.ccFlags = [
 182         "-c",
 183         ccBaseFlags,
 184         IS_DEBUG_NATIVE ? ["-DDEBUG", "-O0"] : ["-O3", "-DNDEBUG"]].flatten()
 185 // 10.7 doesn't have libstdc++ as an option for stdlib, so filter it out
 186 if (!(MACOSX_MIN_VERSION in ['10.7', '10.8'])) {
 187     MAC.launcherlibrary.ccFlags += "-stdlib=libstdc++"
 188 }
 189 MAC.launcherlibrary.linker = linker
 190 MAC.launcherlibrary.linkFlags = ["-ldl", "-dynamiclib",
 191         "-framework", "Cocoa",
 192         "-stdlib=libstdc++"]
 193 
 194 MAC.iio = [:]
 195 MAC.iio.javahInclude = ["com/sun/javafx/iio/**/*"]
 196 MAC.iio.nativeSource = [
 197     file("modules/graphics/src/main/native-iio"),
 198     file("modules/graphics/src/main/native-iio/libjpeg7")]
 199 MAC.iio.compiler = compiler
 200 MAC.iio.ccFlags = [ccFlags].flatten()
 201 MAC.iio.linker = linker
 202 MAC.iio.linkFlags = [linkFlags].flatten()
 203 MAC.iio.lib = "javafx_iio"
 204 
 205 MAC.prismES2 = [:]
 206 MAC.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
 207 MAC.prismES2.nativeSource = [
 208     file("modules/graphics/src/main/native-prism-es2"),
 209     file("modules/graphics/src/main/native-prism-es2/GL"),
 210     file("modules/graphics/src/main/native-prism-es2/macosx")
 211 ]
 212 MAC.prismES2.compiler = compiler
 213 MAC.prismES2.ccFlags = ["-DMACOSX", ccFlags].flatten()
 214 MAC.prismES2.linker = linker
 215 MAC.prismES2.linkFlags = [linkFlags].flatten()
 216 MAC.prismES2.lib = "prism_es2"
 217 
 218 def closedDir = file("$projectDir/../rt-closed")
 219 MAC.font = [:]
 220 MAC.font.javahInclude = [
 221         "com/sun/javafx/font/**/*",
 222         "com/sun/javafx/text/**/*"]
 223 MAC.font.nativeSource = [file("modules/graphics/src/main/native-font")]
 224 MAC.font.compiler = compiler
 225 MAC.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
 226 MAC.font.linker = linker
 227 MAC.font.linkFlags = [linkFlags].flatten()
 228 MAC.font.lib = "javafx_font"
 229 
 230 MAC.fontT2K = [:]
 231 MAC.fontT2K.javahInclude = ["com/sun/javafx/font/t2k/**/*"]
 232 MAC.fontT2K.nativeSource = [
 233         file("$closedDir/javafx-font-t2k-native/src"),
 234         file("$closedDir/javafx-font-t2k-native/src/layout")]
 235 MAC.fontT2K.compiler = compiler
 236 MAC.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten()
 237 MAC.fontT2K.linker = linker
 238 MAC.fontT2K.linkFlags = [linkFlags].flatten()
 239 MAC.fontT2K.lib = "javafx_font_t2k"
 240 
 241 MAC.media = [:]
 242 MAC.media.compiler = compiler
 243 MAC.media.linker = linker
 244 MAC.media.lib = "libtool"