diff --git a/.github/workflows/libwmf.yml b/.github/workflows/libwmf.yml new file mode 100644 index 0000000..f280f65 --- /dev/null +++ b/.github/workflows/libwmf.yml @@ -0,0 +1,16 @@ +name: libwmf +on: + workflow_dispatch: + push: + paths: + - 'buildSrc/**' + - 'libwmf/**' + - '.github/workflows/build.yml' + - '.github/workflows/libwmf.yml' + +jobs: + build: + name: libwmf + uses: ./.github/workflows/build.yml + with: + package: libwmf diff --git a/README.md b/README.md index 01c3a53..cd91e6a 100644 --- a/README.md +++ b/README.md @@ -266,3 +266,11 @@ pdf2htmlEX also has a Java wrapper - [pdf2htmlEX-Android](https://github.com/Vil [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libgsf-ndk25-shared.svg?label=Maven%20Central%20libgsf-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libgsf-ndk25-shared) [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libgsf-ndk26-static.svg?label=Maven%20Central%20libgsf-ndk26-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libgsf-ndk26-static) [![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libgsf-ndk26-shared.svg?label=Maven%20Central%20libgsf-ndk26-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libgsf-ndk26-shared) + +#### [libwmf](https://github.com/caolanm/libwmf) + +[![libwmf](https://github.com/ViliusSutkus89/ndkports/actions/workflows/libwmf.yml/badge.svg)](https://github.com/ViliusSutkus89/ndkports/actions/workflows/libwmf.yml) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libwmf-ndk25-static.svg?label=Maven%20Central%20libwmf-ndk25-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libwmf-ndk25-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libwmf-ndk25-shared.svg?label=Maven%20Central%20libwmf-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libwmf-ndk25-shared) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libwmf-ndk26-static.svg?label=Maven%20Central%20libwmf-ndk26-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libwmf-ndk26-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/libwmf-ndk26-shared.svg?label=Maven%20Central%20libwmf-ndk26-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:libwmf-ndk26-shared) diff --git a/buildSrc/src/main/kotlin/com/android/ndkports/GetPkgConfig.kt b/buildSrc/src/main/kotlin/com/android/ndkports/GetPkgConfig.kt new file mode 100644 index 0000000..4c34d96 --- /dev/null +++ b/buildSrc/src/main/kotlin/com/android/ndkports/GetPkgConfig.kt @@ -0,0 +1,42 @@ +package com.android.ndkports + +import java.io.File + +data class PkgConfig( + val cflags: String, + val libs: String, +) +private fun callPkgConfig(arguments: List, pkgConfigLibDir: String): String { + val pb = ProcessBuilder(arguments).redirectErrorStream(true) + pb.environment()["PKG_CONFIG_LIBDIR"] = pkgConfigLibDir + + val result = pb.start() + val status = result.waitFor(); + val output = result.inputStream.bufferedReader().use { it.readText() }.trim() + if (status != 0) { + throw RuntimeException("PkgConfigHelper failed with:\n$output") + } + return output +} + +fun getPkgConfig( + packageName: String, + generatedDependenciesDir: File, + isStatic: Boolean, +): Map { + val config = mutableMapOf() + val arguments = mutableListOf("pkg-config", packageName) + if (isStatic) + arguments.add("--static") + generatedDependenciesDir.listFiles()?.forEach { generatedDirectory -> + val triple = generatedDirectory.name + val pkgConfigLibDir = generatedDirectory.resolve("lib/pkgconfig").absoluteFile + assert(pkgConfigLibDir.exists()) + + config[triple] = PkgConfig( + cflags = callPkgConfig(arguments + "--cflags", pkgConfigLibDir = pkgConfigLibDir.path), + libs = callPkgConfig(arguments + "--libs", pkgConfigLibDir = pkgConfigLibDir.path), + ) + } ?: throw RuntimeException("Generated dependencies directory is empty!\n") + return config +} diff --git a/libwmf/build.gradle.kts b/libwmf/build.gradle.kts new file mode 100644 index 0000000..a9afdf7 --- /dev/null +++ b/libwmf/build.gradle.kts @@ -0,0 +1,210 @@ +import com.android.ndkports.* +import org.gradle.jvm.tasks.Jar + +val portVersion = "0.2.13" + +group = rootProject.group +version = "${portVersion}-beta-1" + +plugins { + id("maven-publish") + id("signing") + id("com.android.ndkports.NdkPorts") +} + +dependencies { + val ndkVersionSuffix = rootProject.extra.get("ndkVersionSuffix") + val dependencyLibraryTypeSuffix = rootProject.extra.get("dependencyLibraryTypeSuffix") + implementation("com.viliussutkus89.ndk.thirdparty:freetype${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:2.13.2-beta-8") + implementation("com.viliussutkus89.ndk.thirdparty:libexpat${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:2.5.0-beta-4") + implementation("com.viliussutkus89.ndk.thirdparty:libjpeg-turbo${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:3.0.1-beta-3") + implementation("com.viliussutkus89.ndk.thirdparty:libpng${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:1.6.40-beta-7") +} + +ndkPorts { + ndkPath.set(File(project.findProperty("ndkPath") as String)) + minSdkVersion.set(rootProject.extra.get("minSdkSupportedByNdk").toString().toInt()) + source.set(project.file("v${portVersion}.tar.gz")) +} + +tasks.prefab { + generator.set(PrefabSysrootPlugin::class.java) +} + +val buildTask = tasks.register("buildPort") { + val generatedDependencies = prefabGenerated.get().asFile + + // libwmf can't find freetype + lateinit var freetypePkgConfig: Map + doFirst { + freetypePkgConfig = getPkgConfig( + packageName = "freetype2", + generatedDependenciesDir = generatedDependencies, + isStatic = project.findProperty("libraryType") == "static" + ) + } + + autoconf { + val generated = generatedDependencies.resolve(toolchain.abi.triple) + args( + "--with-expat=$generated", + "--with-freetype=$generated", + "--with-png=$generated", + "--with-jpeg=$generated", + ) + freetypePkgConfig[toolchain.abi.triple]?.let { + env["CFLAGS"] = it.cflags + env["LDFLAGS"] = it.libs + } + } +} + +tasks.prefabPackage { + version.set(CMakeCompatibleVersion.parse(portVersion)) + + licensePath.set("COPYING") + + dependencies.set(mapOf( + "freetype" to "1", + "libexpat" to "1", + "libjpeg-turbo" to "1", + "libpng" to "1", + )) + + modules { + create("wmf") { + static.set(project.findProperty("libraryType") == "static") + dependencies.set(listOf( + "//freetype:freetype", + "//libexpat:expat", + "//libjpeg-turbo:jpeg", + "//libpng:png", + )) + } + create("wmflite") { + static.set(project.findProperty("libraryType") == "static") + dependencies.set(listOf( + "//freetype:freetype", + "//libexpat:expat", + "//libjpeg-turbo:jpeg", + "//libpng:png", + )) + } + } +} + +val packageSources = tasks.register("packageSources") { + archiveClassifier.set("sources") + from(projectDir.resolve("build.gradle.kts")) + from(ndkPorts.source) +} + +publishing { + publications { + create("release") { + from(components["prefab"]) + artifactId += rootProject.extra.get("ndkVersionSuffix") + artifactId += rootProject.extra.get("libraryTypeSuffix") + artifact(packageSources) + pom { + name.set("libwmf") + description.set("library for converting WMF files") + url.set("https://github.com/caolanm/libwmf") + licenses { + license { + name.set("GPLv2") + url.set("https://github.com/caolanm/libwmf/blob/v${portVersion}/COPYING") + distribution.set("repo") + } + } + developers { + // Developer list obtained from: + // https://github.com/caolanm/libwmf/blob/v0.2.13/CREDITS + developer { + name.set("Thomas Boutell") + } + developer { + id.set("allegro") + } + developer { + id.set("Gdtclft") + } + developer { + id.set("wine") + } + developer { + name.set("Bjorn Reese") + } + developer { + name.set("Daniel Stenberg") + } + developer { + name.set("Caolan McNamara") + } + developer { + name.set("Francis James Franklin") + } + developer { + name.set("David Airlie") + } + developer { + name.set("Frédéric Vivien") + } + developer { + name.set("Martin Vermeer") + } + developer { + name.set("Bob Friesenhahn") + } + developer { + name.set("Raj Manandhar") + } + developer { + name.set("Steven Michael Robbins") + } + developer { + name.set("Steven Michael Robbins") + } + developer { + name.set("Bob Bell") + } + developer { + name.set("Albert Chin") + } + developer { + name.set("Matej Vila") + } + developer { + name.set("Benjamin Geer") + } + developer { + name.set("Peter Ohlerich") + } + developer { + name.set("Steve Oney") + } + developer { + name.set("Michael Cree") + } + developer { + name.set("Dom Lachowicz") + } + } + scm { + url.set("https://github.com/ViliusSutkus89/ndkports") + connection.set("scm:git:https://github.com/ViliusSutkus89/ndkports.git") + } + } + } + } +} + +afterEvaluate { + System.getenv("SIGNING_KEY")?.let { signingKey -> + signing { + isRequired = true + useInMemoryPgpKeys(signingKey, System.getenv("SIGNING_PASS")) + sign(publishing.publications.findByName("release")) + } + } +} diff --git a/libwmf/v0.2.13.tar.gz b/libwmf/v0.2.13.tar.gz new file mode 100644 index 0000000..5f9df95 Binary files /dev/null and b/libwmf/v0.2.13.tar.gz differ diff --git a/settings.gradle.kts b/settings.gradle.kts index 873c75a..d142fc3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -53,4 +53,5 @@ include(":spiro") include(":openlibm") include(":fontforge") include(":pdf2htmlEX") -include("libgsf") +include(":libgsf") +include(":libwmf")