1 /*
   2  * Copyright (c) 2013, 2016, 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/$OS_ARCH"
  39 LINUX.modulesArch = "$OS_ARCH"
  40 
  41 // Lambda for naming the generated libs
  42 LINUX.library = { name -> return "lib${name}.so" as String }
  43 
  44 // A set of common parameters to use for both compiling and linking
  45 def commonFlags = [
  46         "-fno-strict-aliasing", "-fPIC", "-fno-omit-frame-pointer", // optimization flags
  47         "-Wextra", "-Wall", "-Wno-unused", "-Wno-parentheses", "-Werror=implicit-function-declaration"] // warning flags
  48 
  49 if (!IS_64) {
  50     commonFlags += "-m32"
  51 }
  52 
  53 // Specify the compilation parameters and link parameters
  54 def ccFlags = [
  55         commonFlags, "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c",
  56         IS_DEBUG_NATIVE ? ["-ggdb", "-DVERBOSE"] : ["-O2", "-DNDEBUG"]].flatten()
  57 def ccFlagsGTK3 = ccFlags
  58 //ccFlags.addAll(["-Wnon-virtual-dtor", "-Woverloaded-virtual", "-std=c++0x"])
  59 def linkFlags = ["-shared", commonFlags].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 
  70 // Create $buildDir/linux_tools.properties file and load props from it
  71 setupTools("linux_gtk",
  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 results2 = new ByteArrayOutputStream();
  81         exec {
  82             commandLine("pkg-config", "--cflags", "gtk+-3.0", "gthread-2.0", "xtst")
  83             setStandardOutput(results2);
  84         }
  85         propFile << "cflagsGTK3=" << results2.toString().trim() << "\n";
  86 
  87         ByteArrayOutputStream results3 = new ByteArrayOutputStream();
  88         exec {
  89             commandLine("pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst")
  90             setStandardOutput(results3);
  91         }
  92         propFile << "libsGTK2=" << results3.toString().trim()  << "\n";
  93 
  94         ByteArrayOutputStream results4 = new ByteArrayOutputStream();
  95         exec {
  96             commandLine("pkg-config", "--libs", "gtk+-3.0", "gthread-2.0", "xtst")
  97             setStandardOutput(results4);
  98         }
  99         propFile << "libsGTK3=" << results4.toString().trim()  << "\n";
 100 
 101     },
 102     { properties ->
 103         gtk2CCFlags.addAll(properties.getProperty("cflagsGTK2").split(" "))
 104         gtk3CCFlags.addAll(properties.getProperty("cflagsGTK3").split(" "))
 105         gtk2LinkFlags.addAll(properties.getProperty("libsGTK2").split(" "))
 106         gtk3LinkFlags.addAll(properties.getProperty("libsGTK3").split(" "))
 107     }
 108 )
 109 
 110 def pangoCCFlags = ["-D_ENABLE_PANGO"];
 111 def pangoLinkFlags = [];
 112 setupTools("linux_pango_tools",
 113     { propFile ->
 114         ByteArrayOutputStream results = new ByteArrayOutputStream();
 115         exec {
 116             commandLine "pkg-config", "--cflags", "pangoft2"
 117             standardOutput = results
 118         }
 119         propFile << "cflags=" << results.toString().trim() << "\n";
 120 
 121         results = new ByteArrayOutputStream();
 122         exec {
 123             commandLine "pkg-config", "--libs", "pangoft2"
 124             standardOutput = results
 125         }
 126         propFile << "libs=" << results.toString().trim();
 127     },
 128     { properties ->
 129         pangoCCFlags.addAll(properties.getProperty("cflags").split(" "))
 130         pangoLinkFlags.addAll(properties.getProperty("libs").split(" "))
 131     }
 132 )
 133 
 134 def freetypeCCFlags = [ext.IS_COMPILE_PANGO ? "-D_ENABLE_PANGO" :
 135                        ext.IS_COMPILE_HARFBUZZ ? "-D_ENABLE_HARFBUZZ" : ""]
 136 def freetypeLinkFlags = []
 137 setupTools("linux_freetype_tools",
 138     { propFile ->
 139         ByteArrayOutputStream results = new ByteArrayOutputStream();
 140         exec {
 141             commandLine "pkg-config", "--cflags", "freetype2"
 142             standardOutput = results
 143         }
 144         propFile << "cflags=" << results.toString().trim() << "\n";
 145 
 146         results = new ByteArrayOutputStream();
 147         exec {
 148             commandLine "pkg-config", "--libs", "freetype2"
 149             standardOutput = results
 150         }
 151         propFile << "libs=" << results.toString().trim();
 152     },
 153     { properties ->
 154         freetypeCCFlags.addAll(properties.getProperty("cflags").split(" "))
 155         freetypeLinkFlags.addAll(properties.getProperty("libs").split(" "))
 156     }
 157 )
 158 
 159 def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
 160 def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";
 161 
 162 LINUX.glass = [:]
 163 LINUX.glass.variants = ["glass", "glassgtk2", "glassgtk3"]
 164 //LINUX.glass.variants = ["glass", "glassgtk2"]
 165 
 166 FileTree ft_gtk_launcher = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 167     //include("**/glass_general.cpp")
 168     include("**/launcher.c")
 169 }
 170 
 171 FileTree ft_gtk = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
 172     //include("**/wrapper*.c")
 173     //exclude("**/glass_general.cpp")
 174     exclude("**/launcher.c")
 175 }
 176 
 177 LINUX.glass.glass = [:]
 178 LINUX.glass.glass.nativeSource = ft_gtk_launcher.getFiles()
 179 LINUX.glass.glass.compiler = compiler
 180 LINUX.glass.glass.ccFlags = [ccFlags, gtk2CCFlags,  "-Werror"].flatten()
 181 LINUX.glass.glass.linker = linker
 182 LINUX.glass.glass.linkFlags = [linkFlags, "-lX11", "-ldl" ].flatten()
 183 LINUX.glass.glass.lib = "glass"
 184 
 185 LINUX.glass.glassgtk2 = [:]
 186 LINUX.glass.glassgtk2.nativeSource =  ft_gtk.getFiles()
 187 LINUX.glass.glassgtk2.compiler = compiler
 188 LINUX.glass.glassgtk2.ccFlags = [ccFlags, gtk2CCFlags, "-Werror"].flatten()
 189 LINUX.glass.glassgtk2.linker = linker
 190 LINUX.glass.glassgtk2.linkFlags = [linkFlags, gtk2LinkFlags ].flatten()
 191 LINUX.glass.glassgtk2.lib = "glassgtk2"
 192 
 193 LINUX.glass.glassgtk3 = [:]
 194 LINUX.glass.glassgtk3.nativeSource =  ft_gtk.getFiles()
 195 LINUX.glass.glassgtk3.compiler = compiler
 196 LINUX.glass.glassgtk3.ccFlags = [ccFlags, gtk3CCFlags, "-Werror"].flatten()
 197 LINUX.glass.glassgtk3.linker = linker
 198 LINUX.glass.glassgtk3.linkFlags = [linkFlags, gtk3LinkFlags ].flatten()
 199 LINUX.glass.glassgtk3.lib = "glassgtk3"
 200 
 201 LINUX.decora = [:]
 202 LINUX.decora.compiler = compiler
 203 LINUX.decora.ccFlags = [ccFlags, "-ffast-math"].flatten()
 204 LINUX.decora.linker = linker
 205 LINUX.decora.linkFlags = [linkFlags].flatten()
 206 LINUX.decora.lib = "decora_sse"
 207 
 208 LINUX.prism = [:]
 209 LINUX.prism.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism")
 210 LINUX.prism.compiler = compiler
 211 LINUX.prism.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 212 LINUX.prism.linker = linker
 213 LINUX.prism.linkFlags = [linkFlags].flatten()
 214 LINUX.prism.lib = "prism_common"
 215 
 216 LINUX.prismSW = [:]
 217 LINUX.prismSW.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism-sw")
 218 LINUX.prismSW.compiler = compiler
 219 LINUX.prismSW.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
 220 LINUX.prismSW.linker = linker
 221 LINUX.prismSW.linkFlags = [linkFlags].flatten()
 222 LINUX.prismSW.lib = "prism_sw"
 223 
 224 LINUX.launcher = [:]
 225 LINUX.launcher.compiler = compiler
 226 LINUX.launcher.ccFlags = ["-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c"]
 227 LINUX.launcher.linker = linker
 228 LINUX.launcher.linkFlags = ["-ldl"]
 229 if (!IS_64) {
 230     LINUX.launcher.ccFlags += "-m32"
 231     LINUX.launcher.linkFlags += "-m32"
 232 }
 233 
 234 LINUX.launcherlibrary = [:]
 235 LINUX.launcherlibrary.compiler = compiler
 236 LINUX.launcherlibrary.ccFlags = ["-DJAVAARCH=\"$OS_ARCH\"", "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c", "-fPIC"]
 237 LINUX.launcherlibrary.linker = linker
 238 LINUX.launcherlibrary.linkFlags = ["-ldl", "-lpthread", "-shared"]
 239 if (!IS_64) {
 240     LINUX.launcherlibrary.ccFlags += "-m32"
 241     LINUX.launcherlibrary.linkFlags += "-m32"
 242 }
 243 
 244 LINUX.iio = [:]
 245 LINUX.iio.nativeSource = [
 246     file("${project("graphics").projectDir}/src/main/native-iio"),
 247     file("${project("graphics").projectDir}/src/main/native-iio/libjpeg7")]
 248 LINUX.iio.compiler = compiler
 249 LINUX.iio.ccFlags = [ccFlags].flatten()
 250 LINUX.iio.linker = linker
 251 LINUX.iio.linkFlags = [linkFlags].flatten()
 252 LINUX.iio.lib = "javafx_iio"
 253 
 254 LINUX.prismES2 = [:]
 255 LINUX.prismES2.nativeSource = [
 256     file("${project("graphics").projectDir}/src/main/native-prism-es2"),
 257     file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
 258     file("${project("graphics").projectDir}/src/main/native-prism-es2/x11")
 259 ]
 260 LINUX.prismES2.compiler = compiler
 261 LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
 262 LINUX.prismES2.linker = linker
 263 LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
 264 LINUX.prismES2.lib = "prism_es2"
 265 
 266 def closedDir = file("$projectDir/../rt-closed")
 267 LINUX.font = [:]
 268 LINUX.font.compiler = compiler
 269 LINUX.font.nativeSource = [file("${project("graphics").projectDir}/src/main/native-font")]
 270 LINUX.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
 271 LINUX.font.linker = linker
 272 LINUX.font.linkFlags = [linkFlags].flatten()
 273 LINUX.font.lib = "javafx_font"
 274 
 275 LINUX.fontT2K = [:]
 276 LINUX.fontT2K.nativeSource = [
 277         file("$closedDir/javafx-font-t2k-native/src"),
 278         file("$closedDir/javafx-font-t2k-native/src/layout")]
 279 LINUX.fontT2K.compiler = compiler
 280 LINUX.fontT2K.ccFlags = ["-DJFXFONT_PLUS", "-DLE_STANDALONE", ccFlags].flatten()
 281 LINUX.fontT2K.linker = linker
 282 LINUX.fontT2K.linkFlags = [linkFlags].flatten()
 283 LINUX.fontT2K.lib = "javafx_font_t2k"
 284 
 285 LINUX.fontFreetype = [:]
 286 LINUX.fontFreetype.nativeSource = ["src/main/native-font/freetype.c"]
 287 LINUX.fontFreetype.compiler = compiler
 288 LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
 289 LINUX.fontFreetype.linker = linker
 290 LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
 291 LINUX.fontFreetype.lib = "javafx_font_freetype"
 292 
 293 LINUX.fontPango = [:]
 294 LINUX.fontPango.nativeSource = ["src/main/native-font/pango.c"]
 295 LINUX.fontPango.compiler = compiler
 296 LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
 297 LINUX.fontPango.linker = linker
 298 LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
 299 LINUX.fontPango.lib = "javafx_font_pango"
 300 
 301 LINUX.media = [:]
 302 LINUX.media.compiler = compiler
 303 LINUX.media.linker = linker
 304 LINUX.media.ar = "ar"