1 /*
   2  * Copyright (c) 2013, 2018, 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.LINUX = [:]
  27 
  28 // Declare whether this particular target file applies to the current system
  29 LINUX.canBuild = IS_LINUX;
  30 if (!LINUX.canBuild) return;
  31 
  32 // All desktop related packages should be built
  33 LINUX.compileSwing = true;
  34 LINUX.compileSWT = true;
  35 LINUX.compileFXPackager = true;
  36 
  37 // Libraries end up in the sdk/rt/lib/$OS_ARCH directory for Linux
  38 LINUX.libDest = "lib/$OS_ARCH"
  39 
  40 // Lambda for naming the generated libs
  41 LINUX.library = { name -> return "lib${name}.so" as String }
  42 
  43 // A set of common parameters to use for both compiling and linking
  44 def commonFlags = [
  45         "-fno-strict-aliasing", "-fPIC", "-fno-omit-frame-pointer", // optimization flags
  46         "-W", "-Wall", "-Wno-unused", "-Wno-parentheses", "-Werror=implicit-function-declaration"] // warning flags
  47 
  48 if (!IS_64) {
  49     commonFlags += "-m32"
  50 }
  51 
  52 // Specify the compilation parameters and link parameters
  53 def ccFlags = [
  54         commonFlags, "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c",
  55         "-ffunction-sections", "-fdata-sections",
  56         IS_DEBUG_NATIVE ? ["-ggdb", "-DVERBOSE"] : ["-O2", "-DNDEBUG"]].flatten()
  57 //ccFlags.addAll(["-Wnon-virtual-dtor", "-Woverloaded-virtual", "-std=c++0x"])
  58 def linkFlags = ["-static-libgcc", "-static-libstdc++", "-shared", commonFlags,
  59                  "-Wl,--gc-sections"].flatten()
  60 def defaultLinkFlags = linkFlags.flatten()
  61 
  62 // Create $buildDir/linux_tools.properties file and load props from it
  63 setupTools("linux_tools",
  64     { propFile ->
  65         ByteArrayOutputStream results = new ByteArrayOutputStream();
  66         exec {
  67             commandLine("pkg-config", "--cflags", "gtk+-2.0", "gthread-2.0", "xtst");
  68             setStandardOutput(results);
  69         }
  70         propFile << "cflags=" << results.toString().trim() << "\n";
  71 
  72         results = new ByteArrayOutputStream();
  73         exec {
  74             commandLine "pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst"
  75             standardOutput = results
  76         }
  77         propFile << "libs=" << results.toString().trim();
  78     },
  79     { properties ->
  80         ccFlags.addAll(properties.getProperty("cflags").split(" "))
  81         linkFlags.addAll(properties.getProperty("libs").split(" "))
  82     }
  83 )
  84 
  85 def pangoCCFlags = ["-D_ENABLE_PANGO"];
  86 def pangoLinkFlags = [];
  87 setupTools("linux_pango_tools",
  88     { propFile ->
  89         ByteArrayOutputStream results = new ByteArrayOutputStream();
  90         exec {
  91             commandLine "pkg-config", "--cflags", "pangoft2"
  92             standardOutput = results
  93         }
  94         propFile << "cflags=" << results.toString().trim() << "\n";
  95 
  96         results = new ByteArrayOutputStream();
  97         exec {
  98             commandLine "pkg-config", "--libs", "pangoft2"
  99             standardOutput = results
 100         }
 101         propFile << "libs=" << results.toString().trim();
 102     },
 103     { properties ->
 104         pangoCCFlags.addAll(properties.getProperty("cflags").split(" "))
 105         pangoLinkFlags.addAll(properties.getProperty("libs").split(" "))
 106     }
 107 )
 108 
 109 def freetypeCCFlags = [ext.IS_COMPILE_PANGO ? "-D_ENABLE_PANGO" :
 110                        ext.IS_COMPILE_HARFBUZZ ? "-D_ENABLE_HARFBUZZ" : ""]
 111 def freetypeLinkFlags = []
 112 setupTools("linux_freetype_tools",
 113     { propFile ->
 114         ByteArrayOutputStream results = new ByteArrayOutputStream();
 115         exec {
 116             commandLine "pkg-config", "--cflags", "freetype2"
 117             standardOutput = results
 118         }
 119         propFile << "cflags=" << results.toString().trim() << "\n";
 120 
 121         results = new ByteArrayOutputStream();
 122         exec {
 123             commandLine "pkg-config", "--libs", "freetype2"
 124             standardOutput = results
 125         }
 126         propFile << "libs=" << results.toString().trim();
 127     },
 128     { properties ->
 129         freetypeCCFlags.addAll(properties.getProperty("cflags").split(" "))
 130         freetypeLinkFlags.addAll(properties.getProperty("libs").split(" "))
 131     }
 132 )
 133 
 134 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
 135 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";
 136 
 137 LINUX.glass = [:]
 138 LINUX.glass.javahInclude = [
 139     "com/sun/glass/events/**",
 140     "com/sun/glass/ui/*",
 141     "com/sun/glass/ui/gtk/*"]
 142 LINUX.glass.nativeSource = file("modules/graphics/src/main/native-glass/gtk")
 143 LINUX.glass.compiler = compiler
 144 LINUX.glass.ccFlags = [ccFlags, "-Werror"].flatten()
 145 LINUX.glass.linker = linker
 146 LINUX.glass.linkFlags = [linkFlags].flatten()
 147 LINUX.glass.lib = "glass"
 148 
 149 LINUX.decora = [:]
 150 LINUX.decora.compiler = compiler
 151 LINUX.decora.ccFlags = [ccFlags, "-ffast-math"].flatten()
 152 LINUX.decora.linker = linker
 153 LINUX.decora.linkFlags = [linkFlags].flatten()
 154 LINUX.decora.lib = "decora_sse"
 155 
 156 LINUX.prism = [:]
 157 LINUX.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"]
 158 LINUX.prism.nativeSource = file("modules/graphics/src/main/native-prism")
 159 LINUX.prism.compiler = compiler
 160 LINUX.prism.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 161 LINUX.prism.linker = linker
 162 LINUX.prism.linkFlags = [linkFlags].flatten()
 163 LINUX.prism.lib = "prism_common"
 164 
 165 LINUX.prismSW = [:]
 166 LINUX.prismSW.javahInclude = ["com/sun/pisces/**/*"]
 167 LINUX.prismSW.nativeSource = file("modules/graphics/src/main/native-prism-sw")
 168 LINUX.prismSW.compiler = compiler
 169 LINUX.prismSW.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 170 LINUX.prismSW.linker = linker
 171 LINUX.prismSW.linkFlags = [linkFlags].flatten()
 172 LINUX.prismSW.lib = "prism_sw"
 173 
 174 LINUX.launcher = [:]
 175 LINUX.launcher.compiler = compiler
 176 LINUX.launcher.ccFlags = ["-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c"]
 177 LINUX.launcher.linker = linker
 178 LINUX.launcher.linkFlags = ["-ldl"]
 179 if (!IS_64) {
 180     LINUX.launcher.ccFlags += "-m32"
 181     LINUX.launcher.linkFlags += "-m32"
 182 }
 183 
 184 LINUX.launcherlibrary = [:]
 185 LINUX.launcherlibrary.compiler = compiler
 186 LINUX.launcherlibrary.ccFlags = ["-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c", "-fPIC",
 187 "-std=gnu++98", "-ffunction-sections", "-fdata-sections"]
 188 LINUX.launcherlibrary.linker = linker
 189 LINUX.launcherlibrary.linkFlags = ["-ldl", "-lpthread", "-shared", "-static-libgcc", "-static-libstdc++", "-Wl,--gc-sections"]
 190 if (!IS_64) {
 191     LINUX.launcherlibrary.ccFlags += "-m32"
 192     LINUX.launcherlibrary.linkFlags += "-m32"
 193 }
 194 
 195 LINUX.iio = [:]
 196 LINUX.iio.javahInclude = ["com/sun/javafx/iio/**/*"]
 197 LINUX.iio.nativeSource = [
 198     file("modules/graphics/src/main/native-iio"),
 199     file("modules/graphics/src/main/native-iio/libjpeg7")]
 200 LINUX.iio.compiler = compiler
 201 LINUX.iio.ccFlags = [ccFlags].flatten()
 202 LINUX.iio.linker = linker
 203 LINUX.iio.linkFlags = [linkFlags].flatten()
 204 LINUX.iio.lib = "javafx_iio"
 205 
 206 LINUX.prismES2 = [:]
 207 LINUX.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
 208 LINUX.prismES2.nativeSource = [
 209     file("modules/graphics/src/main/native-prism-es2"),
 210     file("modules/graphics/src/main/native-prism-es2/GL"),
 211     file("modules/graphics/src/main/native-prism-es2/x11")
 212 ]
 213 LINUX.prismES2.compiler = compiler
 214 LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
 215 LINUX.prismES2.linker = linker
 216 LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
 217 LINUX.prismES2.lib = "prism_es2"
 218 
 219 def closedDir = file("$projectDir/../rt-closed")
 220 LINUX.font = [:]
 221 LINUX.font.javahInclude = [
 222      "com/sun/javafx/font/**/*",
 223      "com/sun/javafx/text/**/*"]
 224 LINUX.font.compiler = compiler
 225 LINUX.font.nativeSource = [file("modules/graphics/src/main/native-font")]
 226 LINUX.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
 227 LINUX.font.linker = linker
 228 LINUX.font.linkFlags = [linkFlags].flatten()
 229 LINUX.font.lib = "javafx_font"
 230 
 231 LINUX.fontT2K = [:]
 232 LINUX.fontT2K.javahInclude = ["com/sun/javafx/font/t2k/**/*"]
 233 LINUX.fontT2K.nativeSource = [
 234         file("$closedDir/javafx-font-t2k-native/src"),
 235         file("$closedDir/javafx-font-t2k-native/src/layout")]
 236 LINUX.fontT2K.compiler = compiler
 237 LINUX.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten()
 238 LINUX.fontT2K.linker = linker
 239 LINUX.fontT2K.linkFlags = [linkFlags].flatten()
 240 LINUX.fontT2K.lib = "javafx_font_t2k"
 241 
 242 LINUX.fontFreetype = [:]
 243 LINUX.fontFreetype.javahInclude = ["com/sun/javafx/font/freetype/OSFreetype.class"]
 244 LINUX.fontFreetype.nativeSource = ["src/main/native-font/freetype.c"]
 245 LINUX.fontFreetype.compiler = compiler
 246 LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
 247 LINUX.fontFreetype.linker = linker
 248 LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
 249 LINUX.fontFreetype.lib = "javafx_font_freetype"
 250 
 251 LINUX.fontPango = [:]
 252 LINUX.fontPango.javahInclude = ["com/sun/javafx/font/freetype/OSPango.class"]
 253 LINUX.fontPango.nativeSource = ["src/main/native-font/pango.c"]
 254 LINUX.fontPango.compiler = compiler
 255 LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
 256 LINUX.fontPango.linker = linker
 257 LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
 258 LINUX.fontPango.lib = "javafx_font_pango"
 259 
 260 LINUX.media = [:]
 261 LINUX.media.compiler = compiler
 262 LINUX.media.linker = linker
 263 LINUX.media.lib = "ar"
 264 
 265 LINUX.webkit = [:]
 266 LINUX.webkit.compiler = compiler
 267 LINUX.webkit.linker = linker
 268 LINUX.webkit.ccFlags = commonFlags.flatten()
 269 LINUX.webkit.linkFlags = defaultLinkFlags.flatten()