Skip to content
This repository was archived by the owner on Sep 20, 2026. It is now read-only.
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:

- name: Install macOS build dependencies
if: runner.os == 'macOS'
run: brew install autoconf automake gperf groff
run: brew install autoconf automake libtool gperf groff

- name: Set up Go
uses: actions/setup-go@v7
Expand Down
125 changes: 125 additions & 0 deletions rscada/libmbus/0.10.2/libmbus_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import (
"os"
"path/filepath"
)

const consumerSource = `#include <mbus/mbus.h>
#include <string.h>

int main(void) {
unsigned char ack = 0xE5;
mbus_frame frame;
mbus_handle *handle;

memset(&frame, 0, sizeof(frame));
if (mbus_parse(&frame, &ack, 1) != 0) {
return 1;
}
if (mbus_get_current_version() == 0) {
return 1;
}

handle = mbus_context_serial("/dev/null");
if (handle == 0) {
return 1;
}
mbus_context_free(handle);
return 0;
}
`

id "rscada/libmbus"

fromVer "0.10.2"

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"

os.chdir(ctx.SourceDir)!
os.mkdirAll(filepath.join(ctx.SourceDir, "m4"), 0o755)!

// GNU libtoolize is `libtoolize` on Linux and `glibtoolize` on Homebrew
// Darwin. Host package managers are not part of the formula.
if exec("libtoolize", "--copy", "--force") != nil {
glibtoolize! "--copy", "--force"
}
autoreconf! "-fi"
Comment on lines +60 to +67

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.

[P3] Non-obvious autotools bootstrap steps are undocumented

The m4/ pre-creation (line 62) and the glibtoolize vs libtoolize darwin branch (lines 63-67) are non-obvious workarounds a future maintainer wouldn't infer (Homebrew renames the GNU tool; AC_CONFIG_MACRO_DIRS needs m4/ to exist). The sibling libatomic_ops documents its comparable non-obvious step (pkg-config relocation) with a comment. A one-line comment here would match repo norms.


picFlag := "--without-pic"
if fPIC {
picFlag = "--with-pic"
}

a := autotools.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir)
if shared {
a.configure "--enable-shared", "--disable-static", picFlag
} else {
a.configure "--disable-shared", "--enable-static", picFlag
}
a.build
a.install

licenseDir := filepath.join(installDir, "licenses")
os.mkdirAll(licenseDir, 0o755)!
os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0o644)!

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.

[P2] Only LICENSE is copied; confirm upstream ships no COPYING

The sibling bdwgc/libatomic_ops copies both LICENSE and COPYING into licenses/. libmbus copies only LICENSE. If the upstream tarball also ships a COPYING (or other license file), it will be omitted from the package. Please confirm LICENSE is the only license file the release ships.


pcDir := filepath.join(installDir, "lib", "pkgconfig")
os.mkdirAll(pcDir, 0o755)!
pc := pkgconfig.new(
name = "libmbus",
description = "Open source M-bus (Meter-Bus) library.",
version = "0.10.2",
URL = "http://www.rscada.se/libmbus/",
libs = ["-L$${libdir}", "-lmbus", "-lm"],
cflags = ["-I$${includedir}"],
)!
out := os.create(filepath.join(pcDir, "libmbus.pc"))!
pc.writeTo(out)!
out.close()!

pkgconfig.use installDir
ctx.setMetadata pkgconfig.lookup("libmbus")!
}

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, "libmbus.flags")
os.writeFile(flagsFile, []byte(pkgconfig.lookup("libmbus")!), 0o644)!

binary := filepath.join(testDir, "consumer")
cc! sourcePath, "-o", binary, "@"+flagsFile

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.

[P3] Test compile omits an explicit -std flag used by the sibling

The sibling libatomic_ops onTest compiles the consumer with an explicit -std=c11. Here cc! is invoked without a -std= flag, so the consumer relies on the compiler's default standard. Minor consistency point — add -std=c11 (or whatever libmbus's headers require) if a specific standard is expected.


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
}
12 changes: 12 additions & 0 deletions rscada/libmbus/libmbus_cmp.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import "strings"

func normalize(version string) string {
if strings.hasPrefix(version, "v") {
return version
}
return "v" + version
}
Comment on lines +3 to +8

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.

[P2] Comparator lacks rationale comment; normalization may be dead code

This comparator is byte-for-byte identical to recp/cglm/Cglm_cmp.gox but drops the block comment explaining why normalization is needed. Every other custom comparator in the repo documents its deviation (cglm's mixed v/bare tags, ChaiScript's Release-* aliases, even ruckig's one-liner).

Upstream rscada/libmbus tags are uniformly bare (0.10.2, 0.10.1, 0.9.0, ...), so the hasPrefix(version, "v") early-return branch is effectively dead and normalize just unconditionally prepends v. Consider either (a) a plain semver.Compare wrapper with a short note like ruckig's, or (b) keeping this form but adding a one-line comment that tags are bare and v is prepended only to satisfy Go semver syntax.


compareVer (a, b) => {
return semver.Compare(normalize(a.Version), normalize(b.Version))
}
4 changes: 4 additions & 0 deletions rscada/libmbus/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "rscada/libmbus",
"deps": {}
}
Loading