diff --git a/drichardson/huffman/v1.2.3/huffman_llar.gox b/drichardson/huffman/v1.2.3/huffman_llar.gox new file mode 100644 index 0000000..f1206d5 --- /dev/null +++ b/drichardson/huffman/v1.2.3/huffman_llar.gox @@ -0,0 +1,123 @@ +import ( + "os" + "path/filepath" + "slices" + "strings" +) + +const consumerSource = `#include +#include + +#include "huffman/huffman.h" + +int main(void) { + uint8_t input[3] = {'a', 'b', 'c'}; + unsigned char *encoded = NULL; + uint32_t encoded_len = 0; + + if (huffman_encode_memory(input, 3, &encoded, &encoded_len) != 0) { + return 1; + } + + free(encoded); + return encoded_len == 0; +} +` + +id "drichardson/huffman" + +// v1.2.3 is the first upstream tag with the CMake build and install contract +// used by v1.2.3 through v1.2.7. +fromVer "v1.2.3" + +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 + + // Match the Conan recipe's Cygwin source fix while retaining upstream + // behavior on native Windows and other platforms. + sourcePath := filepath.join(ctx.SourceDir, "huffman.c") + source := string(os.readFile(sourcePath)!) + source = strings.replace(source, "#ifdef WIN32", "#if defined _WIN32 || defined __CYGWIN__", 1) + os.writeFile(sourcePath, []byte(source), 0644)! + + shared := slices.contains(target.options["shared"], "ON") + fPIC := slices.contains(target.options["fPIC"], "ON") + + c := cmake.new(ctx.SourceDir, filepath.join(ctx.SourceDir, "_build"), installDir) + c.defineBool "BUILD_SHARED_LIBS", shared + c.defineBool "CMAKE_POSITION_INDEPENDENT_CODE", fPIC + c.configure + c.build + c.install + + licenseDir := filepath.join(installDir, "licenses") + os.mkdirAll(licenseDir, 0755)! + os.writeFile(filepath.join(licenseDir, "LICENSE"), os.readFile(filepath.join(ctx.SourceDir, "LICENSE"))!, 0644)! + + libs := "-L$${libdir} -lhuffman" + if slices.contains(target.require["os"], "windows") { + libs += " -lws2_32" + } + + pcDir := filepath.join(installDir, "lib", "pkgconfig") + os.mkdirAll(pcDir, 0755)! + pc := `prefix=$${pcfiledir}/../.. +includedir=$${prefix}/include +libdir=$${prefix}/lib + +Name: huffman +Description: Huffman encoder and decoder library +Version: 1.2.3 +Libs: ` + libs + ` +Cflags: -I$${includedir} +` + os.writeFile(filepath.join(pcDir, "huffman.pc"), []byte(pc), 0644)! + pkgconfig.use installDir + ctx.setMetadata pkgconfig.lookup("huffman")! +} + +onTest ctx => { + installDir := ctx.outputDir + testDir := filepath.join(ctx.SourceDir, "_llar_consumer") + os.mkdirAll(testDir, 0755)! + + sourcePath := filepath.join(testDir, "consumer.c") + os.writeFile(sourcePath, []byte(consumerSource), 0644)! + + binary := filepath.join(testDir, "consumer") + pkgconfig.use installDir + flags := strings.fields(pkgconfig.lookup("huffman")!) + args := []string{sourcePath} + args <- flags... + args <- "-o", binary + cc! args... + + if slices.contains(target.options["shared"], "ON") { + os.setenv("LD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + os.setenv("DYLD_LIBRARY_PATH", filepath.join(installDir, "lib"))! + if slices.contains(target.require["os"], "windows") { + path := os.getenv("PATH") + os.setenv("PATH", filepath.join(installDir, "bin")+";"+path)! + } + } + exec! binary +} diff --git a/drichardson/huffman/versions.json b/drichardson/huffman/versions.json new file mode 100644 index 0000000..eb8b2aa --- /dev/null +++ b/drichardson/huffman/versions.json @@ -0,0 +1,4 @@ +{ + "path": "drichardson/huffman", + "deps": {} +}