view buildSrc/linux.gradle @ 11236:8d0b833ea001

8214810: Update to build scripts Reviewed-by: prr, almatvee, mschoene, rhalade
author kcr
date Thu, 06 Dec 2018 05:04:52 -0800
parents dc4eac151944
children 559c9b9d75a8
line wrap: on
line source
/*
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

ext.LINUX = [:]

// Declare whether this particular target file applies to the current system
LINUX.canBuild = IS_LINUX;
if (!LINUX.canBuild) return;

// All desktop related packages should be built
LINUX.compileSwing = true;
LINUX.compileSWT = true;

// Libraries end up in the lib/$OS_ARCH directory for Linux
LINUX.libDest = "lib"

// Lambda for naming the generated libs
LINUX.library = { name -> return "lib${name}.so" as String }

// A set of common parameters to use for both compiling and linking
def commonFlags = [
        "-fno-strict-aliasing", "-fPIC", "-fno-omit-frame-pointer", // optimization flags
        "-fstack-protector",
        "-Wextra", "-Wall", "-Wformat-security", "-Wno-unused", "-Wno-parentheses", "-Werror=implicit-function-declaration"] // warning flags

if (!IS_64) {
    commonFlags += "-m32"
}

// Specify the compilation parameters and link parameters
def ccFlags = [
        commonFlags, "-I$JDK_HOME/include", "-I$JDK_HOME/include/linux", "-c",
        "-ffunction-sections", "-fdata-sections",
        IS_DEBUG_NATIVE ? ["-ggdb", "-DVERBOSE"] : ["-O2", "-DNDEBUG"]].flatten()
def ccFlagsGTK3 = ccFlags
//ccFlags.addAll(["-Wnon-virtual-dtor", "-Woverloaded-virtual", "-std=c++0x"])
def linkFlags = ["-static-libgcc", "-static-libstdc++", "-shared", commonFlags,
                 "-z", "relro",
                 "-Wl,--gc-sections"].flatten()

if (IS_DEBUG_NATIVE) {
    linkFlags += "-g"
}

def gtk2CCFlags = [  ];
def gtk3CCFlags = [ "-Wno-deprecated-declarations" ];
def gtk2LinkFlags = [ ];
def gtk3LinkFlags = [ ];
LINUX.buildGTK3 = true

// Create $buildDir/linux_tools.properties file and load props from it
setupTools("linux_gtk2",
    { propFile ->
        ByteArrayOutputStream results1 = new ByteArrayOutputStream();
        exec {
            commandLine("pkg-config", "--cflags", "gtk+-2.0", "gthread-2.0", "xtst")
            setStandardOutput(results1);
        }
        propFile << "cflagsGTK2=" << results1.toString().trim() << "\n";

        ByteArrayOutputStream results3 = new ByteArrayOutputStream();
        exec {
            commandLine("pkg-config", "--libs", "gtk+-2.0", "gthread-2.0", "xtst")
            setStandardOutput(results3);
        }
        propFile << "libsGTK2=" << results3.toString().trim()  << "\n";
    },
    { properties ->
        def cflagsGTK2 = properties.getProperty("cflagsGTK2")
        def libsGTK2 = properties.getProperty("libsGTK2")
        if (cflagsGTK2 && libsGTK2) {
            gtk2CCFlags.addAll(cflagsGTK2.split(" "))
            gtk2LinkFlags.addAll(libsGTK2.split(" "))
        } else {
            throw new IllegalStateException("GTK2 development packages not found. If GTK2 packages are installed, please remove the build directory and try again.")
        }
    }
)

setupTools("linux_gtk3",
    { propFile ->
        ByteArrayOutputStream results2 = new ByteArrayOutputStream();
        exec {
            commandLine("pkg-config", "--cflags", "gtk+-3.0", "gthread-2.0", "xtst")
            setStandardOutput(results2);
            ignoreExitValue(true)
        }
        propFile << "cflagsGTK3=" << results2.toString().trim() << "\n";

        ByteArrayOutputStream results4 = new ByteArrayOutputStream();
        exec {
            commandLine("pkg-config", "--libs", "gtk+-3.0", "gthread-2.0", "xtst")
            setStandardOutput(results4);
            ignoreExitValue(true)
        }
        propFile << "libsGTK3=" << results4.toString().trim()  << "\n";

    },
    { properties ->
        def ccflags =  properties.getProperty("cflagsGTK3")
        def ldflags =  properties.getProperty("libsGTK3")
        if (ccflags && ldflags) {
            gtk3CCFlags.addAll(ccflags.split(" "))
            gtk3LinkFlags.addAll(ldflags.split(" "))
        } else {
            logger.info("Warning: GTK3 development packages not found, not building GTK3 support");
            LINUX.buildGTK3 = false
        }
    }
)

def pangoCCFlags = ["-D_ENABLE_PANGO"];
def pangoLinkFlags = [];
setupTools("linux_pango_tools",
    { propFile ->
        ByteArrayOutputStream results = new ByteArrayOutputStream();
        exec {
            commandLine "pkg-config", "--cflags", "pangoft2"
            standardOutput = results
        }
        propFile << "cflags=" << results.toString().trim() << "\n";

        results = new ByteArrayOutputStream();
        exec {
            commandLine "pkg-config", "--libs", "pangoft2"
            standardOutput = results
        }
        propFile << "libs=" << results.toString().trim();
    },
    { properties ->
        def cflags = properties.getProperty("cflags")
        def libs = properties.getProperty("libs")
        if (cflags && libs) {
            pangoCCFlags.addAll(cflags.split(" "))
            pangoLinkFlags.addAll(libs.split(" "))
        } else {
            throw new IllegalStateException("Linux pango packages not found.\nIf pango packages are installed, please remove the build directory and try again.")
        }
    }
)

def freetypeCCFlags = [ext.IS_COMPILE_PANGO ? "-D_ENABLE_PANGO" :
                       ext.IS_COMPILE_HARFBUZZ ? "-D_ENABLE_HARFBUZZ" : ""]
def freetypeLinkFlags = []
setupTools("linux_freetype_tools",
    { propFile ->
        ByteArrayOutputStream results = new ByteArrayOutputStream();
        exec {
            commandLine "pkg-config", "--cflags", "freetype2"
            standardOutput = results
        }
        propFile << "cflags=" << results.toString().trim() << "\n";

        results = new ByteArrayOutputStream();
        exec {
            commandLine "pkg-config", "--libs", "freetype2"
            standardOutput = results
        }
        propFile << "libs=" << results.toString().trim();
    },
    { properties ->
        def cflags = properties.getProperty("cflags")
        def libs = properties.getProperty("libs")
        if (cflags && libs) {
            freetypeCCFlags.addAll(cflags.split(" "))
            freetypeLinkFlags.addAll(libs.split(" "))
        } else {
            throw new IllegalStateException("Linux freetype packages not found.\nIf freetype pacakges are installed, please remove the build directory and try again.")
        }
    }
)

def compiler = IS_COMPILE_PARFAIT ? "parfait-gcc" : "gcc";
def linker = IS_COMPILE_PARFAIT ? "parfait-g++" : "g++";

LINUX.glass = [:]
LINUX.glass.variants = ["glass", "glassgtk2"]
if (LINUX.buildGTK3) {
    logger.info("Building libglassgtk3")
    LINUX.glass.variants += "glassgtk3"
} else {
    logger.warn("NOT Building libglassgtk3")
}

FileTree ft_gtk_launcher = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
    include("**/launcher.c")
}

