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