-
Notifications
You must be signed in to change notification settings - Fork 2
formula: dmtx/libdmtx #197
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,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. | ||
| 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"] { | ||
|
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.
|
||
| 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 | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "path": "dmtx/libdmtx", | ||
| "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 the Autotools template's fields," but the
.pcis hand-authored inline rather than read/transformed from any template, and theLibsfield intentionally diverges from the upstream template (-ldmtx→-ldmtx -lmon 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-lmwhere libm is needed) and make it relocatable."