1 /*
   2  * Copyright (c) 2013, 2017, 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 lib/$OS_ARCH directory for Linux
  38 LINUX.libDest = "lib"
  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         "-Wextra", "-Wall", "-Wformat-security", "-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         IS_DEBUG_NATIVE ? ["-ggdb", "-DVERBOSE"] : ["-O2", "-DNDEBUG"]].flatten()
  56 def ccFlagsGTK3 = ccFlags
  57 //ccFlags.addAll(["-Wnon-virtual-dtor", "-Woverloaded-virtual", "-std=c++0x"])
  58 def linkFlags = ["-shared", commonFlags].flatten()
  59 
  60 if (IS_DEBUG_NATIVE) {
  61     linkFlags += "-g"
  62 }
  63 
  64 def gtk2CCFlags = [  ];
  65 def gtk3CCFlags = [ "-Wno-deprecated-declarations" ];
  66 def gtk2LinkFlags = [ ];
  67 def gtk3LinkFlags = [ ];
  68 LINUX.buildGTK3 = true
  69 
  70 // Create $buildDir/linux_tools.properties file and load props from it
  71 setupTools("linux_gtk2",
  72     { propFile ->
  73         ByteArrayOutputStream results1 = new ByteArrayOutputStream();
  74         exec {
  75             commandLine("pkg-config", "--cflags", "gtk+-2.0", "gthread-2.0", "xtst")
  76             setStandardOutput(results1);
  77         }
  78         propFile << "cflagsGTK2=" << results1.toString().trim() << "\n";
  79 
  80         ByteArrayOutputStream results3 = new ByteArrayOutputStream();
  81         exec {
  82             commandLine("pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst")
  83             setStandardOutput(results3);
  84         }
  85         propFile << "libsGTK2=" << results3.toString().trim()  << "\n";
  86     },
  87     { properties ->
  88         gtk2CCFlags.addAll(properties.getProperty("cflagsGTK2").split(" "))
  89         gtk2LinkFlags.addAll(properties.getProperty("libsGTK2").split(" "))
  90     }
  91 )
  92 
  93 setupTools("linux_gtk3",
  94     { propFile ->
  95         ByteArrayOutputStream results2 = new ByteArrayOutputStream();
  96         exec {
  97             commandLine("pkg-config", "--cflags", "gtk+-3.0", "gthread-2.0", "xtst")
  98             setStandardOutput(results2);
  99             ignoreExitValue(true)
 100         }
 101         propFile << "cflagsGTK3=" << results2.toString().trim() << "\n";
 102 
 103         ByteArrayOutputStream results4 = new ByteArrayOutputStream();
 104         exec {
 105             commandLine("pkg-config", "--libs", "gtk+-3.0", "gthread-2.0", "xtst")
 106             setStandardOutput(results4);
 107             ignoreExitValue(true)
 108         }
 109         propFile << "libsGTK3=" << results4.toString().trim()  << "\n";
 110 
 111     },
 112     { properties ->
 113         String ccflags =  properties.getProperty("cflagsGTK3")
 114         String ldflags =  properties.getProperty("libsGTK3")
 115         if (ccflags != null && ! ccflags.equals("")) {
 116             gtk3CCFlags.addAll(properties.getProperty("cflagsGTK3").split(" "))
 117             gtk3LinkFlags.addAll(properties.getProperty("libsGTK3").split(" "))
 118         } else {
 119             logger.info("Warning: GTK3 development packages not found, not building GTK3 support");
 120             LINUX.buildGTK3 = false
 121         }
 122     }
 123 )
 124 
 125 def pangoCCFlags = ["-D_ENABLE_PANGO"];
 126 def pangoLinkFlags = [];
 127 setupTools("linux_pango_tools",
 128     { propFile ->
 129         ByteArrayOutputStream results = new ByteArrayOutputStream();
 130         exec {
 131             commandLine "pkg-config", "--cflags", "pangoft2"
 132             standardOutput = results
 133         }
 134         propFile << "cflags=" << results.toString().trim() << "\n";
 135 
 136         results = new ByteArrayOutputStream();
 137         exec {
 138             commandLine "pkg-config", "--libs", "pangoft2"
 139             standardOutput = results
 140         }
 141         propFile << "libs=" << results.toString().trim();
 142     },
 143     { properties ->
 144         pangoCCFlags.addAll(properties.getProperty("cflags").split(" "))
 145         pangoLinkFlags.addAll(properties.getProperty("libs").split(" "))
 146     }
 147 )
 148 
 149 def freetypeCCFlags = [ext.IS_COMPILE_PANGO ? "-D_ENABLE_PANGO" :
 150                        ext.IS_COMPILE_HARFBUZZ ? "-D_ENABLE_HARFBUZZ" : ""]
 151 def freetypeLinkFlags = []
 152 setupTools("linux_freetype_tools",
 153     { propFile ->
 154         ByteArrayOutputStream results = new ByteArrayOutputStream();
 155         exec {
 156             commandLine "pkg-config", "--cflags", "freetype2"
 157             standardOutput = results
 158         }
 159         propFile << "cflags=" << results.toString().trim() << "\n";
 160 
 161         results = new ByteArrayOutputStream();
 162         exec {
 163             commandLine "pkg-config", "--libs", "freetype2"
 164             standardOutput = results
 165         }
 166         propFile << "libs=" << results.toString().trim();
 167     },
 168     { properties ->
 169         freetypeCCFlags.addAll(properties.getProperty("cflags").split(" "))
 170         freetypeLinkFlags.addAll(properties.getProperty("libs").split(" "))
 171     }
 172 )
 173 
 174 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
 175 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";
 176 
 177 LINUX.glass = [:]
 178 LINUX.glass.variants = ["glass", "glassgtk2"]
 179 if (LINUX.buildGTK3) {
 180     logger.info("Building libglassgtk3")
 181     LINUX.glass.variants += "glassgtk3"
 182 } else {
 183     logger.warn("NOT Building libglassgtk3")
 184 }
 185 
 186 FileTree ft_gtk_launcher = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 187     include("**/launcher.c")
 188 }
 189 
 190 FileTree ft_gtk = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 191     exclude("**/launcher.c")
 192 }
 193 
 194 LINUX.glass.glass = [:]
 195 LINUX.glass.glass.nativeSource = ft_gtk_launcher.getFiles()
 196 LINUX.glass.glass.compiler = compiler
 197 LINUX.glass.glass.ccFlags = [ccFlags, gtk2CCFlags,  "-Werror"].flatten()
 198 LINUX.glass.glass.linker = linker
 199 LINUX.glass.glass.linkFlags = [linkFlags, "-lX11", "-ldl" ].flatten()
 200 LINUX.glass.glass.lib = "glass"
 201 
 202 LINUX.glass.glassgtk2 = [:]
 203 LINUX.glass.glassgtk2.nativeSource =  ft_gtk.getFiles()
 204 LINUX.glass.glassgtk2.compiler = compiler
 205 LINUX.glass.glassgtk2.ccFlags = [ccFlags, gtk2CCFlags, "-Werror"].flatten()
 206 LINUX.glass.glassgtk2.linker = linker
 207 LINUX.glass.glassgtk2.linkFlags = [linkFlags, gtk2LinkFlags ].flatten()
 208 LINUX.glass.glassgtk2.lib = "glassgtk2"
 209 
 210 LINUX.glass.glassgtk3 = [:]
 211 LINUX.glass.glassgtk3.nativeSource =  ft_gtk.getFiles()
 212 LINUX.glass.glassgtk3.compiler = compiler
 213 LINUX.glass.glassgtk3.ccFlags = [ccFlags, gtk3CCFlags, "-Werror"].flatten()
 214 LINUX.glass.glassgtk3.linker = linker
 215 LINUX.glass.glassgtk3.linkFlags = [linkFlags, gtk3LinkFlags ].flatten()
 216 LINUX.glass.glassgtk3.lib = "glassgtk3"
 217 
 218 LINUX.decora = [:]
 219 LINUX.decora.compiler = compiler
 220 LINUX.decora.ccFlags = [ccFlags, "-ffast-math"].flatten()
 221 LINUX.decora.linker = linker
 222 LINUX.decora.linkFlags = [linkFlags].flatten()
 223 LINUX.decora.lib = "decora_sse"
 224 
 225 LINUX.prism = [:]
 226 LINUX.prism.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism")
 227 LINUX.prism.compiler = compiler
 228 LINUX.prism.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 229 LINUX.prism.linker = linker
 230 LINUX.prism.linkFlags = [linkFlags].flatten()
 231 LINUX.prism.lib = "prism_common"
 232 
 233 LINUX.prismSW = [:]
 234 LINUX.prismSW.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism-sw")
 235 LINUX.prismSW.compiler = compiler
 236 LINUX.prismSW.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 237 LINUX.prismSW.linker = linker
 238 LINUX.prismSW.linkFlags = [linkFlags].flatten()
 239 LINUX.prismSW.lib = "prism_sw"
 240 
 241 LINUX.launcher = [:]
 242 LINUX.launcher.compiler = compiler
 243 LINUX.launcher.ccFlags = ["-Wextra", "-Wformat", "-Wformat-security", "-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c"]
 244 LINUX.launcher.linker = linker
 245 LINUX.launcher.linkFlags = ["-ldl", "-lX11"]
 246 if (!IS_64) {
 247     LINUX.launcher.ccFlags += "-m32"
 248     LINUX.launcher.linkFlags += "-m32"
 249 }
 250 
 251 LINUX.launcherlibrary = [:]
 252 LINUX.launcherlibrary.compiler = compiler
 253 LINUX.launcherlibrary.ccFlags = ["-Wextra", "-Wformat", "-Wformat-security", "-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c", "-fPIC"]
 254 LINUX.launcherlibrary.linker = linker
 255 LINUX.launcherlibrary.linkFlags = ["-ldl", "-lpthread", "-shared", "-lX11"]
 256 if (!IS_64) {
 257     LINUX.launcherlibrary.ccFlags += "-m32"
 258     LINUX.launcherlibrary.linkFlags += "-m32"
 259 }
 260 
 261 LINUX.iio = [:]
 262 LINUX.iio.nativeSource = [
 263     file("${project("graphics").projectDir}/src/main/native-iio"),
 264     file("${project("graphics").projectDir}/src/main/native-iio/libjpeg7")]
 265 LINUX.iio.compiler = compiler
 266 LINUX.iio.ccFlags = [ccFlags].flatten()
 267 LINUX.iio.linker = linker
 268 LINUX.iio.linkFlags = [linkFlags].flatten()
 269 LINUX.iio.lib = "javafx_iio"
 270 
 271 LINUX.prismES2 = [:]
 272 LINUX.prismES2.nativeSource = [
 273     file("${project("graphics").projectDir}/src/main/native-prism-es2"),
 274     file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
 275     file("${project("graphics").projectDir}/src/main/native-prism-es2/x11")
 276 ]
 277 LINUX.prismES2.compiler = compiler
 278 LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
 279 LINUX.prismES2.linker = linker
 280 LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
 281 LINUX.prismES2.lib = "prism_es2"
 282 
 283 def closedDir = file("$projectDir/../rt-closed")
 284 LINUX.font = [:]
 285 LINUX.font.compiler = compiler
 286 LINUX.font.nativeSource = [file("${project("graphics").projectDir}/src/main/native-font")]
 287 LINUX.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
 288 LINUX.font.linker = linker
 289 LINUX.font.linkFlags = [linkFlags].flatten()
 290 LINUX.font.lib = "javafx_font"
 291 
 292 LINUX.fontT2K = [:]
 293 LINUX.fontT2K.nativeSource = [
 294         file("$closedDir/javafx-font-t2k-native/src"),
 295         file("$closedDir/javafx-font-t2k-native/src/layout")]
 296 LINUX.fontT2K.compiler = compiler
 297 LINUX.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten()
 298 LINUX.fontT2K.linker = linker
 299 LINUX.fontT2K.linkFlags = [linkFlags].flatten()
 300 LINUX.fontT2K.lib = "javafx_font_t2k"
 301 
 302 LINUX.fontFreetype = [:]
 303 LINUX.fontFreetype.nativeSource = ["src/main/native-font/freetype.c"]
 304 LINUX.fontFreetype.compiler = compiler
 305 LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
 306 LINUX.fontFreetype.linker = linker
 307 LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
 308 LINUX.fontFreetype.lib = "javafx_font_freetype"
 309 
 310 LINUX.fontPango = [:]
 311 LINUX.fontPango.nativeSource = ["src/main/native-font/pango.c"]
 312 LINUX.fontPango.compiler = compiler
 313 LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
 314 LINUX.fontPango.linker = linker
 315 LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
 316 LINUX.fontPango.lib = "javafx_font_pango"
 317 
 318 LINUX.media = [:]
 319 LINUX.media.compiler = compiler
 320 LINUX.media.linker = linker
 321 LINUX.media.ar = "ar"