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 
  36 // Libraries end up in the lib/$OS_ARCH directory for Linux
  37 LINUX.libDest = "lib"
  38 
  39 // Lambda for naming the generated libs
  40 LINUX.library = { name -> return "lib${name}.so" as String }
  41 
  42 // A set of common parameters to use for both compiling and linking
  43 def commonFlags = [
  44         "-fno-strict-aliasing", "-fPIC", "-fno-omit-frame-pointer", // optimization flags
  45         "-Wextra", "-Wall", "-Wformat-security", "-Wno-unused", "-Wno-parentheses", "-Werror=implicit-function-declaration"] // warning flags
  46 
  47 if (!IS_64) {
  48     commonFlags += "-m32"
  49 }
  50 
  51 // Specify the compilation parameters and link parameters
  52 def ccFlags = [
  53         commonFlags, "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c",
  54         "-ffunction-sections", "-fdata-sections",
  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 = ["-static-libgcc", "-static-libstdc++", "-shared", commonFlags,
  59                  "-Wl,--gc-sections"].flatten()
  60 
  61 if (IS_DEBUG_NATIVE) {
  62     linkFlags += "-g"
  63 }
  64 
  65 def toolchainDir
  66 if (hasProperty('toolchainDir')) {
  67     toolchainDir = ext.toolchainDir + "/"
  68 } else {
  69     toolchainDir = ""
  70 }
  71 
  72 def gtk2CCFlags = [  ];
  73 def gtk3CCFlags = [ "-Wno-deprecated-declarations" ];
  74 def gtk2LinkFlags = [ ];
  75 def gtk3LinkFlags = [ ];
  76 LINUX.buildGTK3 = true
  77 
  78 // Create $buildDir/linux_tools.properties file and load props from it
  79 setupTools("linux_gtk2",
  80     { propFile ->
  81         ByteArrayOutputStream results1 = new ByteArrayOutputStream();
  82         exec {
  83             commandLine("${toolchainDir}pkg-config", "--cflags", "gtk+-2.0", "gthread-2.0", "xtst")
  84             setStandardOutput(results1);
  85         }
  86         propFile << "cflagsGTK2=" << results1.toString().trim() << "\n";
  87 
  88         ByteArrayOutputStream results3 = new ByteArrayOutputStream();
  89         exec {
  90             commandLine("${toolchainDir}pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst")
  91             setStandardOutput(results3);
  92         }
  93         propFile << "libsGTK2=" << results3.toString().trim()  << "\n";
  94     },
  95     { properties ->
  96         def cflagsGTK2 = properties.getProperty("cflagsGTK2")
  97         def libsGTK2 = properties.getProperty("libsGTK2")
  98         if (cflagsGTK2 && libsGTK2) {
  99             gtk2CCFlags.addAll(cflagsGTK2.split(" "))
 100             gtk2LinkFlags.addAll(libsGTK2.split(" "))
 101         } else {
 102             throw new IllegalStateException("GTK2 development packages not found. If GTK2 packages are installed, please remove the build directory and try again.")
 103         }
 104     }
 105 )
 106 
 107 setupTools("linux_gtk3",
 108     { propFile ->
 109         ByteArrayOutputStream results2 = new ByteArrayOutputStream();
 110         exec {
 111             commandLine("${toolchainDir}pkg-config", "--cflags", "gtk+-3.0", "gthread-2.0", "xtst")
 112             setStandardOutput(results2);
 113             ignoreExitValue(true)
 114         }
 115         propFile << "cflagsGTK3=" << results2.toString().trim() << "\n";
 116 
 117         ByteArrayOutputStream results4 = new ByteArrayOutputStream();
 118         exec {
 119             commandLine("${toolchainDir}pkg-config", "--libs", "gtk+-3.0", "gthread-2.0", "xtst")
 120             setStandardOutput(results4);
 121             ignoreExitValue(true)
 122         }
 123         propFile << "libsGTK3=" << results4.toString().trim()  << "\n";
 124 
 125     },
 126     { properties ->
 127         def ccflags =  properties.getProperty("cflagsGTK3")
 128         def ldflags =  properties.getProperty("libsGTK3")
 129         if (ccflags && ldflags) {
 130             gtk3CCFlags.addAll(ccflags.split(" "))
 131             gtk3LinkFlags.addAll(ldflags.split(" "))
 132         } else {
 133             logger.info("Warning: GTK3 development packages not found, not building GTK3 support");
 134             LINUX.buildGTK3 = false
 135         }
 136     }
 137 )
 138 
 139 def pangoCCFlags = ["-D_ENABLE_PANGO"];
 140 def pangoLinkFlags = [];
 141 setupTools("linux_pango_tools",
 142     { propFile ->
 143         ByteArrayOutputStream results = new ByteArrayOutputStream();
 144         exec {
 145             commandLine "${toolchainDir}pkg-config", "--cflags", "pangoft2"
 146             standardOutput = results
 147         }
 148         propFile << "cflags=" << results.toString().trim() << "\n";
 149 
 150         results = new ByteArrayOutputStream();
 151         exec {
 152             commandLine "${toolchainDir}pkg-config", "--libs", "pangoft2"
 153             standardOutput = results
 154         }
 155         propFile << "libs=" << results.toString().trim();
 156     },
 157     { properties ->
 158         def cflags = properties.getProperty("cflags")
 159         def libs = properties.getProperty("libs")
 160         if (cflags && libs) {
 161             pangoCCFlags.addAll(cflags.split(" "))
 162             pangoLinkFlags.addAll(libs.split(" "))
 163         } else {
 164             throw new IllegalStateException("Linux pango packages not found.\nIf pango packages are installed, please remove the build directory and try again.")
 165         }
 166     }
 167 )
 168 
 169 def freetypeCCFlags = [ext.IS_COMPILE_PANGO ? "-D_ENABLE_PANGO" :
 170                        ext.IS_COMPILE_HARFBUZZ ? "-D_ENABLE_HARFBUZZ" : ""]
 171 def freetypeLinkFlags = []
 172 setupTools("linux_freetype_tools",
 173     { propFile ->
 174         ByteArrayOutputStream results = new ByteArrayOutputStream();
 175         exec {
 176             commandLine "${toolchainDir}pkg-config", "--cflags", "freetype2"
 177             standardOutput = results
 178         }
 179         propFile << "cflags=" << results.toString().trim() << "\n";
 180 
 181         results = new ByteArrayOutputStream();
 182         exec {
 183             commandLine "${toolchainDir}pkg-config", "--libs", "freetype2"
 184             standardOutput = results
 185         }
 186         propFile << "libs=" << results.toString().trim();
 187     },
 188     { properties ->
 189         def cflags = properties.getProperty("cflags")
 190         def libs = properties.getProperty("libs")
 191         if (cflags && libs) {
 192             freetypeCCFlags.addAll(cflags.split(" "))
 193             freetypeLinkFlags.addAll(libs.split(" "))
 194         } else {
 195             throw new IllegalStateException("Linux freetype packages not found.\nIf freetype pacakges are installed, please remove the build directory and try again.")
 196         }
 197     }
 198 )
 199 
 200 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "${toolchainDir}gcc";
 201 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "${toolchainDir}g++";
 202 
 203 LINUX.glass = [:]
 204 LINUX.glass.variants = ["glass", "glassgtk2"]
 205 if (LINUX.buildGTK3) {
 206     logger.info("Building libglassgtk3")
 207     LINUX.glass.variants += "glassgtk3"
 208 } else {
 209     logger.warn("NOT Building libglassgtk3")
 210 }
 211 
 212 FileTree ft_gtk_launcher = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 213     include("**/launcher.c")
 214 }
 215 
 216 FileTree ft_gtk = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 217     exclude("**/launcher.c")
 218 }
 219 
 220 LINUX.glass.glass = [:]
 221 LINUX.glass.glass.nativeSource = ft_gtk_launcher.getFiles()
 222 LINUX.glass.glass.compiler = compiler
 223 LINUX.glass.glass.ccFlags = [ccFlags, gtk2CCFlags,  "-Werror"].flatten()
 224 LINUX.glass.glass.linker = linker
 225 LINUX.glass.glass.linkFlags = [linkFlags, "-lX11", "-ldl" ].flatten()
 226 LINUX.glass.glass.lib = "glass"
 227 
 228 LINUX.glass.glassgtk2 = [:]
 229 LINUX.glass.glassgtk2.nativeSource =  ft_gtk.getFiles()
 230 LINUX.glass.glassgtk2.compiler = compiler
 231 LINUX.glass.glassgtk2.ccFlags = [ccFlags, gtk2CCFlags, "-Werror"].flatten()
 232 LINUX.glass.glassgtk2.linker = linker
 233 LINUX.glass.glassgtk2.linkFlags = [linkFlags, gtk2LinkFlags ].flatten()
 234 LINUX.glass.glassgtk2.lib = "glassgtk2"
 235 
 236 LINUX.glass.glassgtk3 = [:]
 237 LINUX.glass.glassgtk3.nativeSource =  ft_gtk.getFiles()
 238 LINUX.glass.glassgtk3.compiler = compiler
 239 LINUX.glass.glassgtk3.ccFlags = [ccFlags, gtk3CCFlags, "-Werror"].flatten()
 240 LINUX.glass.glassgtk3.linker = linker
 241 LINUX.glass.glassgtk3.linkFlags = [linkFlags, gtk3LinkFlags ].flatten()
 242 LINUX.glass.glassgtk3.lib = "glassgtk3"
 243 
 244 LINUX.decora = [:]
 245 LINUX.decora.compiler = compiler
 246 LINUX.decora.ccFlags = [ccFlags, "-ffast-math"].flatten()
 247 LINUX.decora.linker = linker
 248 LINUX.decora.linkFlags = [linkFlags].flatten()
 249 LINUX.decora.lib = "decora_sse"
 250 
 251 LINUX.prism = [:]
 252 LINUX.prism.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism")
 253 LINUX.prism.compiler = compiler
 254 LINUX.prism.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 255 LINUX.prism.linker = linker
 256 LINUX.prism.linkFlags = [linkFlags].flatten()
 257 LINUX.prism.lib = "prism_common"
 258 
 259 LINUX.prismSW = [:]
 260 LINUX.prismSW.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism-sw")
 261 LINUX.prismSW.compiler = compiler
 262 LINUX.prismSW.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 263 LINUX.prismSW.linker = linker
 264 LINUX.prismSW.linkFlags = [linkFlags].flatten()
 265 LINUX.prismSW.lib = "prism_sw"
 266 
 267 LINUX.iio = [:]
 268 LINUX.iio.nativeSource = [
 269     file("${project("graphics").projectDir}/src/main/native-iio"),
 270     file("${project("graphics").projectDir}/src/main/native-iio/libjpeg")]
 271 LINUX.iio.compiler = compiler
 272 LINUX.iio.ccFlags = [ccFlags].flatten()
 273 LINUX.iio.linker = linker
 274 LINUX.iio.linkFlags = [linkFlags].flatten()
 275 LINUX.iio.lib = "javafx_iio"
 276 
 277 LINUX.prismES2 = [:]
 278 LINUX.prismES2.nativeSource = [
 279     file("${project("graphics").projectDir}/src/main/native-prism-es2"),
 280     file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
 281     file("${project("graphics").projectDir}/src/main/native-prism-es2/x11")
 282 ]
 283 LINUX.prismES2.compiler = compiler
 284 LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
 285 LINUX.prismES2.linker = linker
 286 LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
 287 LINUX.prismES2.lib = "prism_es2"
 288 
 289 def closedDir = file("$projectDir/../rt-closed")
 290 LINUX.font = [:]
 291 LINUX.font.compiler = compiler
 292 LINUX.font.nativeSource = [file("${project("graphics").projectDir}/src/main/native-font")]
 293 LINUX.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
 294 LINUX.font.linker = linker
 295 LINUX.font.linkFlags = [linkFlags].flatten()
 296 LINUX.font.lib = "javafx_font"
 297 
 298 LINUX.fontFreetype = [:]
 299 LINUX.fontFreetype.nativeSource = ["src/main/native-font/freetype.c"]
 300 LINUX.fontFreetype.compiler = compiler
 301 LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
 302 LINUX.fontFreetype.linker = linker
 303 LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
 304 LINUX.fontFreetype.lib = "javafx_font_freetype"
 305 
 306 LINUX.fontPango = [:]
 307 LINUX.fontPango.nativeSource = ["src/main/native-font/pango.c"]
 308 LINUX.fontPango.compiler = compiler
 309 LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
 310 LINUX.fontPango.linker = linker
 311 LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
 312 LINUX.fontPango.lib = "javafx_font_pango"
 313 
 314 LINUX.media = [:]
 315 LINUX.media.compiler = compiler
 316 LINUX.media.linker = linker
 317 LINUX.media.ar = "${toolchainDir}ar"
 318 
 319 LINUX.webkit = [:]
 320 LINUX.webkit.compiler = compiler
 321 LINUX.webkit.linker = linker
 322 LINUX.webkit.ccFlags = commonFlags.flatten()
 323 LINUX.webkit.linkFlags = linkFlags.flatten()