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