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
122 changes: 122 additions & 0 deletions AcademySoftwareFoundation/openapv/v0.2.1.3-fix/openapv_llar.gox
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import (
"os"
"path/filepath"
"slices"
"strings"
)

const consumerSource = `#include <oapv.h>
#include <stdio.h>

int main(void) {
unsigned int version_num = 0;
const char *version_str = oapv_version(&version_num);
if (version_str == 0) {
return 1;
}
printf("%u %s\n", version_num, version_str);
return 0;
}
`

id "AcademySoftwareFoundation/openapv"

fromVer "v0.2.1.3-fix"

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 "OAPV_APP_STATIC_BUILD", !shared
c.defineBool "OAPV_BUILD_STATIC_LIB", !shared
c.defineBool "OAPV_BUILD_SHARED_LIB", shared
c.defineBool "ENABLE_TESTS", false
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)!

// Upstream installs oapv.pc with CMAKE_INSTALL_PREFIX-expanded paths.
// Keep its verified flags while making the installed 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 its verified flags," but the loop below actually rewrites Cflags: and Libs: entirely with hardcoded relocatable values rather than preserving the upstream flags. Consider rewording to something like "Rewrite the paths and flags to be relocatable" so the comment matches the behavior.

pcPath := filepath.join(installDir, "lib", "pkgconfig", "oapv.pc")
lines := string(os.readFile(pcPath)!).split("\n")
for i, line in lines {
if line.hasPrefix("prefix=") {
line = "prefix=$${pcfiledir}/../.."
} else if line.hasPrefix("exec_prefix=") {
line = "exec_prefix=$${prefix}"
} else if line.hasPrefix("libdir=") {
line = "libdir=$${prefix}/lib"
} else if line.hasPrefix("includedir=") {
line = "includedir=$${prefix}/include/oapv"
} else if line.hasPrefix("Cflags:") {
cflags := "-I$${prefix}/include -I$${includedir}"
if !shared {
cflags += " -DOAPV_STATIC_DEFINE"
}
line = "Cflags: " + cflags
} else if line.hasPrefix("Libs:") {
libs := "-L$${libdir} -loapv"
if !shared {
libs = "-L$${libdir}/oapv -loapv"
}
if slices.contains(target.require["os"], "linux") {
libs += " -lm -lpthread"

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 -lpthread is appended to the public Libs: for both shared and static builds. These are transitive runtime deps that upstream keeps in Libs.private (needed only for static linking). Harmless for the shared case (the .so already carries them), but if you want to mirror upstream semantics you could scope this append inside the if !shared branch. Non-blocking.

}
line = "Libs: " + libs
}
lines[i] = line
}
os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0o644)!

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

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, "oapv.flags")
os.writeFile(flagsFile, []byte(pkgconfig.lookup("oapv")!), 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 AcademySoftwareFoundation/openapv/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "AcademySoftwareFoundation/openapv",
"deps": {}
}
Loading