diff --git a/rscada/libmbus/0.10.2/libmbus_llar.gox b/rscada/libmbus/0.10.2/libmbus_llar.gox new file mode 100644 index 0000000..d8f2dc2 --- /dev/null +++ b/rscada/libmbus/0.10.2/libmbus_llar.gox @@ -0,0 +1,120 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include +#include + +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)! + if slices.contains(target.require["os"], "darwin") { + glibtoolize! "--copy", "--force" + } else { + libtoolize! "--copy", "--force" + } + autoreconf! "-fi" + + 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)! + + pcPath := filepath.join(installDir, "lib", "pkgconfig", "libmbus.pc") + pc := string(os.readFile(pcPath)!) + pc = strings.replace(pc, "prefix="+installDir, "prefix=$${pcfiledir}/../..", 1) + pc = strings.replace(pc, "exec_prefix="+installDir, "exec_prefix=$${prefix}", 1) + pc = strings.replace(pc, "libdir="+filepath.join(installDir, "lib"), "libdir=$${prefix}/lib", 1) + pc = strings.replace(pc, "includedir="+filepath.join(installDir, "include"), "includedir=$${prefix}/include", 1) + os.writeFile(pcPath, []byte(pc), 0o644)! + + 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 + + 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/rscada/libmbus/libmbus_cmp.gox b/rscada/libmbus/libmbus_cmp.gox new file mode 100644 index 0000000..37d6fc8 --- /dev/null +++ b/rscada/libmbus/libmbus_cmp.gox @@ -0,0 +1,12 @@ +import "strings" + +func normalize(version string) string { + if strings.hasPrefix(version, "v") { + return version + } + return "v" + version +} + +compareVer (a, b) => { + return semver.Compare(normalize(a.Version), normalize(b.Version)) +} diff --git a/rscada/libmbus/versions.json b/rscada/libmbus/versions.json new file mode 100644 index 0000000..2590315 --- /dev/null +++ b/rscada/libmbus/versions.json @@ -0,0 +1,4 @@ +{ + "path": "rscada/libmbus", + "deps": {} +}