diff --git a/danfis/libccd/v2.1/ccd_llar.gox b/danfis/libccd/v2.1/ccd_llar.gox new file mode 100644 index 0000000..3549d3f --- /dev/null +++ b/danfis/libccd/v2.1/ccd_llar.gox @@ -0,0 +1,108 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include + +int main(void) { + ccd_t ccd; + CCD_INIT(&ccd); + return 0; +} +` + +id "danfis/libccd" + +fromVer "v2.1" + +defaults { + "shared": "OFF", + "fPIC": "ON", + "enable_double_precision": "OFF", +} + +filter => { + for name, values in target.options { + if name != "shared" && name != "fPIC" && name != "enable_double_precision" { + 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" + enableDoublePrecision := target.options["enable_double_precision"][0] == "ON" + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.define "CMAKE_INSTALL_LIBDIR", "lib" + c.define "CMAKE_POLICY_VERSION_MINIMUM", "3.5" + c.defineBool "BUILD_DOCUMENTATION", false + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.defineBool "ENABLE_DOUBLE_PRECISION", enableDoublePrecision + c.defineBool "CCD_HIDE_ALL_SYMBOLS", !shared + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0o755)! + os.writeFile(filepath.join(licenseDir, "BSD-LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "BSD-LICENSE"))!, 0o644)! + + // Upstream installs ccd.pc with CMAKE_INSTALL_PREFIX-expanded paths. + // Keep its verified flags while making the installed metadata relocatable. + pcPath := filepath.join(installDir, "lib", "pkgconfig", "ccd.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) + lines := pc.split("\n") + if !shared { + for i, line in lines { + if line.hasPrefix("Cflags:") && !strings.contains(line, "CCD_STATIC_DEFINE") { + lines[i] = line + " -DCCD_STATIC_DEFINE" + } + if slices.contains(target.require["os"], "linux") && line.hasPrefix("Libs:") && !strings.contains(line, " -lm") { + lines[i] = line + " -lm" + } + } + } + os.writeFile(pcPath, []byte(strings.join(lines, "\n")), 0o644)! + + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("ccd")! +} + +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, "ccd.flags") + os.writeFile(flagsFile, []byte(pkgconfig.lookup("ccd")!), 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/danfis/libccd/versions.json b/danfis/libccd/versions.json new file mode 100644 index 0000000..c3bfb07 --- /dev/null +++ b/danfis/libccd/versions.json @@ -0,0 +1,4 @@ +{ + "path": "danfis/libccd", + "deps": {} +}