FileTree ft_gtk = fileTree("${project(":graphics").projectDir}/src/main/native-glass/gtk/") {
    exclude("**/launcher.c")
}

LINUX.glass.glass = [:]
LINUX.glass.glass.nativeSource = ft_gtk_launcher.getFiles()
LINUX.glass.glass.compiler = compiler
LINUX.glass.glass.ccFlags = [ccFlags, gtk2CCFlags,  "-Werror"].flatten()
LINUX.glass.glass.linker = linker
LINUX.glass.glass.linkFlags = [linkFlags, "-lX11", "-ldl" ].flatten()
LINUX.glass.glass.lib = "glass"

LINUX.glass.glassgtk2 = [:]
LINUX.glass.glassgtk2.nativeSource =  ft_gtk.getFiles()
LINUX.glass.glassgtk2.compiler = compiler
LINUX.glass.glassgtk2.ccFlags = [ccFlags, gtk2CCFlags, "-Werror"].flatten()
LINUX.glass.glassgtk2.linker = linker
LINUX.glass.glassgtk2.linkFlags = [linkFlags, gtk2LinkFlags ].flatten()
LINUX.glass.glassgtk2.lib = "glassgtk2"

LINUX.glass.glassgtk3 = [:]
LINUX.glass.glassgtk3.nativeSource =  ft_gtk.getFiles()
LINUX.glass.glassgtk3.compiler = compiler
LINUX.glass.glassgtk3.ccFlags = [ccFlags, gtk3CCFlags, "-Werror"].flatten()
LINUX.glass.glassgtk3.linker = linker
LINUX.glass.glassgtk3.linkFlags = [linkFlags, gtk3LinkFlags ].flatten()
LINUX.glass.glassgtk3.lib = "glassgtk3"

