-
Notifications
You must be signed in to change notification settings - Fork 2
formula: add AcademySoftwareFoundation/openapv #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
| 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" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| 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 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "AcademySoftwareFoundation/openapv", | ||
| "deps": {} | ||
| } |
There was a problem hiding this comment.
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:andLibs: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.