From 7c0d0697b7e288af0e44691446e34004206dfeba Mon Sep 17 00:00:00 2001 From: Rick Guo Date: Thu, 20 Aug 2026 13:58:58 +0800 Subject: [PATCH] formula: add dmtx/libdmtx --- dmtx/libdmtx/v0.7.8/libdmtx_llar.gox | 121 +++++++++++++++++++++++++++ dmtx/libdmtx/versions.json | 4 + 2 files changed, 125 insertions(+) create mode 100644 dmtx/libdmtx/v0.7.8/libdmtx_llar.gox create mode 100644 dmtx/libdmtx/versions.json diff --git a/dmtx/libdmtx/v0.7.8/libdmtx_llar.gox b/dmtx/libdmtx/v0.7.8/libdmtx_llar.gox new file mode 100644 index 0000000..8ed7c08 --- /dev/null +++ b/dmtx/libdmtx/v0.7.8/libdmtx_llar.gox @@ -0,0 +1,121 @@ +import ( + "os" + "path/filepath" + "strings" +) + +const consumerSource = `#include + +int main(void) { + DmtxEncode *enc = dmtxEncodeCreate(); + dmtxEncodeDestroy(&enc); + return 0; +} +` + +id "dmtx/libdmtx" + +fromVer "v0.7.8" + +defaults { + "shared": "OFF", + "fPIC": "ON", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" { + return false + } + for value in values { + if value != "ON" && value != "OFF" { + return false + } + } + } + return true +} + +onBuild ctx => { + installDir := ctx.outputDir + shared := target.options["shared"][0] == "ON" + fPIC := target.options["fPIC"][0] == "ON" + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.define "CMAKE_INSTALL_LIBDIR", "lib" + c.defineBool "BUILD_TESTING", false + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "BUILD_STATIC_LIBS", !shared + c.defineBool "DMTX_SHARED", shared + c.defineBool "DMTX_STATIC", !shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)! + + // CMake installs the library and dmtx.h but not libdmtx.pc. Keep the + // Autotools template's fields and make the published metadata relocatable. + version := "" + for line in string(os.readFile(filepath.join(ctx.SourceDir, "CMakeLists.txt"))!).split("\n") { + if line.hasPrefix("project(DMTX VERSION ") { + version = line.trimPrefix("project(DMTX VERSION ").split(" ")[0] + break + } + } + if version == "" { + panic "libdmtx CMakeLists.txt has no project version" + } + + libs := "-L$${libdir} -ldmtx" + for osName in target.require["os"] { + if osName == "linux" || osName == "freebsd" { + libs += " -lm" + break + } + } + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0o755)! + pc := `prefix=$${pcfiledir}/../.. +exec_prefix=$${prefix} +libdir=$${prefix}/lib +includedir=$${prefix}/include + +Name: libdmtx +URL: http://www.libdmtx.org/ +Description: Library for reading and writing Data Matrix barcodes +Version: ` + version + ` +Libs: ` + libs + ` +Cflags: -I$${includedir} +` + os.writeFile(filepath.join(pcDir, "libdmtx.pc"), []byte(pc), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("libdmtx")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0o755)! + + sourcePath := filepath.join(testDir, "consumer.c") + os.writeFile(sourcePath, []byte(consumerSource), 0o644)! + + pkgconfig.use installDir + flagsFile := filepath.join(testDir, "libdmtx.flags") + os.writeFile(flagsFile, []byte(pkgconfig.lookup("libdmtx")!), 0o644)! + + binary := filepath.join(testDir, "consumer") + cc! sourcePath, "-o", binary, "@"+flagsFile + + if target.options["shared"][0] == "ON" { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + } + exec! binary +} diff --git a/dmtx/libdmtx/versions.json b/dmtx/libdmtx/versions.json new file mode 100644 index 0000000..cea3424 --- /dev/null +++ b/dmtx/libdmtx/versions.json @@ -0,0 +1,4 @@ +{ + "path": "dmtx/libdmtx", + "deps": {} +}