LINUX.decora = [:]
LINUX.decora.compiler = compiler
LINUX.decora.ccFlags = [ccFlags, "-ffast-math"].flatten()
LINUX.decora.linker = linker
LINUX.decora.linkFlags = [linkFlags].flatten()
LINUX.decora.lib = "decora_sse"

LINUX.prism = [:]
LINUX.prism.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism")
LINUX.prism.compiler = compiler
LINUX.prism.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
LINUX.prism.linker = linker
LINUX.prism.linkFlags = [linkFlags].flatten()
LINUX.prism.lib = "prism_common"

LINUX.prismSW = [:]
LINUX.prismSW.nativeSource = file("${project(":graphics").projectDir}/src/main/native-prism-sw")
LINUX.prismSW.compiler = compiler
LINUX.prismSW.ccFlags = [ccFlags, "-DINLINE=inline"].flatten()
LINUX.prismSW.linker = linker
LINUX.prismSW.linkFlags = [linkFlags].flatten()
LINUX.prismSW.lib = "prism_sw"

LINUX.iio = [:]
LINUX.iio.nativeSource = [
    file("${project("graphics").projectDir}/src/main/native-iio"),
    file("${project("graphics").projectDir}/src/main/native-iio/libjpeg")]
LINUX.iio.compiler = compiler
LINUX.iio.ccFlags = [ccFlags].flatten()
LINUX.iio.linker = linker
LINUX.iio.linkFlags = [linkFlags].flatten()
LINUX.iio.lib = "javafx_iio"

LINUX.prismES2 = [:]
LINUX.prismES2.nativeSource = [
    file("${project("graphics").projectDir}/src/main/native-prism-es2"),
    file("${project("graphics").projectDir}/src/main/native-prism-es2/GL"),
    file("${project("graphics").projectDir}/src/main/native-prism-es2/x11")
]
LINUX.prismES2.compiler = compiler
LINUX.prismES2.ccFlags = ["-DLINUX", ccFlags].flatten()
LINUX.prismES2.linker = linker
LINUX.prismES2.linkFlags = [linkFlags, "-lX11", "-lXxf86vm", "-lGL"].flatten()
LINUX.prismES2.lib = "prism_es2"

def closedDir = file("$projectDir/../rt-closed")
LINUX.font = [:]
LINUX.font.compiler = compiler
LINUX.font.nativeSource = [file("${project("graphics").projectDir}/src/main/native-font")]
LINUX.font.ccFlags = ["-DJFXFONT_PLUS", ccFlags].flatten()
LINUX.font.linker = linker
LINUX.font.linkFlags = [linkFlags].flatten()
LINUX.font.lib = "javafx_font"

LINUX.fontFreetype = [:]
LINUX.fontFreetype.nativeSource = ["src/main/native-font/freetype.c"]
LINUX.fontFreetype.compiler = compiler
LINUX.fontFreetype.ccFlags = ["-DJFXFONT_PLUS", ccFlags, freetypeCCFlags].flatten()
LINUX.fontFreetype.linker = linker
LINUX.fontFreetype.linkFlags = [linkFlags, freetypeLinkFlags].flatten()
LINUX.fontFreetype.lib = "javafx_font_freetype"

LINUX.fontPango = [:]
LINUX.fontPango.nativeSource = ["src/main/native-font/pango.c"]
LINUX.fontPango.compiler = compiler
LINUX.fontPango.ccFlags = ["-DJFXFONT_PLUS", ccFlags, pangoCCFlags].flatten()
LINUX.fontPango.linker = linker
LINUX.fontPango.linkFlags = [linkFlags, pangoLinkFlags].flatten()
LINUX.fontPango.lib = "javafx_font_pango"

LINUX.media = [:]
LINUX.media.compiler = compiler
LINUX.media.linker = linker
LINUX.media.ar = "ar"

LINUX.webkit = [:]
LINUX.webkit.compiler = compiler
LINUX.webkit.linker = linker
LINUX.webkit.ccFlags = commonFlags.flatten()
LINUX.webkit.linkFlags = linkFlags.flatten()