diff --git a/.github/workflows/wvware.yml b/.github/workflows/wvware.yml new file mode 100644 index 0000000..a26c56b --- /dev/null +++ b/.github/workflows/wvware.yml @@ -0,0 +1,16 @@ +name: wvWare +on: + workflow_dispatch: + push: + paths: + - 'buildSrc/**' + - 'wvware/**' + - '.github/workflows/build.yml' + - '.github/workflows/wvware.yml' + +jobs: + build: + name: wvWare + uses: ./.github/workflows/build.yml + with: + package: wvware diff --git a/README.md b/README.md index cd91e6a..9c8ffe6 100644 --- a/README.md +++ b/README.md @@ -274,3 +274,13 @@ 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/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) + +#### [wvWare](http://wvware.sourceforge.net) + +wvWare has a Java wrapper - [wvWare-Android](https://github.com/ViliusSutkus89/wvWare-Android) + +[![wvWare](https://github.com/ViliusSutkus89/ndkports/actions/workflows/wvWare.yml/badge.svg)](https://github.com/ViliusSutkus89/ndkports/actions/workflows/wvWare.yml) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/wvWare-ndk25-static.svg?label=Maven%20Central%20wvWare-ndk25-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:wvWare-ndk25-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/wvWare-ndk25-shared.svg?label=Maven%20Central%20wvWare-ndk25-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:wvWare-ndk25-shared) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/wvWare-ndk26-static.svg?label=Maven%20Central%20wvWare-ndk26-static)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:wvWare-ndk26-static) +[![Maven Central](https://img.shields.io/maven-central/v/com.viliussutkus89.ndk.thirdparty/wvWare-ndk26-shared.svg?label=Maven%20Central%20wvWare-ndk26-shared)](https://search.maven.org/search?q=g:com.viliussutkus89.ndk.thirdparty%20AND%20a:wvWare-ndk26-shared) diff --git a/settings.gradle.kts b/settings.gradle.kts index d142fc3..ac91bcf 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -55,3 +55,4 @@ include(":fontforge") include(":pdf2htmlEX") include(":libgsf") include(":libwmf") +include(":wvWare") diff --git a/wvWare/build.gradle.kts b/wvWare/build.gradle.kts new file mode 100644 index 0000000..7838251 --- /dev/null +++ b/wvWare/build.gradle.kts @@ -0,0 +1,198 @@ +import com.android.ndkports.AutoconfPortTask +import com.android.ndkports.CMakeCompatibleVersion +import com.android.ndkports.PrefabSysrootPlugin +import org.gradle.jvm.tasks.Jar + +val portVersion = "1.2.9" + +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:libgsf${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:1.14.51-beta-1") + implementation("com.viliussutkus89.ndk.thirdparty:libpng${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:1.6.40-beta-7") + implementation("com.viliussutkus89.ndk.thirdparty:libwmf${ndkVersionSuffix}${dependencyLibraryTypeSuffix}:0.2.13-beta-1") +} + +ndkPorts { + ndkPath.set(File(project.findProperty("ndkPath") as String)) + minSdkVersion.set(rootProject.extra.get("minSdkSupportedByNdk").toString().toInt()) + source.set(project.file("wv-${portVersion}.tar.gz")) +} + +tasks.prefab { + generator.set(PrefabSysrootPlugin::class.java) +} + +fun File.replace(oldValue: String, newValue: String, ignoreCase: Boolean = false): File { + writeText(readText().replace(oldValue, newValue, ignoreCase)) + return this +} + +fun File.patch(patch: String): File { + patch(projectDir.resolve("patches/$portVersion").resolve(patch)) + return this +} + +fun File.patch(patch: File): File { + val pb = ProcessBuilder( + if (isFile) listOf("patch", "-p0", absolutePath) + else listOf("patch", "-p0") + ) + + if (isDirectory) + pb.directory(absoluteFile) + + val process = pb.start() + process.outputStream.writer().use { + it.write(patch.readText()) + } + process.errorStream.bufferedReader().use { + println(it.readText()) + } + process.inputStream.bufferedReader().use { + println(it.readText()) + } + if (process.waitFor() != 0) { + throw RuntimeException("Patch failed!\n") + } + return this +} + +tasks.extractSrc { + doLast { + val srcDir = outDir.get().asFile + + srcDir.resolve("GNUmakefile.am").patch("skip-programs.patch") + srcDir.resolve("wv.h").patch("printf-redirect.patch") + + srcDir.resolve("config.sub").delete() + val pb = ProcessBuilder(srcDir.resolve("autogen.sh").absolutePath).directory(srcDir) + pb.environment()["NOCONFIGURE"] = "1" + if (pb.start().waitFor() != 0) + throw RuntimeException("autogen.sh failed!") + } +} + +val buildTask = tasks.register("buildPort") { + val generatedDependencies = prefabGenerated.get().asFile + val isStatic = project.findProperty("libraryType") == "static" + autoconf { + val generated = generatedDependencies.resolve(toolchain.abi.triple) + arg("--with-libwmf=$generated") + env["ac_cv_path_LIBWMF_CONFIG"] = "pkg-config libwmf" + if (isStatic) + env["ac_cv_path_LIBWMF_CONFIG"] += " --static" + + // wvWare can't find libpng + generated.let { + env["CFLAGS"] = "-I${generated.resolve("include")}" + env["LDFLAGS"] = "-L${generated.resolve("lib")}" + } + + env["CFLAGS"] += " -Wno-error=incompatible-function-pointer-types" + } + + doLast { + com.android.ndkports.Abi.values().forEach { abi -> + val installDir = installDirectoryFor(abi) + buildDirectoryFor(abi).resolve("config.h").copyTo( + target = installDir.resolve("include/wv/config.h"), overwrite = true + ) + + installDir.resolve("lib/pkgconfig/wv-1.0.pc").let { pc -> + pc.replace("-lpng", "") + pc.replace("Requires:", "Requires: libpng16") + } + } + } +} + +tasks.prefabPackage { + version.set(CMakeCompatibleVersion.parse(portVersion)) + + licensePath.set("COPYING") + + dependencies.set(mapOf( + "libgsf" to "1", + "libpng" to "1", + "libwmf" to "1", + )) + modules { + create("wv") { + includesPerAbi.set(true) + static.set(project.findProperty("libraryType") == "static") + dependencies.set(listOf( + "//libgsf:gsf-1", + "//libpng:png16", + "//libwmf:wmf", + "//libwmf:wmflite", + )) + } + } +} + +val packageSources = tasks.register("packageSources") { + archiveClassifier.set("sources") + from(projectDir.resolve("build.gradle.kts")) + from(projectDir.resolve("patches/$portVersion")) + 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("wvWare") + description.set("Library to load and parse Word 2000, 97, 95 and 6 files") + url.set("http://wvware.sourceforge.net") + licenses { + license { + name.set("GPLv2") + url.set("http://www.gnu.org/copyleft/gpl.html") + distribution.set("repo") + } + } + developers { + // Developer list obtained from: + // http://wvware.sourceforge.net/#dom + developer { + name.set("Dom Lachowicz") + } + developer { + name.set("Caolán McNamara") + } + developer { + name.set("Martin Vermeer") + } + } + 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/wvWare/patches/1.2.9/printf-redirect.patch b/wvWare/patches/1.2.9/printf-redirect.patch new file mode 100644 index 0000000..aac015c --- /dev/null +++ b/wvWare/patches/1.2.9/printf-redirect.patch @@ -0,0 +1,12 @@ +--- wv.h ++++ wv.h +@@ -10,6 +10,9 @@ + extern "C" { + #endif + ++int printfRedirect(const char* __fmt, ...); ++#define printf printfRedirect ++ + /* The structure below is used to refer to a wvStream. Usually, + * kind = GSF_STREAM, + * but if we can't open a file using LibGSF, we fall back to the old file-based diff --git a/wvWare/patches/1.2.9/skip-programs.patch b/wvWare/patches/1.2.9/skip-programs.patch new file mode 100644 index 0000000..a57deef --- /dev/null +++ b/wvWare/patches/1.2.9/skip-programs.patch @@ -0,0 +1,11 @@ +--- GNUmakefile.am ++++ GNUmakefile.am +@@ -18,8 +18,6 @@ wvhdr_HEADERS = wv.h + + bin_SCRIPTS = wvCleanLatex wvHtml wvDocBook wvAbw wvMime wvPS wvDVI wvLatex wvPDF wvText wvWml + +-bin_PROGRAMS = wvWare wvRTF wvConvert wvVersion wvSummary +- + lib_LTLIBRARIES = libwv.la + + GETOPT = @LIBOBJS@ diff --git a/wvWare/wv-1.2.9.tar.gz b/wvWare/wv-1.2.9.tar.gz new file mode 100644 index 0000000..c021da8 Binary files /dev/null and b/wvWare/wv-1.2.9.tar.gz differ