Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions dmtx/libdmtx/v0.7.8/libdmtx_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import (
"os"
"path/filepath"
"strings"
)

const consumerSource = `#include <dmtx.h>

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Keep the Autotools template's fields," but the .pc is hand-authored inline rather than read/transformed from any template, and the Libs field intentionally diverges from the upstream template (-ldmtx-ldmtx -lm on linux/freebsd). Consider rewording to match what the code does, e.g. "libdmtx ships no pkg-config file, so synthesize one with the standard fields (adding -lm where libm is needed) and make it 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"] {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-lm is only appended when target.require["os"] explicitly contains linux/freebsd. Upstream links libm PUBLIC on all non-MSVC platforms, so if require["os"] is unset/empty for a UNIX-like target, this loop runs zero times and -lm is dropped from the .pc Libs: — static consumers calling math symbols would then hit undefined references. This mirrors the sibling neco recipe's require["os"]-gated pattern, so it matches convention, but it's worth confirming the harness always populates require["os"] for your target platforms. Minor style: the sibling recipes use slices.contains(target.require["os"], "linux") for this exact check, which is shorter and drops the manual break.

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
}
4 changes: 4 additions & 0 deletions dmtx/libdmtx/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "dmtx/libdmtx",
"deps": {}
}
Loading